# crsmusk/hotel-reservas-apirest architecture

> Architecture diagram of the GitHub repository crsmusk/hotel-reservas-apirest, 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/crsmusk/hotel-reservas-apirest
- Repository: https://github.com/crsmusk/hotel-reservas-apirest

## Overview

##### Main Components
- Backend Application: Represent the core application that uses Spring Boot—indicate the main entry point (ReservahabitacionesApplication.java).
- Controllers: Show the API endpoints for resources such as Clientes, Empleados, Habitaciones, Reservaciones, Permisos, and Roles. These are organized under the “Controller” package.
- Services: Include the service layer with both interfaces (e.g., ICliente, IEmpleado, … in “Service/Interface”) and their implementations (in “Service/Impl”). Also highlight the SecurityService (UserDetailService) component.
- Repositories: Represent the data access layer (e.g., ClienteRepository, HabitacionRepository, etc.) provided via Spring Data JPA.
- Models: Indicate the Entities (under Model/Entities) and DTOs (under Model/DTOs) that represent the domain – showing that data transfer and persistence are separated.
- Exception Handling: Include the exception packages (for custom errors, exception handlers) that ensure robust error management.
- Database: Although not explicitly defined in the file tree, infer a relational database component since Spring Data JPA is used.
- Configuration: Note configuration files like application.properties and security configuration (SecurityConfig.java).

##### Component Relationships and Data Flow
- The Controllers handle incoming HTTP requests and delegate to the Service layer.
- The Service layer contains business logic and interacts with Repositories to perform CRUD operations on Entities.
- Repositories communicate with the Database.
- DTOs in the Model layer are used to transfer data between Controllers and Services (and possibly map to Entities using Mapper classes).
- Global Exception Handlers intercept and process errors that occur in the Controllers or Services.
- The Security module (Spring Security/SecurityConfig and SecurityService) secures endpoints and manages role-based access control.

##### Architectural Patterns and Design Principles
- MVC (Model-View-Controller) Pattern: Although primarily a backend service, controllers, services, and repository layers reflect the separation of concerns.
- Layered Architecture: Clearly separated layers (Controller, Service, Repository) with mappers to move data between DTOs and Entities.
- Exception Handling: Centralized exception management with GlobalExceptionHandler.
- Dependency Injection: Utilized throughout the application (Spring Boot’s auto-configuration and dependency injection).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Request
    HTTPReq["HTTP Request"]

    %% Configuration Layer
    subgraph "Configuration Layer"
        App["ReservahabitacionesApplication"]
        AP["application.properties"]
    end

    %% Security Layer
    subgraph "Security Layer"
        SecConfig["SecurityConfig"]
        UserService["UserDetailService"]
    end

    %% API Layer
    subgraph "API Layer"
        Controllers["Controllers"]
    end

    %% Service Layer
    subgraph "Service Layer"
        ServiceI["Service Interfaces"]
        ServiceImpl["Service Implementations"]
        ServiceI --> ServiceImpl
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        Repositories["Repositories"]
    end

    %% Persistence Layer
    subgraph "Persistence"
        Database["Database"]
    end

    %% Domain Model
    subgraph "Domain Model"
        Entities["Entities"]
        DTOs["DTOs"]
        Mappers["Mappers"]
    end

    %% Exception Handling
    subgraph "Exception Handling"
        Exceptions["GlobalExceptionHandler"]
    end

    %% Flow connections
    HTTPReq -->|"intercepts"| SecConfig
    SecConfig -->|"configures"| UserService
    UserService -->|"authenticates"| Controllers
    Controllers -->|"delegates"| ServiceImpl
    ServiceImpl -->|"uses"| ServiceI
    ServiceImpl -->|"queries"| Repositories
    Repositories -->|"persists to"| Database
    ServiceImpl -->|"maps data"| Mappers
    Mappers -->|"converts to"| Entities
    Mappers -->|"converts to"| DTOs
    Controllers -->|"handles errors"| Exceptions
    ServiceImpl -->|"handles exceptions"| Exceptions

    %% Click Events
    click App "https://github.com/crsmusk/hotel-reservas-apirest/blob/master/src/main/java/com/hotel/reservahabitaciones/ReservahabitacionesApplication.java"
    click AP "https://github.com/crsmusk/hotel-reservas-apirest/blob/master/src/main/resources/application.properties"
    click SecConfig "https://github.com/crsmusk/hotel-reservas-apirest/blob/master/src/main/java/com/hotel/reservahabitaciones/Securiy/SecurityConfig.java"
    click UserService "https://github.com/crsmusk/hotel-reservas-apirest/blob/master/src/main/java/com/hotel/reservahabitaciones/Service/SecurityService/UserDetailService.java"
    click Controllers "https://github.com/crsmusk/hotel-reservas-apirest/tree/master/src/main/java/com/hotel/reservahabitaciones/Controller"
    click ServiceI "https://github.com/crsmusk/hotel-reservas-apirest/tree/master/src/main/java/com/hotel/reservahabitaciones/Service/Interface"
    click ServiceImpl "https://github.com/crsmusk/hotel-reservas-apirest/tree/master/src/main/java/com/hotel/reservahabitaciones/Service/Impl"
    click Repositories "https://github.com/crsmusk/hotel-reservas-apirest/tree/master/src/main/java/com/hotel/reservahabitaciones/Repository"
    click Entities "https://github.com/crsmusk/hotel-reservas-apirest/tree/master/src/main/java/com/hotel/reservahabitaciones/Model/Entities"
    click DTOs "https://github.com/crsmusk/hotel-reservas-apirest/tree/master/src/main/java/com/hotel/reservahabitaciones/Model/DTOs"
    click Mappers "https://github.com/crsmusk/hotel-reservas-apirest/tree/master/src/main/java/com/hotel/reservahabitaciones/Mapper"
    click Exceptions "https://github.com/crsmusk/hotel-reservas-apirest/tree/master/src/main/java/com/hotel/reservahabitaciones/Exception"

    %% Styling
    classDef config fill:#f9f,stroke:#333,stroke-width:2px;
    classDef security fill:#f96,stroke:#333,stroke-width:2px;
    classDef controller fill:#bbf,stroke:#333,stroke-width:2px;
    classDef service fill:#bfb,stroke:#333,stroke-width:2px;
    classDef repository fill:#ffb,stroke:#333,stroke-width:2px;
    classDef database fill:#cfc,stroke:#333,stroke-width:2px;
    classDef model fill:#fdd,stroke:#333,stroke-width:2px;
    classDef exception fill:#faa,stroke:#333,stroke-width:2px;

    class App,AP config;
    class SecConfig,UserService security;
    class Controllers controller;
    class ServiceI,ServiceImpl service;
    class Repositories repository;
    class Database database;
    class Entities,DTOs,Mappers model;
    class Exceptions exception;
```
