A modern RESTful API for book management built with Spring Boot 3, Java 21 and Hexagonal Architecture
ArchivumLibris API provides endpoints for managing books, users, and purchases with a clean, maintainable architecture. The system allows for:
- Book catalog management - Create, read, update, and delete books with detailed metadata
- User management - Registration, authentication, and profile management with role-based access
- Purchase processing - Create and track book purchases with payment methods
The project follows Hexagonal Architecture (Ports and Adapters) principles with Feature Slices organization to achieve excellent separation of concerns and maintainability.
This project implements a modern approach to software architecture:
- Domain-Driven Design - Focus on the core domain and domain logic
- Hexagonal Architecture - Clear separation between application core and external dependencies
- Feature Slices - Organize code by feature rather than technical layers
- Clean Architecture - Independent of frameworks, UI, and external agencies
src/
โโโ main/java/com/archivumlibris/
โ โโโ adapter/ # Adapters layer (Ports & Adapters)
โ โ โโโ in/ # Inbound adapters (Controllers)
โ โ โ โโโ auth/ # Authentication endpoints
โ โ โ โโโ book/ # Book management endpoints
โ โ โ โโโ purchase/ # Purchase processing endpoints
โ โ โ โโโ user/ # User management endpoints
โ โ โโโ out/ # Outbound adapters
โ โ โโโ jpa/ # JPA entities and repositories
โ โ โโโ persistence/ # Repository implementations
โ โโโ application/ # Application layer (Use cases)
โ โ โโโ seeder/ # Data seeders
โ โ โโโ service/ # Business services
โ โโโ domain/ # Domain layer (Core business logic)
โ โ โโโ model/ # Domain entities and enums
โ โ โโโ port/ # Interfaces (contracts)
โ โ โโโ in/ # Inbound ports (use cases)
โ โ โโโ out/ # Outbound ports (repositories)
โ โโโ dto/ # Data Transfer Objects
โ โ โโโ request/ # Request DTOs
โ โ โโโ response/ # Response DTOs
โ โโโ mapper/ # Object mappers
โ โโโ security/ # Security configuration and JWT
โ โโโ shared/ # Shared configurations and utilities
โ โโโ exception/ # Custom exceptions and handlers
โโโ resources/
โโโ db/migration/ # Flyway database migrations
โโโ application.properties # Application configuration
โโโ META-INF/ # Spring configuration metadata
Complete book catalog management with rich metadata support:
- โ Create, read, update, and delete books
- โ Search and filter books by title, author, publisher, and genre
- โ Book genre categorization (Fiction, Non-Fiction, Science, etc.)
- โ Price management with decimal precision
- โ Pagination support for large catalogs
Comprehensive user system with security:
- โ User registration and authentication via JWT
- โ Profile management (name, email updates)
- โ Role-based access control (ADMIN, USER)
- โ Soft delete functionality (users marked as deleted)
- โ Password encryption with BCrypt
- โ Admin seeder for initial setup
End-to-end purchase flow:
- โ Purchase creation with book and user association
- โ Payment method tracking
- โ Purchase date recording
- โ Price tracking at time of purchase
- โ Purchase history retrieval
- โ JWT-based authentication
- โ Role-based authorization
- โ Password encryption
- โ Automatic admin user creation
- โ Secure endpoints with proper access control
- Backend: Spring Boot 3.x, Java 21
- Database: PostgreSQL with Flyway migrations
- Security: Spring Security with JWT
- Documentation: OpenAPI 3 (Swagger)
- Build Tool: Maven
- Container: Docker & Docker Compose
- JDK 21+
- Maven 3.8+
- PostgreSQL 15+ (or use Docker)
-
Clone the repository
git clone https://github.com/brunoliratm/ArchivumLibris-API.git cd ArchivumLibris-API
-
Start with Docker Compose
docker-compose up --build -d
-
Access the application:
- API: http://localhost:8080
- Swagger UI: http://localhost:8080/swagger-ui.html
- Database: localhost:5432 (user: postgres, password: postgres, db: ala)
-
Clone the repository
git clone https://github.com/brunoliratm/ArchivumLibris-API.git cd ArchivumLibris-API
-
Setup PostgreSQL database
CREATE DATABASE ala;
-
Configure environment variables (optional)
export SPRING_DATASOURCE_URL=localhost:5432/ala export SPRING_DATASOURCE_USERNAME=postgres export SPRING_DATASOURCE_PASSWORD=your_password export JWT_SECRET=your_jwt_secret export ADMIN_DEFAULT_EMAIL=admin@yourdomain.com export ADMIN_DEFAULT_PASSWORD=your_admin_password
-
Build and run the application
# Build the project ./mvnw clean install # Run the application ./mvnw spring-boot:run
-
Start the application using one of the methods above
-
Access the API endpoints:
- API Base URL: http://localhost:8080
- Swagger UI: http://localhost:8080/swagger-ui.html
- API Documentation: http://localhost:8080/v3/api-docs
-
Login with default admin credentials:
- Email: admin@email.com
- Password: admin2025@
-
Test the API using Swagger UI or your preferred API client
Comprehensive API documentation is available via Swagger UI at /swagger-ui.html
after starting the application.
- Books:
/api/books
- CRUD operations for book management - Users:
/api/users
- User management and authentication - Purchases:
/api/purchases
- Purchase processing and history - Authentication:
/api/auth
- Login and token management
- Email: admin@email.com (configurable via
ADMIN_DEFAULT_EMAIL
) - Password: admin2025@ (configurable via
ADMIN_DEFAULT_PASSWORD
)
The application uses Flyway for database migrations with the following main tables:
- users - User accounts with roles and soft delete
- books - Book catalog with metadata and pricing
- purchases - Purchase transactions linking users and books
The project includes:
- Multi-stage Dockerfile for optimized builds
- Docker Compose for simplified local development
- PostgreSQL container support with data persistence
- Optimized Alpine-based images for production
Quick start with Docker Compose:
docker-compose up --build -d
Manual Docker commands:
# Build the application
./mvnw clean package -DskipTests
# Build Docker image
docker build -t archivumlibris-api .
# Run with database
docker run --name archivumlibris-postgres \
-e POSTGRES_DB=ala \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=postgres \
-p 5432:5432 -d postgres:16-alpine
docker run --name archivumlibris-api \
-p 8080:8080 \
-e SPRING_DATASOURCE_URL=host.docker.internal:5432/ala \
-e SPRING_DATASOURCE_USERNAME=postgres \
-e SPRING_DATASOURCE_PASSWORD=postgres \
--link archivumlibris-postgres:postgres \
-d archivumlibris-api
POST /api/books
Content-Type: application/json
{
"title": "Clean Code",
"author": "Robert C. Martin",
"publisher": "Prentice Hall",
"genre": "NON_FICTION",
"price": 99.90
}
POST /api/auth/register
Content-Type: application/json
{
"name": "Alice",
"email": "alice@email.com",
"password": "secret123"
}
POST /api/purchases
Content-Type: application/json
Authorization: Bearer <JWT_TOKEN>
{
"bookId": 1,
"payMethod": "PIX"
}
To run all unit and integration tests:
./mvnw test
- Database connection issues: Check your environment variables and Docker Compose logs.
- Port conflicts: Ensure ports 8080 (API) and 5432 (Postgres) are free.
- Swagger not loading: Wait for the backend to finish starting or check logs for errors.
Contributions make the open source community an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
Distributed under the MIT License. See LICENSE
for more information.
Project Link: https://github.com/brunoliratm/ArchivumLibris-API
Author: Bruno Lira LinkedIn: brunoliratm GitHub: @brunoliratm