# pablopenaheredia/trimly-app architecture

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

- Interactive diagram: https://gitdiagram.com/pablopenaheredia/trimly-app
- Repository: https://github.com/pablopenaheredia/trimly-app

## Overview

##### Project type and purpose
- This is a full-stack web application (“Trimly-APP”) for managing clients, appointments (turnos), services, products, billing (facturación), reports and a real-time dashboard.
- Frontend: React + TypeScript + Vite.
- Backend: NestJS (TypeScript) organized into modules (clientes, turnos, servicios, producto, facturación, reportes, dashboard, usuarios).
- Persistence: SQL database (seeds.sql under backend/db indicates relational DB).

##### File structure
- Top-level folders “frontend” and “backend” clearly separate client and server.
- Backend uses NestJS’s module-controller-service pattern:
- src/app.module.ts wires all feature modules.
- Each feature (e.g. /clientes, /turnos) has its controller, service, entity.
- db/seeds.sql for initial data.
- E2E tests under backend/test.
- Frontend organizes by feature folders (clientes, turnos, servicios, stock, facturación, reportes, dashboard, usuarios) each containing React pages and modals.
- Common utilities: authService.ts, ProtectedRoute, pdfGenerator.ts.
- Build/config: Vite (vite.config.ts), tsconfig.json, ESLint, Prettier.

##### README
- Minimal; project name and badge.
- Rely on file structure to infer architecture.

