# cryselayala98/proyecto-api architecture

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

- Interactive diagram: https://gitdiagram.com/cryselayala98/proyecto-api
- Repository: https://github.com/cryselayala98/proyecto-api

## Overview

##### Main Components
- API Application: At the heart is the Spring Boot application (ApiApplication.java) that bootstraps the entire service.
- Controllers: Exposed endpoints are handled by controllers such as HistoryController and MathOperationsController.
- Services: Business logic is managed by service components (MathOperationsService, HistoryCallService, ResponseService) implemented in their respective impl classes.
- Repository Layer: Persistence logic for history calls, responses, and caching is handled by repository classes such as HistoryCallRepository and ResponseRepository.
- Caching Mechanism: There is a caching layer that uses dedicated classes (RedisEntity, PercentageCacheRepository, PercentageCacheService) with their implementations.
- External Services: Components under externalServices (PercentageService, ExternalCallsService) indicate integration with external systems.
- Configuration: Several configuration classes (CacheConfig, OpenApiConfig, WebClientConfig, PageableWebFluxConfiguration, WebConfig) set up the runtime environment and dependencies (e.g., for caching and reactive web features).
- Database & Redis: Although not directly in the code, the inclusion of script.sql and docker-compose.yml indicates a database container. Redis, used for caching, is also spun up via Docker.

- Presentation Layer: Controllers that receive HTTP requests.
- Business Logic Layer: Service classes that implement the core computation and delegation to cache/external service calls.
- Data Access Layer: Repositories that handle persistence for entities such as HistoryCall and Response.
- Caching Layer: Redis cache components showing the flow of data between the application and Redis.
- Integration with External Systems:
- Database: Represented by a separate database container (as indicated by script.sql and docker-compose) where the repositories operate.
- Infrastructure and Deployment:
- Docker: Include Docker containers for the entire API, Redis, and the database. Indicate that “docker-compose” sets up these containers.
- Configuration management: Note how configuration classes set up routing, caching, and API documentation (Swagger setup available via ApiHub and local URL).

