# gonzalostickar/practicaprofesional architecture

> Architecture diagram of the GitHub repository gonzalostickar/practicaprofesional, 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/gonzalostickar/practicaprofesional
- Repository: https://github.com/gonzalostickar/practicaprofesional

## Overview

##### Main Components
a. Frontend (Views/Components):
- The "components" directory contains various .htm files used for the UI. It includes pages for login, dashboard (with subdirectories for adding, searching, etc.), and static pages like "politica_privacidad.htm" and "terminos_condiciones.htm".
- The "public" folder holds static assets (e.g., CSS stylesheets, JavaScript scripts, images).

b. Backend:
- Controllers: The "controllers" directory comprises the core business logic. There are separate modules for handling login, main operations, and different CRUD operations (adding, searching, editing, deleting, and generating reports) in its "crud" subdirectory, along with others for dashboard functionality.
- Routes: The "routes" folder mirrors the controllers with endpoints for the various functionalities. Each route file (e.g., routes/consultas.js, routes/crud/agregar.js, etc.) connects HTTP requests to the appropriate controller logic.
- Models: The "models" directory houses data representations, with separate files like persona.js and reparacion.js for your domain entities. The "models/sql" subdirectory along with schema.sql indicates that the project uses SQL for the database.
- Data & Database: Files like "data/db.js" and "database.js" suggest that there is a database connection/initialization layer, which might be used by the models and controllers.

c. Middlewares & Helpers:
- The "middlewares" folder contains modules for caching and authentication (e.g., isAuth.js), which regulate access and optimize performance.
- The "helpers" folder includes utility functions like date formatting (dateHelper.js).

##### Relationships and Interactions
- Flow starting from the client: a user interacts with the UI presented in static webpages (from the "components" and "public" directories).
- HTTP requests are made to routes defined in the "routes" directory.
- Routes pass these requests to the relevant controllers that implement business logic.
- Controllers interact with the models (and, in turn, the database) to fetch, update, or delete the necessary data.
- Middleware components (like “isAuth.js” and “cache.js”) process requests before they reach the controller, ensuring authentication and performance optimizations.
- Finally, responses are returned back through the routes to be rendered in the user’s browser.

##### Architectural Patterns & Key Technologies
- MVC or similar layered architecture divides the application into distinct concerns (views, controllers, models).
- The CRUD operations are modularized in both the controllers and routes (for adding, searching, editing, and deleting data).
- The project uses Node.js (suggested by package.json, index.js) for server-side logic.
- SQL-based database is indicated by the schema.sql in models/sql.
- Deployment on Vercel is indicated via vercel.json and the README.

– From “Frontend” to “API Routes” indicating HTTP requests.
– From “API Routes” through “Middlewares” to “Controllers”.
– From “Controllers” to “Models/Database” for data operations.
- Entry point ("index.js") as a starting node that ties all components together when the application starts.

