# witordias/animelistor architecture

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

- Interactive diagram: https://gitdiagram.com/witordias/animelistor
- Repository: https://github.com/witordias/animelistor

## Overview

##### Main Components
- API / Presentation Layer: Represented by the controllers (e.g., AnimeController). This layer receives HTTP requests and routes them to appropriate services.
- Business Logic / Service Layer: The AnimeService encapsulates the business logic. It acts as the intermediary between controllers and repositories.
- Data Access Layer: The repository (AnimeRepository) handles interactions with the MySQL database.
- Domain Model: The Anime class defines the core entity; DTOs (like AnimeDto) are used for data transfer.
- Exception Handling: Custom exceptions (BadRequestException, ValidationExceptionCustomFields etc.) along with the RestExceptionHandler provide robust error management.
- Security: The SecurityConfig configures in-memory authentication with different roles (admin and user) to secure API endpoints.
- Configuration/Extension: Files such as AnimeListorWebMvcConfigurer indicate customized configurations for the web layer.
- External and Supporting Services:
- Database: MySQL managed via Docker-compose.
- Monitoring: Prometheus (with its configuration in prometheus.yml) and Grafana for dashboard visualization.
- API Documentation: Swagger generated automatically via SpringDoc OpenAPI 3.
- Testing: The inclusion of both unit and integration tests (in the src/test tree) indicates a comprehensive test layer.

##### Relationships and Interactions
- Clients (e.g., Postman, Swagger UI, web browsers) send HTTP requests which are processed by the Controller layer.
- Requests flow through Spring Security to ensure proper authentication (using basic in-memory credentials).
- Controllers invoke methods in the Service layer, which in turn call the Repository layer for database operations.
- Exceptions raised in any layer are centrally handled by the RestExceptionHandler to inform users of errors.
- Docker Compose coordinates external dependencies (MySQL, Prometheus, Grafana) which interact with the API container.
- Monitoring data flows from the application (via Prometheus metrics) into Grafana dashboards.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        Clients["Clients (SwaggerUI,Postman,WebBrowsers)"]:::client
    end

    %% Security Layer
    subgraph "Security"
        Sec["Spring Security"]:::security
        SecConfig["SecurityConfig"]:::security
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        Ctrl["AnimeController"]:::controller
    end

    %% Service Layer
    subgraph "Service Layer"
        Serv["AnimeService"]:::service
    end

    %% Repository Layer
    subgraph "Repository Layer"
        Repo["AnimeRepository"]:::repository
    end

    %% Domain Model
    subgraph "Domain Model"
        Anime["Anime (Entity)"]:::domain
        Dto["AnimeDto (DTO)"]:::domain
    end

    %% Exception Handling
    subgraph "Exception Handling"
        Ex1["BadRequestException"]:::exception
        Ex2["BadRequestExceptionCustomizedFields"]:::exception
        Ex3["ExceptionCustomFields"]:::exception
        Ex4["ValidationExceptionCustomFields"]:::exception
        RestEx["RestExceptionHandler"]:::exception
    end

    %% Configuration
    subgraph "Configuration"
        Configurer["AnimeListorWebMvcConfigurer"]:::config
    end

    %% External Services
    subgraph "External Services"
        DB["MySQL"]:::external
        Prom["Prometheus"]:::external
        Graf["Grafana"]:::external
    end

    %% Build & Deployment
    subgraph "Build & Deployment"
        Maven["Maven Build"]:::build
        Docker["Docker Compose"]:::build
    end

    %% Testing
    subgraph "Testing"
        Tests["Tests (Unit&Integration)"]:::testing
    end

    %% Data Flow
    Clients -->|"sendsRequest"| Sec
    Sec -->|"authenticates"| SecConfig
    SecConfig -->|"forwardsRequest"| Ctrl
    Ctrl -->|"calls"| Serv
    Serv -->|"invokes"| Repo
    Repo -->|"mapsEntity"| Anime
    Ctrl -->|"transfersData"| Dto

    %% Error Handling Flow
    Ctrl -->|"errorsHandledBy"| RestEx
    Serv -->|"errorsHandledBy"| RestEx
    Repo -->|"errorsHandledBy"| RestEx

    %% External Interactions
    Docker -.-> DB
    Docker -.-> Prom
    Docker -.-> Graf
    Serv -->|"sendsMetricsTo"| Prom
    Prom -->|"feedsDataTo"| Graf

    %% Build & Testing Integration
    Maven -->|"builds"| Ctrl
    Maven -->|"builds"| Serv
    Tests -->|"validates"| Ctrl
    Tests -->|"validates"| Serv

    %% Configuration Impact
    Configurer -->|"configures"| Ctrl

    %% Click Events
    click Ctrl "https://github.com/witordias/animelistor/blob/main/src/main/java/br/com/animelistor/controllers/AnimeController.java"
    click Serv "https://github.com/witordias/animelistor/blob/main/src/main/java/br/com/animelistor/services/AnimeService.java"
    click Repo "https://github.com/witordias/animelistor/blob/main/src/main/java/br/com/animelistor/repository/AnimeRepository.java"
    click Anime "https://github.com/witordias/animelistor/blob/main/src/main/java/br/com/animelistor/domain/Anime.java"
    click Dto "https://github.com/witordias/animelistor/blob/main/src/main/java/br/com/animelistor/dto/AnimeDto.java"
    click Ex1 "https://github.com/witordias/animelistor/blob/main/src/main/java/br/com/animelistor/exception/BadRequestException.java"
    click Ex2 "https://github.com/witordias/animelistor/blob/main/src/main/java/br/com/animelistor/exception/BadRequestExceptionCustomizedFields.java"
    click Ex3 "https://github.com/witordias/animelistor/blob/main/src/main/java/br/com/animelistor/exception/ExceptionCustomFields.java"
    click Ex4 "https://github.com/witordias/animelistor/blob/main/src/main/java/br/com/animelistor/exception/ValidationExceptionCustomFields.java"
    click RestEx "https://github.com/witordias/animelistor/blob/main/src/main/java/br/com/animelistor/handler/RestExceptionHandler.java"
    click SecConfig "https://github.com/witordias/animelistor/blob/main/src/main/java/br/com/animelistor/config/SecurityConfig.java"
    click Configurer "https://github.com/witordias/animelistor/blob/main/src/main/java/br/com/animelistor/configurer/AnimeListorWebMvcConfigurer.java"
    click Docker "https://github.com/witordias/animelistor/blob/main/docker-compose.yml"
    click Prom "https://github.com/witordias/animelistor/blob/main/src/main/resources/prometheus.yml"
    click Tests "https://github.com/witordias/animelistor/tree/main/src/test/"

    %% Styles
    classDef client fill:#C5E1A5,stroke:#4CAF50,stroke-width:2px;
    classDef security fill:#FFF9C4,stroke:#FBC02D,stroke-width:2px;
    classDef controller fill:#BBDEFB,stroke:#1976D2,stroke-width:2px;
    classDef service fill:#FFCC80,stroke:#F57C00,stroke-width:2px;
    classDef repository fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
    classDef domain fill:#F8BBD0,stroke:#C2185B,stroke-width:2px;
    classDef exception fill:#FFCDD2,stroke:#D32F2F,stroke-width:2px;
    classDef config fill:#E1BEE7,stroke:#8E24AA,stroke-width:2px;
    classDef external fill:#FFE0B2,stroke:#FB8C00,stroke-width:2px;
    classDef build fill:#D7CCC8,stroke:#795548,stroke-width:2px;
    classDef testing fill:#C8E6C9,stroke:#388E3C,stroke-width:2px;
```
