# disilab-frba-utn-edu-ar/ejemplo-inicial-springboot architecture

> Architecture diagram of the GitHub repository disilab-frba-utn-edu-ar/ejemplo-inicial-springboot, 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/disilab-frba-utn-edu-ar/ejemplo-inicial-springboot
- Repository: https://github.com/disilab-frba-utn-edu-ar/ejemplo-inicial-springboot

## Overview

##### Main Components
- Application Entry Point:
- Application.java – marks the starting point of the Spring Boot application.
- REST Controllers:
- Controllers such as TurnoController and GlobalExceptionHandlerController that expose the API endpoints.
- Service Layer:
- Interfaces and their implementations (e.g., ITurnosService and TurnosService) that encapsulate business logic.
- Data Transfer Objects:
- DTO classes for input and output (e.g., TurnoInputDTO and TurnoOutputDTO) that are used to transfer data to/from the API.
- Data Mapping:
- Mappers (like TurnoMapper) to convert between entities and DTOs.
- Persistence/Repository Layer:
- Entities (e.g., Turno) and repositories (e.g., TurnoRepository) using Spring Data JPA for database operations.
- Exception Handling:
- Custom exception classes (e.g., NotFoundException) and a global exception controller.
- Database:
- The configuration indicates usage of H2 for in-memory testing, with options to switch to MySQL or PostgreSQL.
- Testing:
- Test directory (src/test) that can be represented as unit/integration tests verifying the components.

##### Defining Relationships and Interactions
- The Application entry point initializes the Spring context and loads all the components.
- REST controllers receive HTTP requests and pass the data (often in the form of DTOs) to the service layer.
- The service layer applies business rules and uses repositories to interact with the database.
- Repositories leverage JPA to map entity objects to persistent data.
- Mappers provide conversion between domain models and DTOs.
- Global Exception Handler captures and processes any exceptions that arise during request processing.
- External configuration (in application.properties and application-test.properties) informs the database setup, which should be illustrated as a connection between the application and the H2 database (with optional links to MySQL/PostgreSQL for production deployments).

##### Architectural Patterns and Principles
- MVC Pattern: Although this is a backend application, the separation of concerns between controllers (presentation), services (business logic), and repositories/models (data access) follows the MVC pattern.
- Layered Architecture: Clearly delineating controllers, services, and repositories.
- Dependency Injection: Managed by Spring Boot across components.
- Exception Handling: Centralized via a global exception controller.

