# cdocamposanchez/get-a-book architecture

> Architecture diagram of the GitHub repository cdocamposanchez/get-a-book, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/cdocamposanchez/get-a-book
- Repository: https://github.com/cdocamposanchez/get-a-book

## Overview

##### Project Type and Purpose
- This is a Java Spring Boot monolithic backend service exposing REST APIs for a book-ordering application (“Gab”).
- Layers follow a clean‐architecture style: presentation (controllers), application (use‐cases + DTOs + mappers), domain (entities, value objects, exceptions), infrastructure (persistence, security, external integrations).

##### Main Components
a. Client (Frontend)
b. Backend Service (“Gab” Application)
– Presentation Layer (Spring MVC Controllers)
– Application Layer (Use-cases orchestrating business logic; DTOs & Mappers)
– Domain Layer (Domain Models, Value Objects, Domain Exceptions)
– Infrastructure Layer
- Persistence: JPA Entities → Repositories → Database
- Security: JWT Provider, Filters, CustomUserDetailsService
- External Services: Cloudinary (image storage), Stripe (payments), SMTP (emails), Caching
- Configuration Modules (CORS, Cache, Security, Dotenv Loader)
c. Database
– Relational DB (MySQL/Postgres; defined by application.yml)
– Show Entities ↔ DB Tables
d. External Services
– Cloudinary API
– Stripe API
– SMTP Email Server
e. Other Services
– Cache (e.g., Redis) if enabled in CacheConfig

##### Relationships & Data Flow
- Frontend → (HTTPS/REST) → Controllers
- Controllers → Use‐cases (calls to application services)
- Use‐cases → Domain Models & Repositories
- Repositories → Database
- Use‐cases/Infrastructure → External Services (Cloudinary, Stripe, SMTP)
- Security Filter Chain intercepts Frontend requests, validates JWT, populates Authentication for Controllers

##### Architectural Patterns & Principles
- Layered (Onion/Clean) architecture separating business logic from delivery and infrastructure
- DTOs + Mappers isolate domain from external models
- Use‐cases encapsulate application business rules
- Spring Security for authentication/authorization (JWT-based)
- Specification pattern for querying (BookSpecification)
- Exception handling with a GlobalExceptionHandler

