# its-quasi/parking-apirest architecture

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

- Interactive diagram: https://gitdiagram.com/its-quasi/parking-apirest
- Repository: https://github.com/its-quasi/parking-apirest

## Overview

Based on our review of the file tree and README, this project is a backend API service designed for managing parking-related operations (users, parking logs, etc.) for a technical test (Solución planteada a prueba técnica Nelumbo). The project employs a layered architecture using Node.js (with TypeScript) and integrates with a PostgreSQL database (the README even shows how to launch a Docker container for it).

##### Main Components
- API Layer – Represent the Express application, which can be inferred from files like src/app.ts and src/index.ts. This layer handles incoming HTTP requests.
- Routing – Include the “routes” folder components (admin.routes.ts, auth.routes.ts, indicators.routes.ts, partner.routes.ts). These define the REST endpoints.
- Service Layer – Display the services (auth.service, admin.service, indicators.service, partner.service, jwt.service) which encapsulate the business logic.
- Data Layer – Include data models (parking, parkingLog, user) and mention the connection file (data-source.ts). This is where interaction with the PostgreSQL database happens.
- DTOs – Illustrate how Data Transfer Objects (createLogDto, parkingDto, userDto) are used for validating and structuring data between the API and the services.
- Utilities – Capture utility modules (handlerPasswords, handlerTime, plateValidator, role) that provide supporting functions across the application.
- Configuration Components – Note the environment configuration (.env file instructions) and the package-related files for dependency management.

##### Relationships and Interactions
- Routes → Middlewares: Illustrate that requests pass through various middleware components (token verification, role validations, etc.) before reaching business logic.
- Service Layer → Data Layer: Connect service modules to the data models and database connection, highlighting data persistence and retrieval operations.
- Service Layer → DTO Conversion: Optionally represent conversion/validation using DTOs to ensure well-defined data formats.
- Utilities: Connect the utilities to both the service and middleware layers where required.

