# altrof/selmefy_hotel_backend architecture

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

- Interactive diagram: https://gitdiagram.com/altrof/selmefy_hotel_backend
- Repository: https://github.com/altrof/selmefy_hotel_backend

## Overview

##### Main Components
- Application Entry & Bootstrapping:
- The HotelApplication.java class (located in tech.selmefy.hotel) serves as the Spring Boot entry point.
- Controllers (Presentation Layer):
- Organized into several domain-specific packages: auth, booking, hotelservice, hotelserviceorder, person, room, and user_account.
- That these controllers expose REST endpoints to the front end or external clients.
- Services (Business Logic Layer):
- Each major domain (auth, booking, room, etc.) has a corresponding service package.
- These components handle business logic and orchestrate data flows from controllers to repositories.
- Repositories & Data Access Layer:
- Each domain has its repository package (e.g., booking, person, room, etc.).
- These modules abstract the database communication and use ORM for persistence.
- Security Components:
- Spring Security configuration (WebSecurityConfig) and key classes like AuthTokenFilter, JwtTokenUtil, and AuthEntryPointJwt.
- How the AuthenticationProvider (using a UserDetailsService – implemented in UserAccountService or similar) handles credentials and token validation.
- Database:
- The PostgreSQL database is setup (as indicated by the docker-compose and sql_scripts files) and is managed with migration scripts using Liquibase (located under src/main/resources/db/changelog).
- Configurations & Utilities:
- Additional configurations are in dedicated packages (config for Swagger, TemplateConfig, security configuration, etc.) and fallback shared utilities (validators, email_sender, etc.).

##### Relationships and Interactions
- A client calls a REST endpoint on a Controller.
- The Controller interacts with the corresponding Service.
- The Service uses one or more Repositories to fetch or update data in the database.
- Security layers:
- Before a request reaches the Controller, it passes through a Security Filter (AuthTokenFilter) that uses JwtTokenUtil to verify the token. Any issues are handled by AuthEntryPointJwt.
- A DaoAuthenticationProvider in the security configuration integrates with the UserDetailsService to retrieve user-specific details.

##### Architectural Patterns and Design Principles
- Use a layered architecture (presentation, business, data) to separate concerns.
- Incorporate dependency injection and inversion of control as provided by Spring Boot.
- Stateless authentication with JWT, which influences the security design (no server sessions; instead, using tokens).
- How docker-compose and Dockerfile are used for deployment and local testing, representing infrastructure components that encapsulate the backend and the PostgreSQL database as separate services.

