# davidfparrab/reserva-tickets architecture

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

- Interactive diagram: https://gitdiagram.com/davidfparrab/reserva-tickets
- Repository: https://github.com/davidfparrab/reserva-tickets

## Overview

##### Main Components
- Service Layer (Business Logic)
– Controllers: e.g., ReservaController and ShowController which expose REST endpoints.
– Services: e.g., BookService, ShowService, and ValidationService that encapsulate business rules and transaction management (for updating seats and reservations in one atomic operation).
- Data Access Layer
– Repositories: Interfaces like BookRepository, LocationRepository, SeatRepository, and ShowRepository along with their implementations.
– Firestore: The NoSQL database (using the Firestore SDK) that holds collections for objects (books/reservations, locations, seats, shows).
- Security Layer
– Security Token Bearer: Two types of tokens for differentiation between app users and admin users.
- Data Transfer Objects and Models
– DTOs: Objects like Filter that are used to process requests (especially for the filtering endpoints).
– Domain Models: Classes like Book, Location, Seat, and Show represent the domain structure.
- External Integration
– The application interacts externally via HTTP REST API endpoints.
– It includes transactional behavior with Firestore to maintain database consistency.

##### Relationships and Interactions
- The Client (user app or admin user) sends an HTTP request (for reserving, querying availability, or filtering shows) with an Authorization header (Bearer tokens).
- The REST Controllers (ReservaController, ShowController) receive these requests.
- Controllers delegate processing to the Service layer, which applies business logic.
- Services interact with Repositories to perform CRUD operations on Firestore. The transaction modality ensures that, for instance, seat reservations are atomic.
- The security mechanism intercepts the requests early to validate the tokens before the request reaches the controller.
- Responses (JSON) are sent back through the REST controllers.

##### Architectural Patterns & Design Principles
- Layered Architecture: Clearly separating the controller (API), service (business logic), and repository (data access) layers.
- Dependency Inversion: The use of interfaces for service and repository implementations suggests that dependency injection is at work (a typical Spring Boot pattern).
- Transaction Management: The use of one transaction per reservation creation in Firestore ensures reliability during seat reservation.
- Security Model: Token-based authentication with clearly defined roles (APP user vs. ADMIN) delineates responsibilities.