##### Essential Details to Capture
- The “frontend branch” (Client) calling REST endpoints
- Secure perimeter: JwtAuthFilter → Controllers
- Use‐cases grouped by domain (book, order, user)
- Technologies: Spring Boot, Spring MVC, Spring Security, Spring Data JPA, Hibernate, Cloudinary SDK, Stripe SDK, Java Mail

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client"
        Frontend["Frontend (Web/Mobile Client)"]:::client
    end

    %% Backend Service
    subgraph "Gab Backend Service"
        direction TB

        subgraph "Presentation Layer"
            direction TB
            Controllers["Controllers"]:::presentation
        end

        subgraph "Application Layer"
            direction TB
            DTOs["DTOs"]:::application
            Mappers["Mappers"]:::application
            UseCases["Use Cases"]:::application
        end

        subgraph "Domain Layer"
            direction TB
            Models["Domain Models"]:::domain
            ValueObjects["Value Objects"]:::domain
            DomainExceptions["Domain Exceptions"]:::domain
            Types["Types (Enums)"]:::domain
        end

        subgraph "Infrastructure Layer"
            direction TB
            subgraph Persistence
                direction TB
                Entities["JPA Entities"]:::persistence
                Repositories["Repositories"]:::persistence
                Specifications["Specifications"]:::persistence
                Embeddables["Embeddables"]:::persistence
            end

            subgraph Security
                direction TB
                JwtFilter["JwtAuthFilter"]:::security
                JwtProvider["JwtTokenProvider"]:::security
                UserDetailsService["CustomUserDetailsService"]:::security
                SecurityExceptions["Security Exceptions & Handlers"]:::security
                CustomUser["CustomUserDetails"]:::security
                AuthUserProvider["AuthenticatedUserProvider"]:::security
            end

            subgraph ExternalServices
                direction TB
                CloudinaryConfig["CloudinaryConfig"]:::external
                CloudinaryService["CloudinaryService"]:::external
                StripeProps["StripeProperties"]:::external
                StripeService["StripeService"]:::external
                MailConfigNode["MailConfig"]:::external
                EmailServiceNode["EmailService"]:::external
            end

            subgraph Configuration
                direction TB
                CacheConfigNode["CacheConfig"]:::config
                CorsConfigNode["CorsConfig"]:::config
                SecurityConfigNode["SecurityConfig"]:::config
                DotenvLoaderNode["DotenvLoader"]:::config
                GlobalExceptionHandler["GlobalExceptionHandler"]:::config
            end
        end
    end

    %% Database and External
    Database[(Relational DB)]:::db
    SMTP["SMTP Email Server"]:::external
    CloudinaryAPI["Cloudinary API"]:::external
    StripeAPI["Stripe API"]:::external
    Cache["Cache (Redis)"]:::external

    %% Connections
    Frontend -->|"JSON over HTTP\n(HTTPS/REST)"| Controllers
    Controllers -->|"BookDTO, OrderDTO, UserDTO"| UseCases
    UseCases -->|"Entities & Value Objects"| Models
    UseCases --> Repositories
    Repositories -->|"CRUD via JPA"| Database
    UseCases --> CloudinaryService
    UseCases --> StripeService
    UseCases --> EmailServiceNode
    JwtFilter -->|Validates JWT| Controllers

    %% External arrows
    CloudinaryService -->|HTTPS API| CloudinaryAPI
    StripeService -->|HTTPS API| StripeAPI
    EmailServiceNode -->|SMTP| SMTP
    CacheConfigNode -->|Configures| Cache

    %% Click Events
    click Controllers "https://github.com/cdocamposanchez/get-a-book/tree/Backend/src/main/java/com/adi/gab/presentation/controller"
    click DTOs "https://github.com/cdocamposanchez/get-a-book/tree/Backend/src/main/java/com/adi/gab/application/dto"
    click Mappers "https://github.com/cdocamposanchez/get-a-book/tree/Backend/src/main/java/com/adi/gab/application/mapper"
    click UseCases "https://github.com/cdocamposanchez/get-a-book/tree/Backend/src/main/java/com/adi/gab/application/usecase"
    click Models "https://github.com/cdocamposanchez/get-a-book/tree/Backend/src/main/java/com/adi/gab/domain/model"
    click ValueObjects "https://github.com/cdocamposanchez/get-a-book/tree/Backend/src/main/java/com/adi/gab/domain/valueobject"
    click DomainExceptions "https://github.com/cdocamposanchez/get-a-book/tree/Backend/src/main/java/com/adi/gab/domain/exception"
    click Types "https://github.com/cdocamposanchez/get-a-book/tree/Backend/src/main/java/com/adi/gab/domain/types"
    click Entities "https://github.com/cdocamposanchez/get-a-book/tree/Backend/src/main/java/com/adi/gab/infrastructure/persistance/entity"
    click Repositories "https://github.com/cdocamposanchez/get-a-book/tree/Backend/src/main/java/com/adi/gab/infrastructure/persistance/repository"
    click Specifications "https://github.com/cdocamposanchez/get-a-book/blob/Backend/src/main/java/com/adi/gab/infrastructure/persistance/specification/BookSpecification.java"
    click Embeddables "https://github.com/cdocamposanchez/get-a-book/tree/Backend/src/main/java/com/adi/gab/infrastructure/persistance/embeddable"
    click JwtFilter "https://github.com/cdocamposanchez/get-a-book/blob/Backend/src/main/java/com/adi/gab/infrastructure/security/JwtAuthFilter.java"
    click JwtProvider "https://github.com/cdocamposanchez/get-a-book/blob/Backend/src/main/java/com/adi/gab/infrastructure/security/JwtTokenProvider.java"
    click UserDetailsService "https://github.com/cdocamposanchez/get-a-book/blob/Backend/src/main/java/com/adi/gab/infrastructure/security/service/CustomUserDetailsService.java"
    click SecurityExceptions "https://github.com/cdocamposanchez/get-a-book/tree/Backend/src/main/java/com/adi/gab/infrastructure/security/exception"
    click CustomUser "https://github.com/cdocamposanchez/get-a-book/blob/Backend/src/main/java/com/adi/gab/infrastructure/security/CustomUserDetails.java"
    click AuthUserProvider "https://github.com/cdocamposanchez/get-a-book/blob/Backend/src/main/java/com/adi/gab/infrastructure/security/AuthenticatedUserProvider.java"
    click CloudinaryConfig "https://github.com/cdocamposanchez/get-a-book/blob/Backend/src/main/java/com/adi/gab/infrastructure/config/cloudinary/CloudinaryConfig.java"
    click CloudinaryService "https://github.com/cdocamposanchez/get-a-book/blob/Backend/src/main/java/com/adi/gab/infrastructure/config/cloudinary/CloudinaryService.java"
    click StripeProps "https://github.com/cdocamposanchez/get-a-book/blob/Backend/src/main/java/com/adi/gab/infrastructure/config/stripe/StripeProperties.java"
    click StripeService "https://github.com/cdocamposanchez/get-a-book/blob/Backend/src/main/java/com/adi/gab/infrastructure/config/stripe/StripeService.java"
    click MailConfigNode "https://github.com/cdocamposanchez/get-a-book/blob/Backend/src/main/java/com/adi/gab/infrastructure/config/smtp/MailConfig.java"
    click EmailServiceNode "https://github.com/cdocamposanchez/get-a-book/blob/Backend/src/main/java/com/adi/gab/infrastructure/smtp/EmailService.java"
    click CacheConfigNode "https://github.com/cdocamposanchez/get-a-book/blob/Backend/src/main/java/com/adi/gab/infrastructure/config/CacheConfig.java"
    click CorsConfigNode "https://github.com/cdocamposanchez/get-a-book/blob/Backend/src/main/java/com/adi/gab/infrastructure/config/CorsConfig.java"
    click SecurityConfigNode "https://github.com/cdocamposanchez/get-a-book/blob/Backend/src/main/java/com/adi/gab/infrastructure/config/SecurityConfig.java"
    click DotenvLoaderNode "https://github.com/cdocamposanchez/get-a-book/blob/Backend/src/main/java/com/adi/gab/infrastructure/config/DotenvLoader.java"
    click GlobalExceptionHandler "https://github.com/cdocamposanchez/get-a-book/blob/Backend/src/main/java/com/adi/gab/infrastructure/exception/GlobalExceptionHandler.java"
    click Database "https://github.com/cdocamposanchez/get-a-book/blob/Backend/src/main/resources/application.yml"

    %% Styles
    classDef client fill:#D0E0FF,stroke:#333,stroke-width:1px
    classDef presentation fill:#CCFFCC,stroke:#333,stroke-width:1px
    classDef application fill:#FFFFCC,stroke:#333,stroke-width:1px
    classDef domain fill:#FFEB99,stroke:#333,stroke-width:1px
    classDef infra fill:#DDDDDD,stroke:#333,stroke-width:1px
    classDef persistence fill:#EEEEEE,stroke:#333,stroke-width:1px
    classDef security fill:#FFCCCC,stroke:#333,stroke-width:1px
    classDef external fill:#CCE5FF,stroke:#333,stroke-width:1px
    classDef config fill:#E0E0E0,stroke:#333,stroke-width:1px
    classDef db fill:#A0A0A0,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5
    class Database db
```