##### Relevant Technologies and Frameworks
- Java 17 with Spring Boot for the main application.
- Spring Security integrated with JWT (with references to spring-security-core, spring-security-web, and spring-security-config).
- Gradle for dependency management/build (build.gradle and settings.gradle).
- Liquibase for managing database migrations.
- Docker and docker-compose for containerized deployment.
- Swagger for API documentation and possibly Spring MVC configurations.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Clients
    EC["External Clients"]:::external

    %% Bootstrapping
    HA["HotelApplication (Main Entry)"]:::bootstrapping

    %% Security Module
    subgraph "Security Module"
        WS["WebSecurityConfig"]:::security
        ATF["AuthTokenFilter"]:::security
        JTU["JwtTokenUtil"]:::security
        AEJ["AuthEntryPointJwt"]:::security
        JUDS["JwtUserDetailsService"]:::security
    end

    %% API Controllers
    subgraph "API Controllers"
        AC["Auth Controller"]:::controller
        BC["Booking Controller"]:::controller
        HSC["Hotel Service Controller"]:::controller
        HSOC["Hotel Service Order Controller"]:::controller
        PC["Person Controller"]:::controller
        RC["Room Controller"]:::controller
        UAC["User Account Controller"]:::controller
    end

    %% Service Layer
    subgraph "Service Layer"
        AS["Auth Service"]:::service
        BS["Booking Service"]:::service
        HSS["Hotel Service Service"]:::service
        HSOS["Hotel Service Order Service"]:::service
        PS["Person Service"]:::service
        RS["Room Service"]:::service
        UAS["User Account Service"]:::service
    end

    %% Repositories
    subgraph "Repositories"
        AR["Auth Repository"]:::repository
        BR["Booking Repository"]:::repository
        HSR["Hotel Service Repository"]:::repository
        HSOR["Hotel Service Order Repository"]:::repository
        PR["Person Repository"]:::repository
        RR["Room Repository"]:::repository
        UAR["User Account Repository"]:::repository
    end

    %% Database Layer
    subgraph "Database Layer"
        DB[(PostgreSQL Database)]:::database
        LM["Liquibase Migrations"]:::database
    end

    %% Configurations & Utilities
    subgraph "Configurations & Utilities"
        SC["Swagger & Configurations"]:::config
        EU["Email Utilities & Validators"]:::config
    end

    %% Deployment & Infrastructure
    subgraph "Deployment & Infrastructure"
        DAPP["Docker - Backend Application"]:::deployment
        DC["Docker Compose Setup"]:::deployment
    end

    %% Connections
    EC -->|"request"| ATF
    ATF -->|"authenticated"| AC
    ATF -->|"authenticated"| BC
    ATF -->|"authenticated"| HSC
    ATF -->|"authenticated"| HSOC
    ATF -->|"authenticated"| PC
    ATF -->|"authenticated"| RC
    ATF -->|"authenticated"| UAC

    HA --> AC
    HA --> BC
    HA --> HSC
    HA --> HSOC
    HA --> PC
    HA --> RC
    HA --> UAC

    AC -->|"calls"| AS
    BC -->|"calls"| BS
    HSC -->|"calls"| HSS
    HSOC -->|"calls"| HSOS
    PC -->|"calls"| PS
    RC -->|"calls"| RS
    UAC -->|"calls"| UAS

    AS -->|"uses"| AR
    BS -->|"uses"| BR
    HSS -->|"uses"| HSR
    HSOS -->|"uses"| HSOR
    PS -->|"uses"| PR
    RS -->|"uses"| RR
    UAS -->|"uses"| UAR

    AR -->|"persists to"| DB
    BR -->|"persists to"| DB
    HSR -->|"persists to"| DB
    HSOR -->|"persists to"| DB
    PR -->|"persists to"| DB
    RR -->|"persists to"| DB
    UAR -->|"persists to"| DB

    LM -->|"migrates"| DB

    %% Security Internal Connections
    WS --> ATF
    ATF --> JTU
    WS --> JUDS
    AEJ --> JUDS

    %% Deployment Connections
    DAPP --> HA
    DC --> DAPP
    DC --> DB

    %% Click Events
    click HA "https://github.com/altrof/selmefy_hotel_backend/blob/dev/src/main/java/tech/selmefy/hotel/HotelApplication.java"
    click AC "https://github.com/altrof/selmefy_hotel_backend/tree/dev/src/main/java/tech/selmefy/hotel/controller/auth"
    click BC "https://github.com/altrof/selmefy_hotel_backend/tree/dev/src/main/java/tech/selmefy/hotel/controller/booking"
    click HSC "https://github.com/altrof/selmefy_hotel_backend/tree/dev/src/main/java/tech/selmefy/hotel/controller/hotelservice"
    click HSOC "https://github.com/altrof/selmefy_hotel_backend/tree/dev/src/main/java/tech/selmefy/hotel/controller/hotelserviceorder"
    click PC "https://github.com/altrof/selmefy_hotel_backend/tree/dev/src/main/java/tech/selmefy/hotel/controller/person"
    click RC "https://github.com/altrof/selmefy_hotel_backend/tree/dev/src/main/java/tech/selmefy/hotel/controller/room"
    click UAC "https://github.com/altrof/selmefy_hotel_backend/tree/dev/src/main/java/tech/selmefy/hotel/controller/user_account"
    click AS "https://github.com/altrof/selmefy_hotel_backend/tree/dev/src/main/java/tech/selmefy/hotel/service/auth"
    click BS "https://github.com/altrof/selmefy_hotel_backend/tree/dev/src/main/java/tech/selmefy/hotel/service/booking"
    click HSS "https://github.com/altrof/selmefy_hotel_backend/tree/dev/src/main/java/tech/selmefy/hotel/service/hotelservice"
    click HSOS "https://github.com/altrof/selmefy_hotel_backend/tree/dev/src/main/java/tech/selmefy/hotel/service/hotelserviceorder"
    click PS "https://github.com/altrof/selmefy_hotel_backend/tree/dev/src/main/java/tech/selmefy/hotel/service/person"
    click RS "https://github.com/altrof/selmefy_hotel_backend/tree/dev/src/main/java/tech/selmefy/hotel/service/room"
    click UAS "https://github.com/altrof/selmefy_hotel_backend/tree/dev/src/main/java/tech/selmefy/hotel/service/user_account"
    click AR "https://github.com/altrof/selmefy_hotel_backend/tree/dev/src/main/java/tech/selmefy/hotel/repository/auth"
    click BR "https://github.com/altrof/selmefy_hotel_backend/tree/dev/src/main/java/tech/selmefy/hotel/repository/booking"
    click HSR "https://github.com/altrof/selmefy_hotel_backend/tree/dev/src/main/java/tech/selmefy/hotel/repository/hotelservice"
    click HSOR "https://github.com/altrof/selmefy_hotel_backend/tree/dev/src/main/java/tech/selmefy/hotel/repository/hotelserviceorder"
    click PR "https://github.com/altrof/selmefy_hotel_backend/tree/dev/src/main/java/tech/selmefy/hotel/repository/person"
    click RR "https://github.com/altrof/selmefy_hotel_backend/tree/dev/src/main/java/tech/selmefy/hotel/repository/room"
    click UAR "https://github.com/altrof/selmefy_hotel_backend/tree/dev/src/main/java/tech/selmefy/hotel/repository/user_account"
    click WS "https://github.com/altrof/selmefy_hotel_backend/blob/dev/src/main/java/tech/selmefy/hotel/security/config/WebSecurityConfig.java"
    click ATF "https://github.com/altrof/selmefy_hotel_backend/blob/dev/src/main/java/tech/selmefy/hotel/security/jwt/AuthTokenFilter.java"
    click JTU "https://github.com/altrof/selmefy_hotel_backend/blob/dev/src/main/java/tech/selmefy/hotel/security/jwt/JwtTokenUtil.java"
    click AEJ "https://github.com/altrof/selmefy_hotel_backend/blob/dev/src/main/java/tech/selmefy/hotel/security/jwt/AuthEntryPointJwt.java"
    click JUDS "https://github.com/altrof/selmefy_hotel_backend/blob/dev/src/main/java/tech/selmefy/hotel/security/services/JwtUserDetailsService.java"
    click SC "https://github.com/altrof/selmefy_hotel_backend/tree/dev/src/main/java/tech/selmefy/hotel/config"
    click EU "https://github.com/altrof/selmefy_hotel_backend/tree/dev/src/main/java/tech/selmefy/hotel/utils/email_sender"
    click LM "https://github.com/altrof/selmefy_hotel_backend/tree/dev/src/main/resources/db/changelog"
    click DC "https://github.com/altrof/selmefy_hotel_backend/blob/dev/docker-compose.yml"

    %% Styles
    classDef external fill:#FCE4EC,stroke:#E91E63,stroke-width:2px;
    classDef bootstrapping fill:#E0F7FA,stroke:#00BCD4,stroke-width:2px;
    classDef controller fill:#E3F2FD,stroke:#2196F3,stroke-width:2px;
    classDef service fill:#E8F5E9,stroke:#4CAF50,stroke-width:2px;
    classDef repository fill:#FFF3E0,stroke:#FF9800,stroke-width:2px;
    classDef security fill:#F3E5F5,stroke:#9C27B0,stroke-width:2px;
    classDef database fill:#FFEBEE,stroke:#F44336,stroke-width:2px;
    classDef config fill:#F1F8E9,stroke:#8BC34A,stroke-width:2px;
    classDef deployment fill:#ECEFF1,stroke:#607D8B,stroke-width:2px;
```