##### Details and Design Principles
- Modularization especially in the CRUD operations and the separation of concerns.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Subgraph
    subgraph "Frontend"
        F1["Components (UI)"]:::frontend
        F2["Public Assets"]:::frontend
    end

    %% API Routes Subgraph
    subgraph "API Routes"
        RC["Consultas Route"]:::routes
        RD["Dashboard Route"]:::routes
        RCRUD["CRUD Routes"]:::routes
    end

    %% Middlewares Subgraph
    subgraph "Middlewares"
        MW1["Cache Middleware"]:::middleware
        MW2["Authentication Middleware"]:::middleware
    end

    %% Controllers Subgraph
    subgraph "Controllers"
        CL["Login Controller"]:::controller
        CM["Main Controller"]:::controller
        CC["CRUD Controllers"]:::controller
    end

    %% Models Subgraph
    subgraph "Models"
        MP["Persona Model"]:::model
        MR["Reparacion Model"]:::model
        MSS["SQL Schema"]:::model
    end

    %% Database Subgraph
    subgraph "Database"
        DB1["Data/DB Connection"]:::database
        DB2["Database Initialization"]:::database
    end

    %% Helpers Subgraph
    subgraph "Helpers"
        H1["Utilities (Date Helper)"]:::helper
    end

    %% Deployment & Entry Point Subgraph
    subgraph "Deployment & Entry Point"
        D1["Vercel Config"]:::deployment
        D2["Index (App Start)"]:::deployment
    end

    %% Connections - Request Flow
    F1 -->|"HTTP Request"| RC
    F2 -->|"HTTP Request"| RC
    RC -->|"Passes Request"| MW1
    RC -->|"Passes Request"| MW2
    MW1 -->|"Forwards"| CL
    MW1 -->|"Forwards"| CM
    MW1 -->|"Forwards"| CC
    MW2 -->|"Forwards"| CL
    MW2 -->|"Forwards"| CM
    MW2 -->|"Forwards"| CC
    CL -->|"Executes CRUD"| MP
    CL -->|"Executes CRUD"| MR
    CL -->|"Executes Query"| MSS
    CM -->|"Handles Main Ops"| MP
    CM -->|"Handles Main Ops"| MR
    CC -->|"Performs CRUD"| MP
    CC -->|"Performs CRUD"| MR
    CC -->|"Uses Schema"| MSS
    %% Controllers interacting with Database
    CL -->|"DB Operation"| DB1
    CM -->|"DB Operation"| DB1
    CC -->|"DB Operation"| DB2

    %% Deployment ties
    D2 -->|"Starts App"| F1
    D2 -->|"Starts App"| RC

    %% Click Events for Frontend
    click F1 "https://github.com/gonzalostickar/practicaprofesional/tree/main/components"
    click F2 "https://github.com/gonzalostickar/practicaprofesional/tree/main/public"

    %% Click Events for API Routes
    click RC "https://github.com/gonzalostickar/practicaprofesional/blob/main/routes/consultas.js"
    click RD "https://github.com/gonzalostickar/practicaprofesional/blob/main/routes/dashboard.js"
    click RCRUD "https://github.com/gonzalostickar/practicaprofesional/tree/main/routes/crud"

    %% Click Events for Controllers
    click CL "https://github.com/gonzalostickar/practicaprofesional/blob/main/controllers/login.js"
    click CM "https://github.com/gonzalostickar/practicaprofesional/blob/main/controllers/main.js"
    click CC "https://github.com/gonzalostickar/practicaprofesional/tree/main/controllers/crud"

    %% Click Events for Models
    click MP "https://github.com/gonzalostickar/practicaprofesional/blob/main/models/persona.js"
    click MR "https://github.com/gonzalostickar/practicaprofesional/blob/main/models/reparacion.js"
    click MSS "https://github.com/gonzalostickar/practicaprofesional/blob/main/models/sql/schema.sql"

    %% Click Events for Database
    click DB1 "https://github.com/gonzalostickar/practicaprofesional/blob/main/data/db.js"
    click DB2 "https://github.com/gonzalostickar/practicaprofesional/blob/main/database.js"

    %% Click Events for Middlewares
    click MW1 "https://github.com/gonzalostickar/practicaprofesional/blob/main/middlewares/cache.js"
    click MW2 "https://github.com/gonzalostickar/practicaprofesional/blob/main/middlewares/isAuth.js"

    %% Click Event for Helpers
    click H1 "https://github.com/gonzalostickar/practicaprofesional/blob/main/helpers/dateHelper.js"

    %% Click Events for Deployment & Entry Point
    click D1 "https://github.com/gonzalostickar/practicaprofesional/blob/main/vercel.json"
    click D2 "https://github.com/gonzalostickar/practicaprofesional/blob/main/index.js"

    %% Styling Classes
    classDef frontend fill:#a2d5f2,stroke:#036,stroke-width:2px;
    classDef routes fill:#f3d250,stroke:#aa6,stroke-width:2px;
    classDef middleware fill:#f7a072,stroke:#d45500,stroke-width:2px;
    classDef controller fill:#c1e1c1,stroke:#2d662d,stroke-width:2px;
    classDef model fill:#f9c0c0,stroke:#a83232,stroke-width:2px;
    classDef database fill:#dab6fc,stroke:#6e3b8a,stroke-width:2px;
    classDef helper fill:#ffe699,stroke:#bfa600,stroke-width:2px;
    classDef deployment fill:#ffb3ba,stroke:#d63333,stroke-width:2px;
```
