# enmanuelrivas/retotc2005b architecture

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

- Interactive diagram: https://gitdiagram.com/enmanuelrivas/retotc2005b
- Repository: https://github.com/enmanuelrivas/retotc2005b

## Overview

##### Project Type & Purpose
- This is a full-stack web application combining:
- A primary Node.js/Express backend (folder: backend/)
- A static frontend (HTML/CSS/JS + a Unity WebGL game) under frontend/
- An auxiliary game-API microservice (folder: game-api/)
- A MySQL database for persistent storage

##### File Structure
- Top-level:
- backend/ – Express app with REST controllers, service layer, data layer, middleware
- frontend/ – Static site assets: pages/, partials/, scripts/, styles/; plus a Unity WebGL build under frontend/game/
- game-api/ – Separate Node.js service exposing its own REST endpoints (db.js, index.js)
- backend/ follows a layered architecture:
- API (controllers) → Service (business logic) → Data (MySQL manager)
- middleware/ for auth and file uploads
- webserver.js (static file serving + API mounting)
- Configuration:
- backend/constants.js, .env for ports, DB credentials
- package.json and npm scripts for dev/prod
- frontend/ is purely static; it communicates with backend REST endpoints and the game-api.

##### README Insights
- Backend runs on port 4000 under base path /awaq
- REST routes for users, forms, images, metrics, support, etc.
- MySQL version 5.7+
- Static pages served from Express or by hosting frontend folder
- game-api is launched separately (likely different port, e.g., 5000)

##### Main Components & Interactions
a. Components
- Browser Client
- Static Frontend Server (Express static middleware)
- Backend API (Node.js/Express)
- game-api Microservice
- MySQL Database
- External Services:
– Email SMTP (emailService in backend)
– Cloud storage or local filesystem (imageUploadService)
b. Relationships
- Browser ↔ Static resources (HTML/CSS/JS + Unity WebGL)
- Browser JS ↔ Backend API endpoints (/awaq/api/…)
- Unity WebGL game ↔ game-api endpoints
- Backend Service layer ↔ Data layer → MySQL
- Backend ↔ External Email & Image storage
c. Architectural Patterns
- Layered (Controller → Service → Data) in backend
- Microservice pattern (game-api separate from main backend)
- Static assets + API separation
- Middleware for cross-cutting concerns (auth, uploads)
d. Key Technologies
- Node.js / Express
- MySQL
- Unity WebGL (HTML5 build)
- Vanilla JavaScript, HTML, CSS for UI
- nodemon for dev, dotenv for env vars

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Layer
    subgraph "Client Layer"
        Browser["Browser Client"]:::client
        Unity["Unity WebGL Game"]:::client
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        StaticServer["Static Frontend Server (Express)\\nport 4000"]:::presentation
    end

    %% Application Layer
    subgraph "Application Layer"
        BackendAPI["Main Backend API\\nNode.js/Express"]:::app
        GameAPI["game-api Microservice\\nNode.js (port 5000)"]:::app
        subgraph "Backend Structure"
            Controllers["Controllers"]:::backendComponent
            Services["Service Layer"]:::backendComponent
            DataLayer["Data Layer"]:::backendComponent
            Templates["Templates Module"]:::backendComponent
            AuthMw["Authentication Middleware"]:::middleware
            UploadMw["File Upload Middleware"]:::middleware
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        DB[(MySQL Database)]:::db
        EmailSvc["Email SMTP Service"]:::external
        StorageSvc["Image Storage Service"]:::external
    end

    %% Connections
    Browser -->|"GET HTML/CSS/JS"| StaticServer
    Browser -->|"GET Unity build"| StaticServer
    Browser -->|"REST calls /awaq/api"| BackendAPI
    Unity -->|"REST calls"| GameAPI

    StaticServer -->|serves| Browser

    BackendAPI -->|uses| Controllers
    Controllers -->|calls| Services
    Services -->|queries| DataLayer
    Controllers -->|protected by| AuthMw
    Controllers -->|uses| UploadMw
    Controllers -->|uses templates| Templates

    BackendAPI -->|CRUD| DB
    BackendAPI -->|send emails| EmailSvc
    BackendAPI -->|upload images| StorageSvc

    GameAPI -->|CRUD| DB

    %% Click Events
    click Browser "https://github.com/enmanuelrivas/retotc2005b/tree/main/frontend/pages/"
    click Browser "https://github.com/enmanuelrivas/retotc2005b/tree/main/frontend/partials/"
    click Browser "https://github.com/enmanuelrivas/retotc2005b/tree/main/frontend/scripts/"
    click Browser "https://github.com/enmanuelrivas/retotc2005b/tree/main/frontend/styles/"
    click Unity "https://github.com/enmanuelrivas/retotc2005b/tree/main/frontend/game/Build/"
    click Unity "https://github.com/enmanuelrivas/retotc2005b/tree/main/frontend/game/StreamingAssets/"
    click Unity "https://github.com/enmanuelrivas/retotc2005b/tree/main/frontend/game/TemplateData/"
    click Unity "https://github.com/enmanuelrivas/retotc2005b/blob/main/frontend/game/index.html"
    click StaticServer "https://github.com/enmanuelrivas/retotc2005b/blob/main/backend/webserver.js"
    click BackendAPI "https://github.com/enmanuelrivas/retotc2005b/blob/main/backend/main.js"
    click BackendAPI "https://github.com/enmanuelrivas/retotc2005b/blob/main/backend/constants.js"
    click BackendAPI "https://github.com/enmanuelrivas/retotc2005b/blob/main/backend/routes/router.js"
    click Controllers "https://github.com/enmanuelrivas/retotc2005b/tree/main/backend/API/"
    click Services "https://github.com/enmanuelrivas/retotc2005b/tree/main/backend/Service/"
    click DataLayer "https://github.com/enmanuelrivas/retotc2005b/blob/main/backend/Data/MySQLMngr.js"
    click BackendAPI "https://github.com/enmanuelrivas/retotc2005b/blob/main/backend/package.json"
    click AuthMw "https://github.com/enmanuelrivas/retotc2005b/blob/main/backend/middleware/auth.middleware.js"
    click UploadMw "https://github.com/enmanuelrivas/retotc2005b/blob/main/backend/middleware/upload.middleware.js"
    click EmailSvc "https://github.com/enmanuelrivas/retotc2005b/blob/main/backend/Service/emailService.js"
    click StorageSvc "https://github.com/enmanuelrivas/retotc2005b/blob/main/backend/Service/imageUploadService.js"
    click Templates "https://github.com/enmanuelrivas/retotc2005b/blob/main/backend/Templates/templates.js"

    %% Styles
    classDef client fill:#D0E6FF,stroke:#0366D6,color:#0366D6;
    classDef presentation fill:#E2F0D9,stroke:#0F5132,color:#0F5132;
    classDef app fill:#FFF4C1,stroke:#856404,color:#856404;
    classDef db fill:#FFE5B4,stroke:#BF360C,color:#BF360C;
    classDef external fill:#F0F0F0,stroke:#6C757D,color:#6C757D;
    classDef backendComponent fill:#F8D7DA,stroke:#721C24,color:#721C24;
    classDef middleware fill:#E2E3E5,stroke:#383D41,color:#383D41
```
