# 1suspensive/lovepdf architecture

> Architecture diagram of the GitHub repository 1suspensive/lovepdf, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/1suspensive/lovepdf
- Repository: https://github.com/1suspensive/lovepdf

## Overview

##### Main Components
- Client / User Interface – This represents API consumers (such as frontend apps or postman) that make HTTP requests.
- API Gateway / Controller Layer – Represented by the controllers in the infraestructure/controllers package (e.g., PDFBasicFunctionsController, UserAuthenticationController, UserPDFController). Also include ExceptionController.
- Service / Application Layer – This includes your application services (in the application/services folder) and use case implementations. Separate PDF-specific functions (encrypt, decrypt, merge, etc.) from user-related functionalities.
- Domain Layer – Capture business models, value objects (e.g., User, Role), DTOs (data transfer objects), and exceptions. Note that this is where the core business logic is defined (in the domain/models, domain/models/dto, and domain/models/exceptions folders) along with the use case interfaces defined in the domain/ports/input and domain/ports/output.
- Infrastructure / Adapters – This layer includes the adapters interacting with external systems (e.g., JWT adapter, UserMongoAdapter), configuration files (e.g., SecurityConfig, JwtFilter), mappers, and utilities. It connects to the MongoDB (as indicated by the UserMongoRepository and properties configuration) and also contains the classes for encryption and JWT utilities.

##### Relationships and Data Flow
- Requests from an external client hit the REST controllers.
- The controllers forward these requests to the appropriate application services (or use cases) which implement business logic.
- The application services leverage domain-level interfaces (ports) which are implemented by infrastructure adapters.
- The repository adapter (such as UserMongoAdapter along with UserMongoRepository) handles database operations in MongoDB.
- Security is enforced by using a JwtFilter (configured via SecurityConfig) and JWT utilities for authentication.
- Data transformation between domain objects and HTTP payloads is handled by the mappers (e.g., UserMapper).

##### Important Architectural Patterns
- Layered or Hexagonal/Ports-and-Adapters Architecture: Clearly delineate the core domain logic from peripheral concerns.
- Separation of Concerns: Each layer (controller, application, domain, infrastructure) handles its own responsibilities.
- Use of Use Cases: Implementing business rules as discrete use case classes for different PDF and user functions.
- JWT Security: Emphasis on authentication and authorization via the security adapter and filter.

##### Relevant Technologies
- Java 21 and SpringBoot 3.3.3 for rapid API development.
- Gradle for build automation.
- Docker and docker-compose for containerized deployment.
- MongoDB (as implied by configuration and repository naming) for data persistence.
- JWT libraries and RSA encryption utilities for security.