a. Main components
1. Client Browser (React App)
2. API Gateway / Web Server (NestJS + Express)
3. Database (e.g. PostgreSQL/MySQL)
4. Optional external services: PDF generator, authentication provider (JWT).
b. Relationships & data flows
- Browser → HTTP(S) calls to REST endpoints (/api/*) handled by NestJS controllers.
- Controllers delegate to Services → ORM repositories → Database.
- Authentication: login endpoint → issues JWT → client stores token → ProtectedRoute guards pages.
- PDF generation: client triggers export → backend generates PDF via pdfGenerator utility or passes data for client-side PDF creation.
c. Architectural patterns
- Layered MVC (Controller → Service → Repository/Entity).
- Feature-module segregation in NestJS.
- Component-based UI on frontend; hooks for data fetching (useDashboardData, useReportes).
d. Key technologies
- Frontend: React, Vite, TypeScript, CSS modules, React Router (ProtectedRoute).
- Backend: NestJS, TypeORM (entities under /clientes, /turnos, etc.), DTOs for validation, Jest for tests.
- Database: SQL with seed scripts.
- Utilities: ESLint, Prettier, JWT auth, pdfGenerator.

- Use clear labels for each component/module.
- UI → API calls → Controllers → Services → DB
- DB → query results → Services → Controllers → UI
- Frontend (blue rectangles)
- Backend layers (controllers green, services yellow, DB orange)
- External services (grey)

##### Detailed capture of architectural elements
- NestJS module (clientes, turnos, servicios, producto, facturación, reportes, dashboard, usuarios).
- Shared DTO layer.
- E2E test target under backend/test.
- Call out build tools (Vite, Nest CLI) near respective layers.
- If deploying via container or CI/CD, include entrypoints: frontend “npm run dev/build”, backend “nest start”, .gitignore, config files.

- Middle row: NestJS API Gateway, subdivided left to right into Controllers → Services → Repository/Entity → Database
- Data flow of key user actions (login, CRUD on clientes, generate report, create factura, view dashboard).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Swimlanes
    subgraph "Frontend (React)" 
        direction TB
        A1["App (frontend/src/App.tsx)"]:::frontend
        A2["main.tsx (frontend/src/main.tsx)"]:::frontend
        A3["ProtectedRoute"]:::frontend
        A4["AuthService"]:::frontend
        A5["PDFGenerator"]:::frontend

        subgraph "Feature Pages"
            direction TB
            F1["ClientesPage"]:::frontend
            F2["TurnosPage"]:::frontend
            F3["ServiciosPage"]:::frontend
            F4["StockPage"]:::frontend
            F5["FacturacionPage"]:::frontend
            F6["ReportesPage"]:::frontend
            F7["DashboardPage"]:::frontend
            F8["UsuariosPage"]:::frontend
        end
    end

    subgraph "Backend (NestJS)" 
        direction TB
        B1["main.ts"]:::backend
        B2["app.module.ts"]:::backend
        B3["app.controller.ts"]:::backend

        subgraph "API Layer (Controllers)" 
            direction TB
            C1["UsuariosController"]:::controller
            C2["ClientesController"]:::controller
            C3["TurnosController"]:::controller
            C4["ServiciosController"]:::controller
            C5["ProductoController"]:::controller
            C6["FacturacionController"]:::controller
            C7["ReportesController"]:::controller
            C8["DashboardController"]:::controller
        end

        subgraph "Business Logic (Services)" 
            direction TB
            S1["UsuariosService"]:::service
            S2["ClientesService"]:::service
            S3["TurnosService"]:::service
            S4["ServiciosService"]:::service
            S5["ProductoService"]:::service
            S6["FacturacionService"]:::service
            S7["ReportesService"]:::service
            S8["DashboardService"]:::service
        end

        subgraph "Data Layer (Entities & DTOs)" 
            direction TB
            E1["UsuarioEntity"]:::entity
            E2["ClienteEntity"]:::entity
            E3["TurnoEntity"]:::entity
            E4["ServicioEntity"]:::entity
            E5["ProductoEntity"]:::entity
            E6["FacturaEntity"]:::entity
            E7["FacturaDetalleEntity"]:::entity
            E8["SharedDTOs"]:::dto
        end

        subgraph "E2E Tests" 
            direction TB
            T1["app.e2e-spec.ts"]:::test
            T2["jest-e2e.json"]:::test
        end
    end

    %% External
    PDF["PDF Generation (backend util)"]:::external
    AUTH["JWT Auth Provider"]:::external
    DB["Database\n(PostgreSQL/MySQL)"]:::db
    SEED["seeds.sql"]:::db

    %% Connections Frontend
    A1 -->|uses| A2
    A1 -->|guards| A3
    A1 -->|calls| A4
    A1 -->|exports| A5
    A1 -->|navigates| F1
    A1 -->|navigates| F2
    A1 -->|navigates| F3
    A1 -->|navigates| F4
    A1 -->|navigates| F5
    A1 -->|navigates| F6
    A1 -->|navigates| F7
    A1 -->|navigates| F8

    %% Frontend to Backend
    F1 -->|HTTP CRUD| C2
    F2 -->|HTTP CRUD| C3
    F3 -->|HTTP CRUD| C4
    F4 -->|HTTP CRUD| C5
    F5 -->|HTTP CRUD| C6
    F6 -->|HTTP CRUD| C7
    F7 -->|HTTP GET| C8
    A3 -->|checks token| AUTH
    A4 -->|login request| C1
    A5 -->|generate| PDF

    %% Controller -> Service -> Entity -> DB
    C1 -->|use| S1
    C2 -->|use| S2
    C3 -->|use| S3
    C4 -->|use| S4
    C5 -->|use| S5
    C6 -->|use| S6
    C7 -->|use| S7
    C8 -->|use| S8

    S1 -->|repo| E1
    S2 -->|repo| E2
    S3 -->|repo| E3
    S4 -->|repo| E4
    S5 -->|repo| E5
    S6 -->|repo| E6
    S6 -->|repo| E7
    S7 -->|dto| E8
    S8 -->|dto| E8

    E1 -->|query| DB
    E2 -->|query| DB
    E3 -->|query| DB
    E4 -->|query| DB
    E5 -->|query| DB
    E6 -->|query| DB
    E7 -->|query| DB

    SEED -->|initial data| DB

    %% Tests
    T1 -->|test API| B1

    %% Click Events
    click A1 "https://github.com/pablopenaheredia/trimly-app/blob/main/frontend/src/App.tsx"
    click A2 "https://github.com/pablopenaheredia/trimly-app/blob/main/frontend/src/main.tsx"
    click A3 "https://github.com/pablopenaheredia/trimly-app/blob/main/frontend/src/components/ProtectedRoute.tsx"
    click A4 "https://github.com/pablopenaheredia/trimly-app/blob/main/frontend/src/services/authService.ts"
    click A5 "https://github.com/pablopenaheredia/trimly-app/blob/main/frontend/src/utils/pdfGenerator.ts"
    click B1 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/src/main.ts"
    click B2 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/src/app.module.ts"
    click B3 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/src/app.controller.ts"
    click C1 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/src/usuarios/usuarios.controller.ts"
    click S1 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/src/usuarios/usuarios.service.ts"
    click E1 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/src/usuarios/usuario.entity.ts"
    click C2 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/src/clientes/clientes.controller.ts"
    click S2 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/src/clientes/clientes.service.ts"
    click E2 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/src/clientes/cliente.entity.ts"
    click C3 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/src/turnos/turnos.controller.ts"
    click S3 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/src/turnos/turnos.service.ts"
    click E3 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/src/turnos/turno.entity.ts"
    click C4 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/src/servicios/servicios.controller.ts"
    click S4 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/src/servicios/servicios.service.ts"
    click E4 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/src/servicios/servicio.entity.ts"
    click C5 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/src/producto/producto.controller.ts"
    click S5 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/src/producto/producto.service.ts"
    click E5 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/src/producto/producto.entity.ts"
    click C6 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/src/facturacion/facturacion.controller.ts"
    click S6 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/src/facturacion/facturacion.service.ts"
    click E6 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/src/facturacion/factura.entity.ts"
    click E7 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/src/facturacion/factura-detalle.entity.ts"
    click C7 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/src/reportes/reportes.controller.ts"
    click S7 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/src/reportes/reportes.service.ts"
    click C8 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/src/dashboard/dashboard.controller.ts"
    click S8 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/src/dashboard/dashboard.service.ts"
    click SEED "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/db/seeds.sql"
    click T1 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/test/app.e2e-spec.ts"
    click T2 "https://github.com/pablopenaheredia/trimly-app/blob/main/backend/test/jest-e2e.json"

    %% Styles
    classDef frontend fill:#AED6F1,stroke:#1B4F72,stroke-width:1px;
    classDef backend fill:#A9DFBF,stroke:#196F3D,stroke-width:1px;
    classDef controller fill:#ABEBC6,stroke:#196F3D,stroke-width:1px;
    classDef service fill:#FCF3CF,stroke:#B7950B,stroke-width:1px;
    classDef entity fill:#F9E79F,stroke:#B9770E,stroke-width:1px;
    classDef dto fill:#E8DAEF,stroke:#6C3483,stroke-width:1px;
    classDef test fill:#F5B7B1,stroke:#922B21,stroke-width:1px;
    classDef db fill:#FAD7A0,stroke:#873600,stroke-width:1px;
    classDef external fill:#D5D8DC,stroke:#566573,stroke-width:1px;
```
