# denis-lima/backend-java-spring-test architecture

> Architecture diagram of the GitHub repository denis-lima/backend-java-spring-test, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/denis-lima/backend-java-spring-test
- Repository: https://github.com/denis-lima/backend-java-spring-test

## Overview

##### Main components
- Application Entry & Configuration – The application is started by TodoappApplication.java. Configuration files (like application.properties and the various configuration classes in the config package) set up the Spring Boot environment.
- Controllers – The controllers (AuthController, TaskController, UserController) handle incoming HTTP requests, validate and pass them to the service layer.
- Services – The service layer (TaskService, UserService, and their implementations alongside the AuthorizationService) encapsulates business logic.
- Repositories – The repository layer (TaskRepository and UserRepository) acts as the Data Access Object (DAO) layer, interacting with the database (even though the database isn’t shown in the file tree, it is implied by the use of repositories).
- Data Transfer Objects (DTOs) – DTO classes (such as CreateTaskDTO, CreateUserDTO, and others) are used in data exchange between the client and server.
- Entities – The entities (User, Task, and Status) represent the domain model and are likely persisted in the database.
- Exception Handling – A global exception handling mechanism is provided via the ExceptionHandlerController and custom exceptions (NotAllowedException, ResourceAlreadyExistsException, ResourceNotFoundException).
- Security – The security module includes components for authentication and authorization (SecurityConfig, SecurityFilter, TokenService, AuthenticationEntryPointImpl, etc.) ensuring the API’s endpoints are accessed securely.
- Utility/Validation – Validators and constraint definitions (for example, TaskValidator and UserValidator, as well as their implementations) help enforce business rules.

##### Interactions and Relationships
- HTTP Request Flow: Requests hit the Controllers → Controllers call Services for processing.
- Service Interaction: The Service layer processes the business logic and calls Repositories to interact with the database.
- DTO Mapping: Mappers (TaskMapper, UserMapper) convert between Entities and DTOs.
- Security Layer: Incoming API calls pass through Security Filters where TokenService is invoked to validate tokens before reaching controllers.
- Exception Propagation: The ExceptionHandlerController globally handles errors thrown from any layer.
- Documentation: The API documentation available via Swagger (configured in OpenApi30Config) indicates an emphasis on clearly defined endpoints.

##### Architectural patterns/design principles to capture
- Layered Architecture: Separate components (Controller, Service, Repository) indicate a clean separation of concerns.
- MVC-like pattern: Controllers and DTOs define the interface between the client and the business logic.
- Security best practices: Configurations indicate use of standard Spring Security mechanisms.
- Validation and Error Handling: Custom validators and global exception handlers help maintain robustness.
- Dependency Injection: Being a Spring Boot application, DI is used across controllers, services, and repositories.

##### Elements
- Integration points such as the REST API endpoints from Controllers or the interaction of Security Filters and Token Service before data processing in controllers.

