# camilovargas05/livetech_backend architecture

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

- Interactive diagram: https://gitdiagram.com/camilovargas05/livetech_backend
- Repository: https://github.com/camilovargas05/livetech_backend

## Overview

##### Project Type and Purpose
- This is a monolithic backend application built with NestJS (TypeScript) that exposes RESTful HTTP APIs and a WebSocket streaming interface.
- It provides user management, authentication (JWT), chat, ticketing, maintenance (“mantenimiento”), statistics, file upload, and real‐time streaming functionality, persisting data to a Postgres database hosted via Supabase.

##### High-Level Architectural Components
a. API Layer
- NestJS HTTP Server (Express under the hood)
- REST Controllers in modules: AuthController, UsersController, ChatController, TicketsController, MantenimientoController, StatsController, UploadsController
b. WebSocket Layer
- NestJS Gateway: StreamingGateway listens for real‐time events over WS.
c. Business Logic Layer
- Services per module: AuthService, UsersService, ChatService, TicketsService, MantenimientoService, StatsService, UploadsService
- Each service encapsulates use cases and interacts with repositories/entities.
d. Data Access Layer
- TypeORM Entities under each module’s `entities/` directory
- Supabase Postgres database (configured via `src/config/supabase.config.ts`)
e. Authentication & Authorization
- JWT Strategy, Guards (JwtAuthGuard, RolesGuard), Custom Decorators (RolesDecorator)
f. External Dependencies
- Supabase for database & file storage
- Possibly CDN/Cloud Storage for uploads if configured in Supabase
g. Infrastructure & Configuration
- `main.ts` bootstraps the Nest application
- `nest-cli.json`, `tsconfig.json` for build/config
- CI/CD hooks or deploy scripts (not shown but assumed)

##### Relationships and Data Flow
- Clients (Web, Mobile)
- Send HTTP requests → NestJS Controllers
- Open WebSocket connections → StreamingGateway
- Controllers
- Delegate to Services for business logic
- Services
- Use TypeORM repositories (entities) to read/write data in Supabase Postgres
- In AuthService: verify credentials, issue JWTs
- In UploadsService: handle multipart, forward to Supabase Storage API
- In StreamingGateway: emit/receive events, coordinate with ChatService or StatsService as needed
- Guards & Interceptors
- JWT guard runs before Controller methods → enforces authentication
- Roles guard checks permissions via custom decorator