##### Relevant Technologies, Frameworks & Libraries
- Java with Spring Boot (as seen in the structure with meli/reserva/tickets and the main application class).
- Firestore (NoSQL database SDK), chosen for its simplicity with collections and its transactional support.
- Maven (based on the pom.xml and mvnw scripts) for dependency and build management.
- Docker (Dockerfile present) possibly for deploying the application as a container.
- Testing: JUnit tests as indicated under the src/test directory.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client (User/App/Admin)"]:::client
    Security["Security TokenValidation (BearerToken)"]:::security

    Client -->|"HTTPRequestwithBearerToken"| Security
    Security -->|"ValidatedRequest"| Controllers1

    subgraph "Controllers (REST API)"
        ReservaCtrl["ReservaController"]:::api
        ShowCtrl["ShowController"]:::api
    end
    Controllers1[DummyControllers]:::api
    Controllers1 --- ReservaCtrl
    Controllers1 --- ShowCtrl

    ReservaCtrl -->|"DelegatesTo"| BookService
    ReservaCtrl -->|"ValidatesInput"| ValidationService
    ShowCtrl -->|"DelegatesTo"| ShowService
    ShowCtrl -->|"ValidatesInput"| ValidationService

    subgraph "Services (Business Logic)"
        BookService["BookService (interface)"]:::service
        ShowService["ShowService (interface)"]:::service
        ValidationService["ValidationService (interface)"]:::service

        BookServiceImpl["BookServiceImpl"]:::service
        ShowServiceImpl["ShowServiceImpl"]:::service
        ValidationServiceImpl["ValidationServiceImpl"]:::service
    end

    BookService -->|"ImplementedBy"| BookServiceImpl
    ShowService -->|"ImplementedBy"| ShowServiceImpl
    ValidationService -->|"ImplementedBy"| ValidationServiceImpl

    BookServiceImpl -->|"CallsCRUD"| BookRepo
    BookServiceImpl -->|"Invokes"| LocationRepo
    BookServiceImpl -->|"Invokes"| SeatRepo
    ShowServiceImpl -->|"CallsRepository"| ShowRepoImpl

    subgraph "Repositories (Data Access)"
        BookRepo["BookRepository (interface)"]:::repository
        LocationRepo["LocationRepository (interface)"]:::repository
        SeatRepo["SeatRepository (interface)"]:::repository
        ShowRepo["ShowRepository (interface)"]:::repository

        LocationRepoImpl["LocationRepositoryImpl"]:::repository
        SeatRepoImpl["SeatRepositoryImpl"]:::repository
        ShowRepoImpl["ShowRepositoryImpl"]:::repository
    end

    LocationRepo -->|"ImplementedBy"| LocationRepoImpl
    SeatRepo -->|"ImplementedBy"| SeatRepoImpl
    ShowRepo -->|"ImplementedBy"| ShowRepoImpl

    BookRepo ---|"PersistsTo"| Firestore
    LocationRepoImpl ---|"PersistsTo"| Firestore
    SeatRepoImpl ---|"PersistsTo"| Firestore
    ShowRepoImpl ---|"PersistsTo"| Firestore

    Firestore["FirestoreDatabase"]:::database

    subgraph "DataModels & DTOs"
        FilterDTO["Filter (DTO)"]:::model
        BookModel["Book"]:::model
        LocationModel["Location"]:::model
        SeatModel["Seat"]:::model
        ShowModel["Show"]:::model
    end

    subgraph "Bootstrap & Utilities"
        AppBootstrap["ReservaTicketsApplication"]:::bootstrap
        Utils["Utils"]:::bootstrap
    end

    %% Styles
    classDef client fill:#EFEFEF,stroke:#333,stroke-width:2px
    classDef security fill:#FCD09C,stroke:#333,stroke-width:2px
    classDef api fill:#F9C2FF,stroke:#333,stroke-width:2px
    classDef service fill:#C2EAFF,stroke:#333,stroke-width:2px
    classDef repository fill:#C2FFC2,stroke:#333,stroke-width:2px
    classDef database fill:#FFC2C2,stroke:#333,stroke-width:2px
    classDef model fill:#FFF7A3,stroke:#333,stroke-width:2px
    classDef bootstrap fill:#A3FFF7,stroke:#333,stroke-width:2px

    %% Click Events
    click ReservaCtrl "https://github.com/davidfparrab/reserva-tickets/blob/main/src/main/java/meli/reserva/tickets/controller/ReservaController.java"
    click ShowCtrl "https://github.com/davidfparrab/reserva-tickets/blob/main/src/main/java/meli/reserva/tickets/controller/ShowController.java"

    click BookService "https://github.com/davidfparrab/reserva-tickets/blob/main/src/main/java/meli/reserva/tickets/service/BookService.java"
    click ShowService "https://github.com/davidfparrab/reserva-tickets/blob/main/src/main/java/meli/reserva/tickets/service/ShowService.java"
    click ValidationService "https://github.com/davidfparrab/reserva-tickets/blob/main/src/main/java/meli/reserva/tickets/service/ValidationService.java"
    click BookServiceImpl "https://github.com/davidfparrab/reserva-tickets/blob/main/src/main/java/meli/reserva/tickets/service/impl/BookServiceImpl.java"
    click ShowServiceImpl "https://github.com/davidfparrab/reserva-tickets/blob/main/src/main/java/meli/reserva/tickets/service/impl/ShowServiceImpl.java"
    click ValidationServiceImpl "https://github.com/davidfparrab/reserva-tickets/blob/main/src/main/java/meli/reserva/tickets/service/impl/ValidationServiceImpl.java"

    click BookRepo "https://github.com/davidfparrab/reserva-tickets/blob/main/src/main/java/meli/reserva/tickets/repository/BookRepository.java"
    click LocationRepo "https://github.com/davidfparrab/reserva-tickets/blob/main/src/main/java/meli/reserva/tickets/repository/LocationRepository.java"
    click SeatRepo "https://github.com/davidfparrab/reserva-tickets/blob/main/src/main/java/meli/reserva/tickets/repository/SeatRepository.java"
    click ShowRepo "https://github.com/davidfparrab/reserva-tickets/blob/main/src/main/java/meli/reserva/tickets/repository/ShowRepository.java"
    click LocationRepoImpl "https://github.com/davidfparrab/reserva-tickets/blob/main/src/main/java/meli/reserva/tickets/repository/impl/LocationRepositoryImpl.java"
    click SeatRepoImpl "https://github.com/davidfparrab/reserva-tickets/blob/main/src/main/java/meli/reserva/tickets/repository/impl/SeatRepositoryImpl.java"
    click ShowRepoImpl "https://github.com/davidfparrab/reserva-tickets/blob/main/src/main/java/meli/reserva/tickets/repository/impl/ShowRepositoryImpl.java"

    click FilterDTO "https://github.com/davidfparrab/reserva-tickets/blob/main/src/main/java/meli/reserva/tickets/dto/Filter.java"

    click BookModel "https://github.com/davidfparrab/reserva-tickets/blob/main/src/main/java/meli/reserva/tickets/model/Book.java"
    click LocationModel "https://github.com/davidfparrab/reserva-tickets/blob/main/src/main/java/meli/reserva/tickets/model/Location.java"
    click SeatModel "https://github.com/davidfparrab/reserva-tickets/blob/main/src/main/java/meli/reserva/tickets/model/Seat.java"
    click ShowModel "https://github.com/davidfparrab/reserva-tickets/blob/main/src/main/java/meli/reserva/tickets/model/Show.java"

    click AppBootstrap "https://github.com/davidfparrab/reserva-tickets/blob/main/src/main/java/meli/reserva/tickets/ReservaTicketsApplication.java"
    click Utils "https://github.com/davidfparrab/reserva-tickets/blob/main/src/main/java/meli/reserva/tickets/Utils.java"
```
