# paviag/proyecto-01 architecture

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

- Interactive diagram: https://gitdiagram.com/paviag/proyecto-01
- Repository: https://github.com/paviag/proyecto-01

## Overview

##### Project Type & Purpose
- This is a backend service, most likely a RESTful API that manages entities such as books, users, and reservations.
- Its purpose is to provide endpoints for creating, reading, updating, and disabling (soft deletion) these entities.
- The existence of middleware (e.g., an auth file) and a database connection (db.ts) indicate that security and persistence are also key aspects.

##### Main Components to Identify
a. Server & Application Bootstrapping:
- server.ts and app.ts are responsible for initializing the backend application and handling incoming HTTP requests.
b. Modules/Domain Areas:
- Book Module: Contains a controller, model, routes, types, and various action files (create, read, update, disable).
- User Module: Similarly segmented with its controller, model, routes, types, and action files.
- Reservation Module: Contains action files, a model, and types, while likely following similar patterns.
c. Database:
- db.ts represents the connection and likely the setup for a database.
d. Middleware:
- Middleware folder (e.g., auth.ts) handles authentication or other request preprocessing.
e. Configuration Files:

##### Structuring Relationships & Interactions
- Global/Middleware Layer: Illustrate middleware (auth) intercepting requests before they are passed to the components.
- Routing & Controller Delegation:
- The server routes the requests based on URL patterns to the respective module’s route files (book.routes.ts, user.routes.ts).
- The route files then delegate the request to the module’s controller (e.g., book.controller.ts, user.controller.ts).
- Service/Action Invocation:
- Controllers then call one or more action files (e.g., create.book.action.ts) that handle business logic.
- Data Persistence:
- After executing business logic, each module interacts with the database component (via db.ts) through model components (book.model.ts, user.model.ts, reservation.model.ts).
- Data Flow Back: The response flows back through controllers to the client.

## Diagram (Mermaid)