##### Elements
- Clear labels for each component and layer.
- Notes on technology choices where applicable (e.g., Docker for deployment, Gradle for building, SpringBoot as the framework).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    subgraph "Client"
        client["Client / API Consumer"]:::client
    end

    %% API Gateway / Controller Layer
    subgraph "API Gateway / Controllers"
        pdfController["PDFBasicFunctionsController"]:::controller
        userAuthController["UserAuthenticationController"]:::controller
        userPDFController["UserPDFController"]:::controller
        exceptionController["ExceptionController"]:::controller
    end

    %% Service / Application Layer
    subgraph "Service / Application Layer"
        subgraph "Application Services"
            pdfService["PDFServiceBasicFunctionsService"]:::service
            userAuthService["UserAuthenticationService"]:::service
            userPDFService["UserPDFService"]:::service
        end
        subgraph "Use Cases"
            pdfUseCase["PDF Use Cases"]:::usecase
            userAuthUseCase["User Authentication Use Cases"]:::usecase
            userPDFUseCase["User PDF Use Cases"]:::usecase
            utilsUseCase["Utils Use Cases"]:::usecase
        end
    end

    %% Domain Layer
    subgraph "Domain Layer"
        domainModels["Domain Models (User, Role)"]:::domain
        dtos["DTOs (e.g., AuthLoginRequestDTO)"]:::domain
        domainExceptions["Domain Exceptions"]:::domain
        inputPort["Input Ports"]:::domain
        outputPort["Output Ports"]:::domain
    end

    %% Infrastructure / Adapters
    subgraph "Infrastructure / Adapters"
        subgraph "Adapters"
            jwtAdapter["JwtAdapter"]:::adapter
            userMongoAdapter["UserMongoAdapter"]:::adapter
        end
        subgraph "Security"
            securityConfig["SecurityConfig"]:::security
            jwtFilter["JwtFilter"]:::security
        end
        subgraph "Persistence"
            userMongoRepository["UserMongoRepository"]:::repository
        end
        subgraph "Mappers & Utils"
            userMapper["UserMapper"]:::mapper
            jwtUtils["JwtUtils"]:::util
            rsaEncryption["RsaEncryptionUtils"]:::util
        end
        subgraph "Documents"
            userDocument["UserDocument"]:::document
        end
    end

    %% External Systems
    subgraph "External Systems"
        mongodb["MongoDB"]:::database
    end

    %% Relationships
    client -->|"HTTP_Request"| jwtFilter
    jwtFilter -->|"Routes_Request"| pdfController
    jwtFilter -->|"Routes_Request"| userAuthController
    jwtFilter -->|"Routes_Request"| userPDFController
    jwtFilter -->|"Routes_Request"| exceptionController

    pdfController -->|"calls"| pdfService
    userAuthController -->|"calls"| userAuthService
    userPDFController -->|"calls"| userPDFService
    userAuthController -->|"generates_token_via"| jwtAdapter

    pdfService -->|"executes"| pdfUseCase
    userAuthService -->|"executes"| userAuthUseCase
    userPDFService -->|"executes"| userPDFUseCase

    pdfController -->|"maps_payload"| userMapper
    userAuthController -->|"maps_payload"| userMapper
    userPDFController -->|"maps_payload"| userMapper

    pdfUseCase -->|"uses"| inputPort
    pdfUseCase -->|"uses"| outputPort
    userAuthUseCase -->|"uses"| inputPort
    userAuthUseCase -->|"uses"| outputPort
    userPDFUseCase -->|"uses"| inputPort
    userPDFUseCase -->|"uses"| outputPort

    inputPort -->|"impl_by"| userMongoAdapter
    outputPort -->|"impl_by"| userMongoAdapter

    userMongoAdapter -->|"calls_repo"| userMongoRepository
    userMongoRepository -->|"persists_to"| mongodb

    securityConfig -->|"configures"| jwtFilter
    jwtFilter -->|"utilizes"| jwtUtils
    securityConfig -->|"includes"| rsaEncryption
    jwtAdapter -->|"uses"| jwtUtils

    %% Click Events for Controllers
    click pdfController "https://github.com/1suspensive/lovepdf/blob/main/src/main/java/org/suspensive/lovepdfnonreactive/infraestructure/controllers/PDFBasicFunctionsController.java"
    click userAuthController "https://github.com/1suspensive/lovepdf/blob/main/src/main/java/org/suspensive/lovepdfnonreactive/infraestructure/controllers/UserAuthenticationController.java"
    click userPDFController "https://github.com/1suspensive/lovepdf/blob/main/src/main/java/org/suspensive/lovepdfnonreactive/infraestructure/controllers/UserPDFController.java"
    click exceptionController "https://github.com/1suspensive/lovepdf/blob/main/src/main/java/org/suspensive/lovepdfnonreactive/infraestructure/controllers/ExceptionController.java"

    %% Click Events for Services
    click pdfService "https://github.com/1suspensive/lovepdf/blob/main/src/main/java/org/suspensive/lovepdfnonreactive/application/services/PDFServiceBasicFunctionsService.java"
    click userAuthService "https://github.com/1suspensive/lovepdf/blob/main/src/main/java/org/suspensive/lovepdfnonreactive/application/services/UserAuthenticationService.java"
    click userPDFService "https://github.com/1suspensive/lovepdf/blob/main/src/main/java/org/suspensive/lovepdfnonreactive/application/services/UserPDFService.java"

    %% Click Events for Use Cases
    click pdfUseCase "https://github.com/1suspensive/lovepdf/tree/main/src/main/java/org/suspensive/lovepdfnonreactive/application/usecases/pdf"
    click userAuthUseCase "https://github.com/1suspensive/lovepdf/tree/main/src/main/java/org/suspensive/lovepdfnonreactive/application/usecases/user/authentication"
    click userPDFUseCase "https://github.com/1suspensive/lovepdf/tree/main/src/main/java/org/suspensive/lovepdfnonreactive/application/usecases/user/pdf"
    click utilsUseCase "https://github.com/1suspensive/lovepdf/tree/main/src/main/java/org/suspensive/lovepdfnonreactive/application/usecases/utils"

    %% Click Events for Domain Layer
    click domainModels "https://github.com/1suspensive/lovepdf/tree/main/src/main/java/org/suspensive/lovepdfnonreactive/domain/models"
    click dtos "https://github.com/1suspensive/lovepdf/tree/main/src/main/java/org/suspensive/lovepdfnonreactive/domain/models/dto"
    click domainExceptions "https://github.com/1suspensive/lovepdf/tree/main/src/main/java/org/suspensive/lovepdfnonreactive/domain/models/exceptions"
    click inputPort "https://github.com/1suspensive/lovepdf/tree/main/src/main/java/org/suspensive/lovepdfnonreactive/domain/ports/input"
    click outputPort "https://github.com/1suspensive/lovepdf/tree/main/src/main/java/org/suspensive/lovepdfnonreactive/domain/ports/output"

    %% Click Events for Infrastructure / Adapters
    click jwtAdapter "https://github.com/1suspensive/lovepdf/blob/main/src/main/java/org/suspensive/lovepdfnonreactive/infraestructure/adapters/JwtAdapter.java"
    click userMongoAdapter "https://github.com/1suspensive/lovepdf/blob/main/src/main/java/org/suspensive/lovepdfnonreactive/infraestructure/adapters/UserMongoAdapter.java"
    click securityConfig "https://github.com/1suspensive/lovepdf/blob/main/src/main/java/org/suspensive/lovepdfnonreactive/infraestructure/config/security/SecurityConfig.java"
    click jwtFilter "https://github.com/1suspensive/lovepdf/blob/main/src/main/java/org/suspensive/lovepdfnonreactive/infraestructure/config/security/filter/JwtFilter.java"
    click userMongoRepository "https://github.com/1suspensive/lovepdf/blob/main/src/main/java/org/suspensive/lovepdfnonreactive/infraestructure/repositories/UserMongoRepository.java"
    click userMapper "https://github.com/1suspensive/lovepdf/blob/main/src/main/java/org/suspensive/lovepdfnonreactive/infraestructure/mappers/UserMapper.java"
    click jwtUtils "https://github.com/1suspensive/lovepdf/blob/main/src/main/java/org/suspensive/lovepdfnonreactive/infraestructure/utils/JwtUtils.java"
    click rsaEncryption "https://github.com/1suspensive/lovepdf/blob/main/src/main/java/org/suspensive/lovepdfnonreactive/infraestructure/utils/RsaEncryptionUtils.java"
    click userDocument "https://github.com/1suspensive/lovepdf/blob/main/src/main/java/org/suspensive/lovepdfnonreactive/infraestructure/documents/UserDocument.java"

    %% Styles and Classes
    classDef client fill:#ffcc00,stroke:#333,stroke-width:1px;
    classDef controller fill:#bbdefb,stroke:#333,stroke-width:1px;
    classDef service fill:#c8e6c9,stroke:#333,stroke-width:1px;
    classDef usecase fill:#ffe082,stroke:#333,stroke-width:1px;
    classDef domain fill:#ffccbc,stroke:#333,stroke-width:1px;
    classDef adapter fill:#b2ebf2,stroke:#333,stroke-width:1px;
    classDef security fill:#f8bbd0,stroke:#333,stroke-width:1px;
    classDef repository fill:#fff59d,stroke:#333,stroke-width:1px;
    classDef mapper fill:#c5e1a5,stroke:#333,stroke-width:1px;
    classDef util fill:#d1c4e9,stroke:#333,stroke-width:1px;
    classDef document fill:#b3e5fc,stroke:#333,stroke-width:1px;
    classDef database fill:#d7ccc8,stroke:#333,stroke-width:1px;
```
