Skip to content

brunoliratm/ArchivumLibris-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

58 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Archivum Libris

A modern RESTful API for book management built with Spring Boot 3, Java 21 and Hexagonal Architecture

Spring Boot Spring Data JPA Spring Security Flyway PostgreSQL Swagger Docker

๐Ÿ“š Overview

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.

๐Ÿ”ท Architecture

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

๐Ÿ“ Project Structure

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

๐Ÿš€ Features

๐Ÿ“– Book Management

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

๐Ÿ‘ฅ User Management

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

๐Ÿ›’ Purchase Processing

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

๐Ÿ” Security Features

  • โœ… JWT-based authentication
  • โœ… Role-based authorization
  • โœ… Password encryption
  • โœ… Automatic admin user creation
  • โœ… Secure endpoints with proper access control

๐Ÿ› ๏ธ Tech Stack

  • 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

๐Ÿƒโ€โ™‚๏ธ Getting Started

Prerequisites

  • JDK 21+
  • Maven 3.8+
  • PostgreSQL 15+ (or use Docker)

๐Ÿ› ๏ธ Installation & Setup

Option 1: Docker Compose (Recommended)

  1. Clone the repository

    git clone https://github.com/brunoliratm/ArchivumLibris-API.git
    cd ArchivumLibris-API
  2. Start with Docker Compose

    docker-compose up --build -d
  3. Access the application:

Option 2: Manual Setup

  1. Clone the repository

    git clone https://github.com/brunoliratm/ArchivumLibris-API.git
    cd ArchivumLibris-API
  2. Setup PostgreSQL database

    CREATE DATABASE ala;
  3. 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
  4. Build and run the application

    # Build the project
    ./mvnw clean install
    
    # Run the application
    ./mvnw spring-boot:run

๐Ÿš€ How to Run

  1. Start the application using one of the methods above

  2. Access the API endpoints:

  3. Login with default admin credentials:

  4. Test the API using Swagger UI or your preferred API client

๐Ÿ“‹ API Documentation

Comprehensive API documentation is available via Swagger UI at /swagger-ui.html after starting the application.

๐Ÿ”— Main Endpoints

  • 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

๐Ÿ”‘ Default Admin Credentials

  • Email: admin@email.com (configurable via ADMIN_DEFAULT_EMAIL)
  • Password: admin2025@ (configurable via ADMIN_DEFAULT_PASSWORD)

๐Ÿ—๏ธ Database Schema

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

๐Ÿณ Docker Support

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

๐Ÿ“ฆ Example Requests

Create a Book

POST /api/books
Content-Type: application/json

{
  "title": "Clean Code",
  "author": "Robert C. Martin",
  "publisher": "Prentice Hall",
  "genre": "NON_FICTION",
  "price": 99.90
}

Register a User

POST /api/auth/register
Content-Type: application/json

{
  "name": "Alice",
  "email": "alice@email.com",
  "password": "secret123"
}

Purchase a Book

POST /api/purchases
Content-Type: application/json
Authorization: Bearer <JWT_TOKEN>

{
  "bookId": 1,
  "payMethod": "PIX"
}

๐Ÿงช Running Tests

To run all unit and integration tests:

./mvnw test

๐Ÿ“ Troubleshooting

  • 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.

๐Ÿค Contributing

Contributions make the open source community an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“„ License

Distributed under the MIT License. See LICENSE for more information.

๐Ÿ“ฎ Contact

Project Link: https://github.com/brunoliratm/ArchivumLibris-API

Author: Bruno Lira LinkedIn: brunoliratm GitHub: @brunoliratm

About

Book management applying Hexagonal Architecture and modern API practices using Spring Boot

Topics

Resources

License

Stars

Watchers

Forks