##### Architectural Patterns & Principles
- Modularization: Each feature lives in its own Nest module (`*.module.ts`).
- Layered Architecture:
- Presentation Layer (Controllers, Gateways)
- Application Layer (Services, DTOs)
- Domain/Entity Layer (TypeORM Entities)
- Infrastructure Layer (Supabase config, external APIs)
- Separation of Concerns: Controllers handle I/O, Services handle logic, Entities represent schema.
- Dependency Injection: NestJS DI container wires controllers to services and repositories.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Clients
    Clients["Clients (Web / Mobile)"]:::external

    %% NestJS Monolith
    subgraph "NestJS Monolith"
        direction TB

        %% Bootstrap & Core
        Main["main.ts\nBootstraps App"]:::infra
        AppModule["app.module.ts\nGlobal Module"]:::infra
        CoreController["AppController"]:::presentation
        CoreService["AppService"]:::business

        Main -->|bootstraps| AppModule
        AppModule --> CoreController
        AppModule --> CoreService

        %% HTTP Server Layer
        subgraph "HTTP Server (Express)" 
            direction TB
            %% Auth Module
            subgraph "Auth Module"
                direction LR
                AuthController["AuthController"]:::presentation
                AuthService["AuthService"]:::business
                JWTStrategy["JWT Strategy"]:::business
                JwtAuthGuard["JwtAuthGuard"]:::business
                RolesGuard["RolesGuard"]:::business
                RolesDecorator["RolesDecorator"]:::business
                AuthEntity["Auth Entity"]:::data

                AuthController -->|"calls"| AuthService
                AuthService -->|"uses"| AuthEntity
                AuthService -->|"uses"| JWTStrategy
                AuthController -->|"guarded by"| JwtAuthGuard
                AuthController -->|"guarded by"| RolesGuard
                AuthController --> RolesDecorator
            end

            %% Users Module
            subgraph "Users Module"
                direction LR
                UsersController["UsersController"]:::presentation
                UsersService["UsersService"]:::business
                UserEntity["User Entity"]:::data

                UsersController -->|"calls"| UsersService
                UsersService -->|"uses"| UserEntity
            end

            %% Chat Module
            subgraph "Chat Module"
                direction LR
                ChatController["ChatController"]:::presentation
                ChatService["ChatService"]:::business
                ChatEntity["Chat Entity"]:::data

                ChatController -->|"calls"| ChatService
                ChatService -->|"uses"| ChatEntity
            end

            %% Tickets Module
            subgraph "Tickets Module"
                direction LR
                TicketsController["TicketsController"]:::presentation
                TicketsService["TicketsService"]:::business
                TicketEntity["Ticket Entity"]:::data

                TicketsController -->|"calls"| TicketsService
                TicketsService -->|"uses"| TicketEntity
            end

            %% Mantenimiento Module
            subgraph "Mantenimiento Module"
                direction LR
                MantenimientoController["MantenimientoController"]:::presentation
                MantenimientoService["MantenimientoService"]:::business
                MantenimientoEntity["Mantenimiento Entity"]:::data

                MantenimientoController -->|"calls"| MantenimientoService
                MantenimientoService -->|"uses"| MantenimientoEntity
            end

            %% Stats Module
            subgraph "Stats Module"
                direction LR
                StatsController["StatsController"]:::presentation
                StatsService["StatsService"]:::business
                StatEntity["Stat Entity"]:::data

                StatsController -->|"calls"| StatsService
                StatsService -->|"uses"| StatEntity
            end

            %% Uploads Module
            subgraph "Uploads Module"
                direction LR
                UploadsController["UploadsController"]:::presentation
                UploadsService["UploadsService"]:::business
                UploadEntity["Upload Entity"]:::data

                UploadsController -->|"calls"| UploadsService
                UploadsService -->|"uses"| UploadEntity
            end
        end

        %% WebSocket Layer
        subgraph "WebSocket Gateway"
            StreamingGateway["StreamingGateway"]:::presentation
            StreamingGateway -->|"uses"| ChatService
            StreamingGateway -->|"uses"| StatsService
        end

        %% Configuration
        SupabaseConfig["supabase.config.ts"]:::infra

        %% Data Storage
        SupabaseDB["Supabase Postgres DB"]:::external
        SupabaseStorage["Supabase Storage"]:::external

        %% Infrastructure Connections
        AppModule -->|"imports config"| SupabaseConfig
        AuthService -->|"CRUD via TypeORM"| SupabaseDB
        UsersService -->|"CRUD via TypeORM"| SupabaseDB
        ChatService -->|"CRUD via TypeORM"| SupabaseDB
        TicketsService -->|"CRUD via TypeORM"| SupabaseDB
        MantenimientoService -->|"CRUD via TypeORM"| SupabaseDB
        StatsService -->|"CRUD via TypeORM"| SupabaseDB
        UploadsService -->|"File upload/download"| SupabaseStorage

        %% Client Connections
        Clients -->|"REST API calls (JSON/HTTP)"| AuthController
        Clients -->|"REST API calls (JSON/HTTP)"| UsersController
        Clients -->|"REST API calls (JSON/HTTP)"| ChatController
        Clients -->|"REST API calls (JSON/HTTP)"| TicketsController
        Clients -->|"REST API calls (JSON/HTTP)"| MantenimientoController
        Clients -->|"REST API calls (JSON/HTTP)"| StatsController
        Clients -->|"REST API calls (JSON/HTTP)"| UploadsController
        Clients -->|"WS events"| StreamingGateway

    end

    %% Click Events
    click Main "https://github.com/camilovargas05/livetech_backend/blob/main/src/main.ts"
    click AppModule "https://github.com/camilovargas05/livetech_backend/blob/main/src/app.module.ts"
    click AuthController "https://github.com/camilovargas05/livetech_backend/blob/main/src/auth/auth.controller.ts"
    click AuthService "https://github.com/camilovargas05/livetech_backend/blob/main/src/auth/auth.service.ts"
    click JWTStrategy "https://github.com/camilovargas05/livetech_backend/blob/main/src/auth/strategies/jwt.strategy.ts"
    click JwtAuthGuard "https://github.com/camilovargas05/livetech_backend/blob/main/src/auth/guards/jwt-auth.guard.ts"
    click RolesGuard "https://github.com/camilovargas05/livetech_backend/blob/main/src/auth/guards/roles.guard.ts"
    click RolesDecorator "https://github.com/camilovargas05/livetech_backend/blob/main/src/auth/decorators/roles.decorator.ts"
    click AuthEntity "https://github.com/camilovargas05/livetech_backend/blob/main/src/auth/entities/auth.entity.ts"
    click UsersController "https://github.com/camilovargas05/livetech_backend/blob/main/src/users/users.controller.ts"
    click UsersService "https://github.com/camilovargas05/livetech_backend/blob/main/src/users/users.service.ts"
    click UserEntity "https://github.com/camilovargas05/livetech_backend/blob/main/src/users/entities/user.entity.ts"
    click ChatController "https://github.com/camilovargas05/livetech_backend/blob/main/src/chat/chat.controller.ts"
    click ChatService "https://github.com/camilovargas05/livetech_backend/blob/main/src/chat/chat.service.ts"
    click ChatEntity "https://github.com/camilovargas05/livetech_backend/blob/main/src/chat/entities/chat.entity.ts"
    click TicketsController "https://github.com/camilovargas05/livetech_backend/blob/main/src/tickets/tickets.controller.ts"
    click TicketsService "https://github.com/camilovargas05/livetech_backend/blob/main/src/tickets/tickets.service.ts"
    click TicketEntity "https://github.com/camilovargas05/livetech_backend/blob/main/src/tickets/entities/ticket.entity.ts"
    click MantenimientoController "https://github.com/camilovargas05/livetech_backend/blob/main/src/mantenimiento/mantenimiento.controller.ts"
    click MantenimientoService "https://github.com/camilovargas05/livetech_backend/blob/main/src/mantenimiento/mantenimiento.service.ts"
    click MantenimientoEntity "https://github.com/camilovargas05/livetech_backend/blob/main/src/mantenimiento/entities/mantenimiento.entity.ts"
    click StatsController "https://github.com/camilovargas05/livetech_backend/blob/main/src/stats/stats.controller.ts"
    click StatsService "https://github.com/camilovargas05/livetech_backend/blob/main/src/stats/stats.service.ts"
    click StatEntity "https://github.com/camilovargas05/livetech_backend/blob/main/src/stats/entities/stat.entity.ts"
    click UploadsController "https://github.com/camilovargas05/livetech_backend/blob/main/src/uploads/uploads.controller.ts"
    click UploadsService "https://github.com/camilovargas05/livetech_backend/blob/main/src/uploads/uploads.service.ts"
    click UploadEntity "https://github.com/camilovargas05/livetech_backend/blob/main/src/uploads/entities/upload.entity.ts"
    click StreamingGateway "https://github.com/camilovargas05/livetech_backend/blob/main/src/streaming/streaming.gateway.ts"
    click SupabaseConfig "https://github.com/camilovargas05/livetech_backend/blob/main/src/config/supabase.config.ts"
    click CoreController "https://github.com/camilovargas05/livetech_backend/blob/main/src/app.controller.ts"
    click CoreService "https://github.com/camilovargas05/livetech_backend/blob/main/src/app.service.ts"

    %% Styles
    classDef presentation fill:#cce5ff,stroke:#004085,color:#004085
    classDef business fill:#d4edda,stroke:#155724,color:#155724
    classDef data fill:#fff3cd,stroke:#856404,color:#856404
    classDef external fill:#e2e3e5,stroke:#6c757d,color:#6c757d
    classDef infra fill:#f8d7da,stroke:#721c24,color:#721c24
```