##### Architectural Patterns and Design Principles
- MVC / Layered Architecture: Controllers, services, and repositories are clearly separated.
- Reactive Programming: Emphasize that the system is built using Spring WebFlux to support non-blocking operations which is a core design principle.
- Caching Strategy: Highlight the cache mechanism integration between controllers/services and Redis for performance improvements.
- Integration / External Service Calls: Indicate that some service logic is delegated to external APIs or services.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Presentation Layer
    subgraph "Presentation Layer"
        A["API Application"]:::app
        subgraph "Controllers"
            B["HistoryController"]:::controller
            C["MathOperationsController"]:::controller
        end
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        subgraph "Services"
            D["MathOperationsService"]:::service
            E["MathOperationsServiceImpl"]:::service
            F["HistoryCallService"]:::service
            G["HistoryCallServiceImpl"]:::service
            H["ResponseService"]:::service
            I["ResponseServiceImpl"]:::service
        end
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        J["HistoryCallRepository"]:::repository
        K["ResponseRepository"]:::repository
    end

    %% Caching Layer
    subgraph "Caching Layer"
        L["RedisEntity"]:::cache
        subgraph "Cache Repositories"
            M["PercentageCacheRepository"]:::cache
            N["PercentageCacheRepositoryImpl"]:::cache
        end
        subgraph "Cache Services"
            O["PercentageCacheService"]:::cache
            P["PercentageCacheServiceImpl"]:::cache
        end
    end

    %% External Services
    subgraph "External Services"
        Q["PercentageService"]:::external
        R["PercentageServiceImpl"]:::external
        S["ExternalCallsService"]:::external
        T["ExternalCallsServiceImpl"]:::external
    end

    %% Configuration
    subgraph "Configuration"
        U["CacheConfig"]:::config
        V["OpenApiConfig"]:::config
        W["WebClientConfig"]:::config
        X["PageableWebFluxConfiguration"]:::config
        Y["WebConfig"]:::config
    end

    %% Deployment
    subgraph "Deployment"
        Z["API Container"]:::deploy
        AA["Redis Container"]:::deploy
        AB["Database Container"]:::deploy
        AC["Docker Compose Setup"]:::deploy
        AD["Database Script (script.sql)"]:::deploy
    end

    %% Connections between layers
    %% API Application bootstraps controllers and services via incoming HTTP requests
    A -->|"init"| B
    A -->|"init"| C

    %% Controllers invoke services
    B -->|"calls"| G
    C -->|"calls"| E

    %% Service Layer interactions
    E -->|"executes"| O
    E -->|"calls"| T
    G -->|"persists"| J
    I -->|"persists"| K

    %% Service implementations to their interfaces
    D --- E
    F --- G
    H --- I

    %% Caching Layer interactions
    O -->|"accesses"| N
    P --- O
    %% Redis entity used within caching implementation
    P -->|"manages"| L

    %% External Services usage
    R --- Q
    T --- S

    %% Data Access Layer interactions
    G -->|"saves data"| J
    I -->|"saves data"| K

    %% Configuration is used for system setup (dotted associations)
    A --- U
    A --- V
    A --- W
    A --- X
    A --- Y

    %% Deployment relationships
    Z -->|"hosts"| A
    Z -->|"hosts"| B
    Z -->|"hosts"| C
    Z -->|"hosts"| D
    Z -->|"hosts"| E
    Z -->|"hosts"| F
    Z -->|"hosts"| G
    Z -->|"hosts"| H
    Z -->|"hosts"| I
    Z -->|"hosts"| J
    Z -->|"hosts"| K
    Z -->|"hosts"| L
    Z -->|"hosts"| M
    Z -->|"hosts"| N
    Z -->|"hosts"| O
    Z -->|"hosts"| P
    Z -->|"hosts"| Q
    Z -->|"hosts"| R
    Z -->|"hosts"| S
    Z -->|"hosts"| T
    Z -->|"hosts"| U
    Z -->|"hosts"| V
    Z -->|"hosts"| W
    Z -->|"hosts"| X
    Z -->|"hosts"| Y

    %% Deployment interconnects
    Z --- AC
    AA --- AC
    AB --- AC
    AB --- AD

    %% Click Events
    click A "https://github.com/cryselayala98/proyecto-api/blob/main/src/main/java/crisel/ayala/api/ApiApplication.java"
    click B "https://github.com/cryselayala98/proyecto-api/blob/main/src/main/java/crisel/ayala/api/controller/HistoryController.java"
    click C "https://github.com/cryselayala98/proyecto-api/blob/main/src/main/java/crisel/ayala/api/controller/MathOperationsController.java"
    click D "https://github.com/cryselayala98/proyecto-api/blob/main/src/main/java/crisel/ayala/api/service/MathOperationsService.java"
    click E "https://github.com/cryselayala98/proyecto-api/blob/main/src/main/java/crisel/ayala/api/service/impl/MathOperationsServiceImpl.java"
    click F "https://github.com/cryselayala98/proyecto-api/blob/main/src/main/java/crisel/ayala/api/service/HistoryCallService.java"
    click G "https://github.com/cryselayala98/proyecto-api/blob/main/src/main/java/crisel/ayala/api/service/impl/HistoryCallServiceImpl.java"
    click H "https://github.com/cryselayala98/proyecto-api/blob/main/src/main/java/crisel/ayala/api/service/ResponseService.java"
    click I "https://github.com/cryselayala98/proyecto-api/blob/main/src/main/java/crisel/ayala/api/service/impl/ResponseServiceImpl.java"
    click J "https://github.com/cryselayala98/proyecto-api/blob/main/src/main/java/crisel/ayala/api/repository/HistoryCallRepository.java"
    click K "https://github.com/cryselayala98/proyecto-api/blob/main/src/main/java/crisel/ayala/api/repository/ResponseRepository.java"
    click L "https://github.com/cryselayala98/proyecto-api/blob/main/src/main/java/crisel/ayala/api/cache/model/RedisEntity.java"
    click M "https://github.com/cryselayala98/proyecto-api/blob/main/src/main/java/crisel/ayala/api/cache/repository/PercentageCacheRepository.java"
    click N "https://github.com/cryselayala98/proyecto-api/blob/main/src/main/java/crisel/ayala/api/cache/repository/impl/PercentageCacheRepositoryImpl.java"
    click O "https://github.com/cryselayala98/proyecto-api/blob/main/src/main/java/crisel/ayala/api/cache/service/PercentageCacheService.java"
    click P "https://github.com/cryselayala98/proyecto-api/blob/main/src/main/java/crisel/ayala/api/cache/service/impl/PercentageCacheServiceImpl.java"
    click Q "https://github.com/cryselayala98/proyecto-api/blob/main/src/main/java/crisel/ayala/api/externalServices/PercentageService.java"
    click R "https://github.com/cryselayala98/proyecto-api/blob/main/src/main/java/crisel/ayala/api/externalServices/impl/PercentageServiceImpl.java"
    click S "https://github.com/cryselayala98/proyecto-api/blob/main/src/main/java/crisel/ayala/api/externalServices/ExternalCallsService.java"
    click T "https://github.com/cryselayala98/proyecto-api/blob/main/src/main/java/crisel/ayala/api/externalServices/impl/ExternalCallsServiceImpl.java"
    click U "https://github.com/cryselayala98/proyecto-api/blob/main/src/main/java/crisel/ayala/api/configuration/CacheConfig.java"
    click V "https://github.com/cryselayala98/proyecto-api/blob/main/src/main/java/crisel/ayala/api/configuration/OpenApiConfig.java"
    click W "https://github.com/cryselayala98/proyecto-api/blob/main/src/main/java/crisel/ayala/api/configuration/WebClientConfig.java"
    click X "https://github.com/cryselayala98/proyecto-api/blob/main/src/main/java/crisel/ayala/api/configuration/PageableWebFluxConfiguration.java"
    click Y "https://github.com/cryselayala98/proyecto-api/blob/main/src/main/java/crisel/ayala/api/configuration/WebConfig.java"
    click AD "https://github.com/cryselayala98/proyecto-api/blob/main/script.sql"
    click AC "https://github.com/cryselayala98/proyecto-api/blob/main/docker-compose.yml"

    %% Styles
    classDef app fill:#d9e8c3,stroke:#000,stroke-width:1px;
    classDef controller fill:#ffcc00,stroke:#000,stroke-width:1px;
    classDef service fill:#99ccff,stroke:#000,stroke-width:1px;
    classDef repository fill:#ccffcc,stroke:#000,stroke-width:1px;
    classDef cache fill:#ffcccc,stroke:#000,stroke-width:1px;
    classDef external fill:#ffffcc,stroke:#000,stroke-width:1px;
    classDef config fill:#e0e0e0,stroke:#000,stroke-width:1px;
    classDef deploy fill:#f9d6cc,stroke:#000,stroke-width:1px;
```