- A top-level node labeled “Spring Boot Application” (starting with Application.java).
- Side-by-side or layered arrangement showing:
- REST API Controllers (global exception controller, TurnoController)
- Services (business logic in TurnosService)
- Data Mapping (TurnoMapper)
- Persistence layer, including Entities (Turno) and Repositories (TurnoRepository)
- Database (H2, with noted possibility for MySQL/PostgreSQL).
- Annotations noting external technologies (Java 17, Spring Boot 3, Spring Data JPA, Maven, Lombok) that help power the framework.
- Testing component demonstrating that unit tests (found under src/test) ensure the integrity of these modules.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Entry Point
    subgraph "Spring Boot Application"
        subgraph "Entry Point"
            A["Application.java"]:::entryPoint
        end
        
        %% API Layer
        subgraph "API Layer"
            TC["REST Controller - TurnoController"]:::controller
            GE["REST Controller - GlobalExceptionHandlerController"]:::controller
        end
        
        %% Service Layer
        subgraph "Service Layer"
            SI["Service Interface - ITurnosService"]:::service
            SS["Service Implementation - TurnosService"]:::service
        end
        
        %% DTOs and Mapper
        subgraph "DTO & Mapper"
            TID["DTO - TurnoInputDTO"]:::dto
            TOD["DTO - TurnoOutputDTO"]:::dto
            TM["Data Mapper - TurnoMapper"]:::mapper
        end
        
        %% Persistence Layer
        subgraph "Persistence Layer"
            E["Entity - Turno"]:::entity
            TR["Repository - TurnoRepository"]:::repository
        end
        
        %% Exception Handling
        subgraph "Exception Handling"
            NE["Exception - NotFoundException"]:::exception
        end
        
        %% Database
        subgraph "Database"
            DB["H2 Database"]:::database
        end
        
        %% Configuration
        subgraph "Configuration"
            AP["application.properties"]:::config
            AT["application-test.properties"]:::config
        end
        
        %% Testing
        subgraph "Testing"
            ATst["ApplicationTests"]:::testing
        end
    end

    %% Connections
    A -->|"initializes"| TC
    A -->|"initializes"| GE

    TC -->|"handles_request"| SI
    GE -->|"handles_exceptions"| NE

    SI -->|"implemented_by"| SS
    SS -->|"calls"| TR
    SS -->|"uses"| TM

    TID -->|"mapped_by"| TM
    TOD -->|"mapped_by"| TM

    TR -->|"persists"| E
    TR -->|"queries"| DB

    TC -->|"receives_DTO"| TID
    TC -->|"returns_DTO"| TOD

    AP -->|"configures"| DB
    AT -->|"configures_testing_DB"| DB

    ATst -->|"verifies"| A
    ATst -->|"verifies"| TC
    ATst -->|"verifies"| SS

    %% Click Events
    click A "https://github.com/disilab-frba-utn-edu-ar/ejemplo-inicial-springboot/blob/main/src/main/java/com/example/springboot/Application.java"
    click TC "https://github.com/disilab-frba-utn-edu-ar/ejemplo-inicial-springboot/blob/main/src/main/java/com/example/springboot/controllers/TurnoController.java"
    click GE "https://github.com/disilab-frba-utn-edu-ar/ejemplo-inicial-springboot/blob/main/src/main/java/com/example/springboot/controllers/GlobalExceptionHandlerController.java"
    click SI "https://github.com/disilab-frba-utn-edu-ar/ejemplo-inicial-springboot/blob/main/src/main/java/com/example/springboot/services/ITurnosService.java"
    click SS "https://github.com/disilab-frba-utn-edu-ar/ejemplo-inicial-springboot/blob/main/src/main/java/com/example/springboot/services/imp/TurnosService.java"
    click TID "https://github.com/disilab-frba-utn-edu-ar/ejemplo-inicial-springboot/blob/main/src/main/java/com/example/springboot/dtos/input/TurnoInputDTO.java"
    click TOD "https://github.com/disilab-frba-utn-edu-ar/ejemplo-inicial-springboot/blob/main/src/main/java/com/example/springboot/dtos/output/TurnoOutputDTO.java"
    click TM "https://github.com/disilab-frba-utn-edu-ar/ejemplo-inicial-springboot/blob/main/src/main/java/com/example/springboot/mappers/TurnoMapper.java"
    click E "https://github.com/disilab-frba-utn-edu-ar/ejemplo-inicial-springboot/blob/main/src/main/java/com/example/springboot/models/entities/Turno.java"
    click TR "https://github.com/disilab-frba-utn-edu-ar/ejemplo-inicial-springboot/blob/main/src/main/java/com/example/springboot/models/repositories/TurnoRepository.java"
    click NE "https://github.com/disilab-frba-utn-edu-ar/ejemplo-inicial-springboot/blob/main/src/main/java/com/example/springboot/exceptions/NotFoundException.java"
    click AP "https://github.com/disilab-frba-utn-edu-ar/ejemplo-inicial-springboot/blob/main/src/main/resources/application.properties"
    click AT "https://github.com/disilab-frba-utn-edu-ar/ejemplo-inicial-springboot/blob/main/src/main/resources/application-test.properties"
    click ATst "https://github.com/disilab-frba-utn-edu-ar/ejemplo-inicial-springboot/blob/main/src/test/java/com/example/springboot/ApplicationTests.java"

    %% Styles
    classDef entryPoint fill:#FFCC00,stroke:#333,stroke-width:2px;
    classDef controller fill:#AED6F1,stroke:#333,stroke-width:2px;
    classDef service fill:#A9DFBF,stroke:#333,stroke-width:2px;
    classDef dto fill:#D7BDE2,stroke:#333,stroke-width:2px;
    classDef mapper fill:#F5B7B1,stroke:#333,stroke-width:2px;
    classDef entity fill:#FAD7A0,stroke:#333,stroke-width:2px;
    classDef repository fill:#FDEBD0,stroke:#333,stroke-width:2px;
    classDef exception fill:#F1948A,stroke:#333,stroke-width:2px;
    classDef database fill:#E8DAEF,stroke:#333,stroke-width:2px;
    classDef config fill:#D1F2EB,stroke:#333,stroke-width:2px;
    classDef testing fill:#D6EAF8,stroke:#333,stroke-width:2px;
```