```mermaid
graph TB
    ExternalClient["External Client"]:::external

    subgraph "Bootstrapping"
        TS["Server (server.ts)"]:::bootstrap
        APP["Application (app.ts)"]:::bootstrap
    end

    AuthMiddleware["Auth Middleware"]:::middleware

    subgraph "Book Module"
        BRoutes["Book Routes"]:::route
        BController["Book Controller"]:::controller
        CreateBook["Create Book Action"]:::action
        DisableBook["Disable Book Action"]:::action
        ReadBooks["Read Books Action"]:::action
        ReadOneBook["Read One Book Action"]:::action
        UpdateBook["Update Book Action"]:::action
        BModel["Book Model"]:::model
        BTypes["Book Types"]:::types
    end

    subgraph "User Module"
        URoutes["User Routes"]:::route
        UController["User Controller"]:::controller
        CheckEnabledUser["CheckEnabled User Action"]:::action
        CreateUser["Create User Action"]:::action
        DisableUser["Disable User Action"]:::action
        ReadUser["Read User Action"]:::action
        UpdateUser["Update User Action"]:::action
        UModel["User Model"]:::model
        UTypes["User Types"]:::types
    end

    subgraph "Reservation Module"
        CreateReservation["Create Reservation Action"]:::action
        ReadReservations["Read Reservations Action"]:::action
        SetReturnDate["Set Return Date Action"]:::action
        RModel["Reservation Model"]:::model
        RTypes["Reservation Types"]:::types
    end

    DB["Database"]:::database

    %% Connections for Bootstrapping & Middleware
    ExternalClient --> TS
    TS --> APP
    APP --> AuthMiddleware

    %% Connections for Book Module
    AuthMiddleware --> BRoutes
    BRoutes --> BController
    BController --> CreateBook
    BController --> DisableBook
    BController --> ReadBooks
    BController --> ReadOneBook
    BController --> UpdateBook
    CreateBook --> BModel
    DisableBook --> BModel
    ReadBooks --> BModel
    ReadOneBook --> BModel
    UpdateBook --> BModel
    BController ---|"uses"| BTypes
    BModel --> DB

    %% Connections for User Module
    AuthMiddleware --> URoutes
    URoutes --> UController
    UController --> CheckEnabledUser
    UController --> CreateUser
    UController --> DisableUser
    UController --> ReadUser
    UController --> UpdateUser
    CheckEnabledUser --> UModel
    CreateUser --> UModel
    DisableUser --> UModel
    ReadUser --> UModel
    UpdateUser --> UModel
    UController ---|"uses"| UTypes
    UModel --> DB

    %% Connections for Reservation Module
    AuthMiddleware --> CreateReservation
    AuthMiddleware --> ReadReservations
    AuthMiddleware --> SetReturnDate
    CreateReservation --> RModel
    ReadReservations --> RModel
    SetReturnDate --> RModel
    RModel ---|"defines"| RTypes
    RModel --> DB

    %% Click Events
    click TS "https://github.com/paviag/proyecto-01/blob/main/src/server.ts"
    click APP "https://github.com/paviag/proyecto-01/blob/main/src/app.ts"
    click BRoutes "https://github.com/paviag/proyecto-01/blob/main/src/book/book.routes.ts"
    click BController "https://github.com/paviag/proyecto-01/blob/main/src/book/book.controller.ts"
    click BModel "https://github.com/paviag/proyecto-01/blob/main/src/book/book.model.ts"
    click BTypes "https://github.com/paviag/proyecto-01/blob/main/src/book/book.types.ts"
    click CreateBook "https://github.com/paviag/proyecto-01/blob/main/src/book/create.book.action.ts"
    click DisableBook "https://github.com/paviag/proyecto-01/blob/main/src/book/disable.book.action.ts"
    click ReadBooks "https://github.com/paviag/proyecto-01/blob/main/src/book/read.books.action.ts"
    click ReadOneBook "https://github.com/paviag/proyecto-01/blob/main/src/book/read.one.book.action.ts"
    click UpdateBook "https://github.com/paviag/proyecto-01/blob/main/src/book/update.book.action.ts"
    click URoutes "https://github.com/paviag/proyecto-01/blob/main/src/user/user.routes.ts"
    click UController "https://github.com/paviag/proyecto-01/blob/main/src/user/user.controller.ts"
    click UModel "https://github.com/paviag/proyecto-01/blob/main/src/user/user.model.ts"
    click UTypes "https://github.com/paviag/proyecto-01/blob/main/src/user/user.types.ts"
    click CheckEnabledUser "https://github.com/paviag/proyecto-01/blob/main/src/user/checkEnabled.user.action.ts"
    click CreateUser "https://github.com/paviag/proyecto-01/blob/main/src/user/create.user.action.ts"
    click DisableUser "https://github.com/paviag/proyecto-01/blob/main/src/user/disable.user.action.ts"
    click ReadUser "https://github.com/paviag/proyecto-01/blob/main/src/user/read.user.action.ts"
    click UpdateUser "https://github.com/paviag/proyecto-01/blob/main/src/user/update.user.action.ts"
    click RModel "https://github.com/paviag/proyecto-01/blob/main/src/reservation/reservation.model.ts"
    click RTypes "https://github.com/paviag/proyecto-01/blob/main/src/reservation/reservation.types.ts"
    click CreateReservation "https://github.com/paviag/proyecto-01/blob/main/src/reservation/create.reservation.action.ts"
    click ReadReservations "https://github.com/paviag/proyecto-01/blob/main/src/reservation/read.reservations.action.ts"
    click SetReturnDate "https://github.com/paviag/proyecto-01/blob/main/src/reservation/set.return.date.action.ts"
    click AuthMiddleware "https://github.com/paviag/proyecto-01/blob/main/src/middleware/auth.ts"
    click DB "https://github.com/paviag/proyecto-01/blob/main/src/db.ts"

    %% Styles
    classDef external fill:#FFDAB9,stroke:#333,stroke-width:2px;
    classDef bootstrap fill:#FFEEAD,stroke:#333,stroke-width:2px;
    classDef middleware fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef route fill:#D1E8FF,stroke:#333,stroke-width:2px;
    classDef controller fill:#C1FFC1,stroke:#333,stroke-width:2px;
    classDef action fill:#FFB6C1,stroke:#333,stroke-width:2px;
    classDef model fill:#F0E68C,stroke:#333,stroke-width:2px;
    classDef types fill:#E6E6FA,stroke:#333,stroke-width:2px;
    classDef database fill:#FFE4E1,stroke:#333,stroke-width:2px;
```