##### Architectural Patterns & Technologies
- Pattern: The project follows a modular or layered architecture, with a clear separation between the API, business logic, and data persistence layers.
- Technology Stack: Node.js with TypeScript for application logic; Express (implicitly via middleware and routing structure) for HTTP request handling; a PostgreSQL database (set up via Docker according to the README); likely some ORM or database abstraction in the data-source.ts file.
- Security: Integration of JWT-based authentication (as seen in jwt.service and verifyToken middleware) and role-based access controls (various role verification middlewares).

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client("Client"):::external
    Client -->|"HTTPRequest"| ExpressApp["Express Application"]:::api

    subgraph "Routing Layer"
        AdminRoutes("Admin Routes"):::route
        AuthRoutes("Auth Routes"):::route
        IndicatorsRoutes("Indicators Routes"):::route
        PartnerRoutes("Partner Routes"):::route
    end
    ExpressApp -->|"handles"| AdminRoutes
    ExpressApp -->|"handles"| AuthRoutes
    ExpressApp -->|"handles"| IndicatorsRoutes
    ExpressApp -->|"handles"| PartnerRoutes

    subgraph "Middlewares Layer"
        MiddlewareRol("verifyRolPartner"):::middleware
        MiddlewareParkingOperation("verifyParkingOperationBody"):::middleware
        MiddlewareParkingPartner("verifyParkingPartner"):::middleware
        MiddlewareRoleAdmin("verifyRoleAdmin"):::middleware
        MiddlewareToken("verifyToken"):::middleware
    end
    AdminRoutes -->|"passesThrough"| MiddlewareRoleAdmin
    AuthRoutes -->|"passesThrough"| MiddlewareToken
    IndicatorsRoutes -->|"passesThrough"| MiddlewareParkingOperation
    PartnerRoutes -->|"passesThrough"| MiddlewareRol
    PartnerRoutes -->|"passesThrough"| MiddlewareParkingPartner

    subgraph "Service Layer"
        AdminService("Admin Service"):::service
        AuthService("Auth Service"):::service
        IndicatorsService("Indicators Service"):::service
        JWTService("JWT Service"):::service
        PartnerService("Partner Service"):::service
    end
    MiddlewareRoleAdmin -->|"calls"| AdminService
    MiddlewareToken -->|"calls"| AuthService
    MiddlewareParkingOperation -->|"calls"| IndicatorsService
    MiddlewareRol -->|"calls"| PartnerService
    MiddlewareParkingPartner -->|"calls"| PartnerService
    AuthService ---|"uses"| JWTService
    MiddlewareToken ---|"uses"| JWTService

    subgraph "Data Layer"
        ParkingModel("Parking Model"):::model
        ParkingLogModel("ParkingLog Model"):::model
        UserModel("User Model"):::model
        DBConnection("Database Connection"):::model
    end
    AdminService -->|"interactsWith"| ParkingModel
    AuthService -->|"interactsWith"| UserModel
    IndicatorsService -->|"interactsWith"| ParkingLogModel
    PartnerService -->|"interactsWith"| ParkingModel
    AdminService -->|"calls"| DBConnection
    AuthService -->|"calls"| DBConnection
    IndicatorsService -->|"calls"| DBConnection
    PartnerService -->|"calls"| DBConnection
    DBConnection -->|"connectsTo"| Postgres["PostgreSQL Database"]:::database

    subgraph "DTOs"
        CreateLogDto("CreateLogDto"):::dto
        ParkingDto("ParkingDto"):::dto
        UserDto("UserDto"):::dto
    end
    AdminService -->|"validatesWith"| CreateLogDto
    AuthService -->|"validatesWith"| UserDto
    IndicatorsService -->|"validatesWith"| ParkingDto

    subgraph "Utilities"
        HandlerPasswords("handlerPasswords"):::utility
        HandlerTime("handlerTime"):::utility
        PlateValidator("plateValidator"):::utility
        RoleUtil("role"):::utility
    end
    AuthService -->|"uses"| HandlerPasswords
    IndicatorsService -->|"uses"| HandlerTime
    PartnerService -->|"uses"| PlateValidator
    AdminService -->|"uses"| RoleUtil
    MiddlewareRoleAdmin -->|"uses"| RoleUtil

    Config("Configuration & Environment"):::config
    ExpressApp ---|"configRead"| Config

    %% Click Events for API Layer
    click ExpressApp "https://github.com/its-quasi/parking-apirest/blob/master/src/app.ts"
    click ExpressApp "https://github.com/its-quasi/parking-apirest/blob/master/src/index.ts"

    %% Click Events for Routing Layer
    click AdminRoutes "https://github.com/its-quasi/parking-apirest/blob/master/src/routes/admin.routes.ts"
    click AuthRoutes "https://github.com/its-quasi/parking-apirest/blob/master/src/routes/auth.routes.ts"
    click IndicatorsRoutes "https://github.com/its-quasi/parking-apirest/blob/master/src/routes/indicators.routes.ts"
    click PartnerRoutes "https://github.com/its-quasi/parking-apirest/blob/master/src/routes/partner.routes.ts"

    %% Click Events for Middlewares Layer
    click MiddlewareRol "https://github.com/its-quasi/parking-apirest/blob/master/src/middlewares/verfyRolPartner.ts"
    click MiddlewareParkingOperation "https://github.com/its-quasi/parking-apirest/blob/master/src/middlewares/verifyParkingOperationBody.ts"
    click MiddlewareParkingPartner "https://github.com/its-quasi/parking-apirest/blob/master/src/middlewares/verifyParkingPartner.ts"
    click MiddlewareRoleAdmin "https://github.com/its-quasi/parking-apirest/blob/master/src/middlewares/verifyRoleAdmin.ts"
    click MiddlewareToken "https://github.com/its-quasi/parking-apirest/blob/master/src/middlewares/verifyToken.ts"

    %% Click Events for Service Layer
    click AdminService "https://github.com/its-quasi/parking-apirest/blob/master/src/services/admin.service.ts"
    click AuthService "https://github.com/its-quasi/parking-apirest/blob/master/src/services/auth.service.ts"
    click IndicatorsService "https://github.com/its-quasi/parking-apirest/blob/master/src/services/indicators.service.ts"
    click JWTService "https://github.com/its-quasi/parking-apirest/blob/master/src/services/jwt.service.ts"
    click PartnerService "https://github.com/its-quasi/parking-apirest/blob/master/src/services/partner.service.ts"

    %% Click Events for Data Layer
    click ParkingModel "https://github.com/its-quasi/parking-apirest/blob/master/src/models/parking.ts"
    click ParkingLogModel "https://github.com/its-quasi/parking-apirest/blob/master/src/models/parkingLog.ts"
    click UserModel "https://github.com/its-quasi/parking-apirest/blob/master/src/models/user.ts"
    click DBConnection "https://github.com/its-quasi/parking-apirest/blob/master/src/data-source.ts"

    %% Click Events for DTOs
    click CreateLogDto "https://github.com/its-quasi/parking-apirest/blob/master/src/dto/createLogDto.ts"
    click ParkingDto "https://github.com/its-quasi/parking-apirest/blob/master/src/dto/parkingDto.ts"
    click UserDto "https://github.com/its-quasi/parking-apirest/blob/master/src/dto/userDto.ts"

    %% Click Events for Utilities
    click HandlerPasswords "https://github.com/its-quasi/parking-apirest/blob/master/src/utils/handlerPasswords.ts"
    click HandlerTime "https://github.com/its-quasi/parking-apirest/blob/master/src/utils/handlerTime.ts"
    click PlateValidator "https://github.com/its-quasi/parking-apirest/blob/master/src/utils/plateValidator.ts"
    click RoleUtil "https://github.com/its-quasi/parking-apirest/blob/master/src/utils/role.ts"

    %% Click Events for Configuration
    click Config "https://github.com/its-quasi/parking-apirest/blob/master/README.md"
    click Config "https://github.com/its-quasi/parking-apirest/blob/master/package.json"
    click Config "https://github.com/its-quasi/parking-apirest/blob/master/tsconfig.json"

    %% Class Definitions for Colors
    classDef api fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef route fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef middleware fill:#FFA500,stroke:#000,stroke-width:1px;
    classDef service fill:#FFB6C1,stroke:#000,stroke-width:1px;
    classDef model fill:#FFFF99,stroke:#000,stroke-width:1px;
    classDef dto fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef utility fill:#F08080,stroke:#000,stroke-width:1px;
    classDef config fill:#D8BFD8,stroke:#000,stroke-width:1px;
    classDef database fill:#00CED1,stroke:#000,stroke-width:1px;
    classDef external fill:#C0C0C0,stroke:#000,stroke-width:1px;
```