- An entry point (TodoappApplication) that initializes the system.
- A clear demarcation into layers: Controllers (handling API calls), Services (business logic), and Repositories/Entities (data layer).
- Side components for security and exception handling that interact with the main request/response cycle.
- Supporting components like DTOs, mappers, and validators that assist data transformation and validation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Global Nodes
    Client["Client Request"]:::client

    %% Application Entry & Config Layer
    subgraph "Application Entry & Config Layer"
        entry["TodoappApplication.java"]:::entry
        configApp["Config (OpenApi30Config, SecurityConfig)"]:::entry
        appProps["application.properties"]:::entry
    end

    %% Security Layer
    subgraph "Security Layer"
        secFilter["SecurityFilter"]:::sec
        tokenSvc["TokenService"]:::sec
        authEntry["AuthenticationEntryPoint"]:::sec
        secConfig["SecurityConfiguration"]:::sec
    end

    %% Controllers Layer
    subgraph "Controllers Layer"
        controllers["Controllers"]:::ctrl
    end

    %% Services Layer
    subgraph "Services Layer"
        svcInt["Service Interfaces (TaskService, UserService)"]:::svc
        svcImpl["Service Implementations (TaskServiceImpl, UserServiceImpl, AuthorizationService)"]:::svc
    end

    %% Repositories Layer
    subgraph "Repositories Layer"
        repos["Repositories"]:::repo
    end

    %% Data & DTOs Layer
    subgraph "Data & DTOs Layer"
        dtos["DTOs (CreateTaskDTO, CreateUserDTO, LoginDTO, etc.)"]:::data
        entities["Entities (User, Task, Status)"]:::data
    end

    %% Mapping & Validation Layer
    subgraph "Mapping & Validation Layer"
        mappers["DTO Mappers (TaskMapper, UserMapper)"]:::util
        validators["Validators & Constraints"]:::util
    end

    %% Exception Handling Layer
    subgraph "Exception Handling Layer"
        excHandler["Global Exception Handler"]:::exc
        customExc["Custom Exceptions"]:::exc
    end

    %% Documentation
    subgraph "Documentation"
        swagger["Swagger (OpenAPI)"]:::doc
    end

    %% Database (Represented as a cylinder)
    database["Database"]:::db

    %% Connections
    Client --> secFilter
    secFilter --> controllers
    controllers --> svcImpl
    svcImpl --> repos
    repos --> database

    %% Supporting components usage
    svcImpl --> mappers
    svcImpl --> validators

    %% Exception flow from layers
    controllers --> excHandler
    svcImpl --> excHandler
    repos --> excHandler

    %% Application Entry connections
    entry --> configApp
    configApp --> controllers
    configApp --> secConfig
    configApp --> swagger

    %% Security internal interactions
    secFilter --> tokenSvc
    secFilter --> authEntry

    %% Service interface to implementation
    svcInt --> svcImpl

    %% Click Events
    click entry "https://github.com/denis-lima/backend-java-spring-test/blob/main/src/main/java/com/selaz/todoapp/TodoappApplication.java"
    click appProps "https://github.com/denis-lima/backend-java-spring-test/blob/main/src/main/resources/application.properties"
    click configApp "https://github.com/denis-lima/backend-java-spring-test/tree/main/src/main/java/com/selaz/todoapp/config"
    click controllers "https://github.com/denis-lima/backend-java-spring-test/tree/main/src/main/java/com/selaz/todoapp/controllers"
    click svcInt "https://github.com/denis-lima/backend-java-spring-test/tree/main/src/main/java/com/selaz/todoapp/services"
    click svcImpl "https://github.com/denis-lima/backend-java-spring-test/tree/main/src/main/java/com/selaz/todoapp/services/impl"
    click repos "https://github.com/denis-lima/backend-java-spring-test/tree/main/src/main/java/com/selaz/todoapp/repositories"
    click dtos "https://github.com/denis-lima/backend-java-spring-test/tree/main/src/main/java/com/selaz/todoapp/dtos"
    click entities "https://github.com/denis-lima/backend-java-spring-test/tree/main/src/main/java/com/selaz/todoapp/entities"
    click excHandler "https://github.com/denis-lima/backend-java-spring-test/blob/main/src/main/java/com/selaz/todoapp/advice/ExceptionHandlerController.java"
    click customExc "https://github.com/denis-lima/backend-java-spring-test/tree/main/src/main/java/com/selaz/todoapp/exceptions"
    click secFilter "https://github.com/denis-lima/backend-java-spring-test/tree/main/src/main/java/com/selaz/todoapp/security"
    click tokenSvc "https://github.com/denis-lima/backend-java-spring-test/tree/main/src/main/java/com/selaz/todoapp/security"
    click authEntry "https://github.com/denis-lima/backend-java-spring-test/tree/main/src/main/java/com/selaz/todoapp/security"
    click secConfig "https://github.com/denis-lima/backend-java-spring-test/blob/main/src/main/java/com/selaz/todoapp/config/SecurityConfig.java"
    click mappers "https://github.com/denis-lima/backend-java-spring-test/tree/main/src/main/java/com/selaz/todoapp/mappers"
    click validators "https://github.com/denis-lima/backend-java-spring-test/tree/main/src/main/java/com/selaz/todoapp/utils/validators"

    %% Styles
    classDef entry fill:#FFCC00,stroke:#333,stroke-width:2px;
    classDef ctrl fill:#66CCFF,stroke:#333,stroke-width:2px;
    classDef svc fill:#99FF99,stroke:#333,stroke-width:2px;
    classDef repo fill:#FF9999,stroke:#333,stroke-width:2px;
    classDef data fill:#CC99FF,stroke:#333,stroke-width:2px;
    classDef sec fill:#FF66CC,stroke:#333,stroke-width:2px;
    classDef exc fill:#FF9966,stroke:#333,stroke-width:2px;
    classDef util fill:#CCCCCC,stroke:#333,stroke-width:2px;
    classDef doc fill:#66FFCC,stroke:#333,stroke-width:2px;
    classDef client fill:#FFCCCC,stroke:#333,stroke-width:2px;
    classDef db fill:#FFFF99,stroke:#333,stroke-width:2px;
```
