# unizar-30226-2024-06/loveroombackend architecture

> Architecture diagram of the GitHub repository unizar-30226-2024-06/loveroombackend, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/unizar-30226-2024-06/loveroombackend
- Repository: https://github.com/unizar-30226-2024-06/loveroombackend

## Overview

##### Project Type & Purpose
- This is a backend service designed to handle various operations – from user authentication and administration to handling multimedia and messaging, with real-time communications enabled by socket events.
- The README focuses on local setup and testing, but the file tree tells us that this service exposes multiple endpoints (via controllers) that likely serve as a backend for a client application.

##### Main Components
a. API Layer:
- That the controllers use the constants from the “src/constants” folder (error codes, multimedia types, socket events).

b. Business Logic & Services:
- The “src/services/socketManager.ts” indicates that the application handles real-time communication via socket events. Create a component labeled “Services” where this real-time management is showcased.
- If there are any hidden business logic components inside the controllers or separate service layers (like validating payments or handling multimedia), include them in this layer.

c. Data Access Layer:
- The “src/db” folder contains modules such as match, mensajes (messages), multimedia, salas (rooms), usuarios, and video; these are your database access/repository classes. Illustrate these as the “Data Access” layer.

d. External Integrations & Infrastructure:
- Integration with external services such as email (correoController) and payments (pagosController) should be shown. Represent these as external systems that the application communicates with.
- Docker and GitHub Actions workflows (found inside “.github/workflows” and the Dockerfile) imply CI/CD and containerized deployment. Represent these as “Deployment/CI/CD Pipeline” components that feed into the main application.

##### Architectural Patterns & Design Principles
- The project follows a layered (or n-tier) architecture: Presentation/API (controllers/routes) → Business Logic (services) → Data Access (db modules using Prisma).
- The separation of concerns is visible with dedicated folders for constants, controllers, services, and data access.
- The use of test folders and separate configuration files (jest.config.js, tsconfig.json) indicates adherence to best practices in code quality and type safety.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Client["Client Application"]:::client

    %% API Layer: Controllers/Routes and Constants
    subgraph "API Layer"
        CTRLS["Controllers (src/controllers)"]:::api
        ROUTES["Routes (src/routes.ts)"]:::api
        CONST["Constants (src/constants)"]:::api
    end

    %% Business Logic & Services
    subgraph "Business Logic"
        SOCKET["Socket Manager (src/services/socketManager.ts)"]:::logic
    end

    %% Data Access Layer
    subgraph "Data Access Layer"
        DBMODULES["Data Access (src/db)"]:::data
    end

    %% Database (Prisma ORM)
    subgraph "Database"
        PRISMA["Prisma Schema (prisma/schema.prisma)"]:::db
    end

    %% External Integrations
    subgraph "External Integrations"
        EMAIL["Email Integration (correoController.ts)"]:::external
        PAYMENTS["Payments Integration (pagosController.ts)"]:::external
    end

    %% Deployment / CI-CD Pipeline
    subgraph "Deployment/CI/CD Pipeline"
        DOCKER["Dockerfile"]:::pipeline
        WORKFLOWS["Workflows (.github/workflows)"]:::pipeline
        DOCKER --- WORKFLOWS
    end

    %% Testing Infrastructure
    subgraph "Testing Infrastructure"
        TESTS["Testing (src/test)"]:::testing
    end

    %% Production Environment
    PROD["Production Environment"]:::production

    %% Connections
    Client -->|"REST_API"| CTRLS
    Client -->|"REST_API"| ROUTES

    CTRLS -->|"uses"| CONST

    CTRLS -->|"calls"| SOCKET
    ROUTES -->|"routesTo"| SOCKET

    SOCKET -->|"logicCalls"| DBMODULES
    DBMODULES -->|"ORMQuery"| PRISMA

    %% External integrations from controllers
    CTRLS -->|"emailCall"| EMAIL
    CTRLS -->|"paymentCall"| PAYMENTS

    %% Deployment connections from core components to CI/CD Pipeline
    CTRLS -->|"deployedVia"| DOCKER
    ROUTES -->|"deployedVia"| DOCKER
    SOCKET -->|"deployedVia"| DOCKER
    DBMODULES -->|"deployedVia"| DOCKER

    %% CI/CD Pipeline deploying to Production
    DOCKER -->|"deploysTo"| PROD
    WORKFLOWS -->|"triggers"| PROD

    %% Testing connections
    CTRLS -->|"testedBy"| TESTS
    SOCKET -->|"testedBy"| TESTS
    DBMODULES -->|"testedBy"| TESTS

    %% Click Events
    click CTRLS "https://github.com/unizar-30226-2024-06/loveroombackend/tree/main/src/controllers"
    click ROUTES "https://github.com/unizar-30226-2024-06/loveroombackend/blob/main/src/routes.ts"
    click CONST "https://github.com/unizar-30226-2024-06/loveroombackend/tree/main/src/constants"
    click SOCKET "https://github.com/unizar-30226-2024-06/loveroombackend/blob/main/src/services/socketManager.ts"
    click DBMODULES "https://github.com/unizar-30226-2024-06/loveroombackend/tree/main/src/db"
    click PRISMA "https://github.com/unizar-30226-2024-06/loveroombackend/blob/main/prisma/schema.prisma"
    click EMAIL "https://github.com/unizar-30226-2024-06/loveroombackend/blob/main/src/controllers/correoController.ts"
    click PAYMENTS "https://github.com/unizar-30226-2024-06/loveroombackend/blob/main/src/controllers/pagosController.ts"
    click DOCKER "https://github.com/unizar-30226-2024-06/loveroombackend/tree/main/Dockerfile"
    click WORKFLOWS "https://github.com/unizar-30226-2024-06/loveroombackend/tree/main/.github/workflows"
    click TESTS "https://github.com/unizar-30226-2024-06/loveroombackend/tree/main/src/test"

    %% Styles
    classDef client fill:#f9f,stroke:#333,stroke-width:2px;
    classDef api fill:#bbf,stroke:#333,stroke-width:2px;
    classDef logic fill:#bfb,stroke:#333,stroke-width:2px;
    classDef data fill:#fdb,stroke:#333,stroke-width:2px;
    classDef db fill:#f99,stroke:#333,stroke-width:2px;
    classDef external fill:#dda,stroke:#333,stroke-width:2px;
    classDef pipeline fill:#ffd,stroke:#333,stroke-width:2px;
    classDef testing fill:#cdf,stroke:#333,stroke-width:2px;
    classDef production fill:#cfc,stroke:#333,stroke-width:2px;
```
