How camilovargas05/livetech_backend works
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.