# vorellana/ranking-services architecture

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

- Interactive diagram: https://gitdiagram.com/vorellana/ranking-services
- Repository: https://github.com/vorellana/ranking-services

## Overview

##### Project’s Main Components
- Backend Service: This is implemented using Node.js and Express. It includes core modules like app.js and config.js, as well as separate directories for middlewares (e.g., authJwt), routes (e.g., auth, games, players, ranking), services for business logic (e.g., auth.service.js, games.service.js) and utilities for database connection and ranking functions.
- Frontend Service: Built with React, this part includes application components subdivided into different views (login, menu, players, ranking-board) with clear structure for routing (Routes.js) and service functions for API calls (auth, games, players, etc.). It also uses nginx as a serving web server.
- Database Service: PostgreSQL is used as the database, with an initialization script (init.sql) provided in the “database” folder. The Dockerfile here prepares the database container.
- Deployment Setup: docker-compose.yml orchestrates the containers (backend, frontend, and database) to work together.

- Within the Backend component, note:
– A set of modules representing routes (auth, games, players, ranking, etc.) that serve API endpoints.
– Middlewares (such as authJwt) that handle security (JWT validation) and other reusable functionality.
– Services that encapsulate business logic for handling various CRUD operations.
– Utilities for connection management and additional helper functions (ranking-functions).
- Within the Frontend component, include:
– A presentation layer with React components for each view (login, menu, players, ranking-board, etc.).
– A routing system to direct user navigation.
– Service layer functions (using Axios, jwt-decode, etc.) to interact with the backend API.
– Integration with nginx (from the frontend/nginx folder) that serves static content.
- The Database component represents PostgreSQL, with an initialization process (via init.sql) set up during container deployment.
- Data flow:

## Diagram (Mermaid)

```mermaid
graph TD
    %% Deployment Setup
    subgraph "Deployment Setup (Docker)"
        Dploy1["docker-compose.yml"]:::deployment
        Dploy2["Backend Dockerfile"]:::deployment
        Dploy3["Frontend Dockerfile"]:::deployment
        Dploy4["Database Dockerfile"]:::deployment
    end

    %% Frontend Container
    subgraph "Frontend Container [React]"
        F1["Login Component (Login.jsx)"]:::frontend
        F2["Menu Component (Menu.jsx)"]:::frontend
        F3["Players Component (Players.jsx)"]:::frontend
        F4["Ranking Board Component (RankingBoard.jsx)"]:::frontend
        F5["Ranking Component (Ranking.jsx)"]:::frontend
        F6["Routing (Routes.js)"]:::frontend
        F7["Service Functions"]:::frontend
        subgraph "Frontend Service Functions"
            F7a["Auth Service (auth.service.js)"]:::frontend
            F7b["Games Service (games.service.js)"]:::frontend
            F7c["Players Service (players.service.js)"]:::frontend
            F7d["Ranked Service (ranked.service.js)"]:::frontend
            F7e["Ranking Service (ranking.service.js)"]:::frontend
        end
        F8["nginx Config (default.conf)"]:::frontend
    end

    %% Backend Container
    subgraph "Backend Container [Node.js/Express]"
        B1["Main Application (app.js)"]:::backend
        B2["Configuration (config.js)"]:::backend
        B3["Middleware (authJwt)"]:::backend
        subgraph "Routes"
            B4["Auth Routes (auth.routes.js)"]:::backend
            B5["Games Routes (games.routes.js)"]:::backend
            B6["Players Routes (players.routes.js)"]:::backend
            B7["Ranked Routes (ranked.routes.js)"]:::backend
            B8["Ranking Routes (ranking.routes.js)"]:::backend
        end
        subgraph "Business Services"
            B9["Auth Service (auth.service.js)"]:::backend
            B10["Games Service (games.service.js)"]:::backend
            B11["Players Service (players.service.js)"]:::backend
            B12["Ranked Service (ranked.service.js)"]:::backend
            B13["Ranking Service (ranking.service.js)"]:::backend
        end
        subgraph "Utilities"
            B14["DB Connection (connection-db.js)"]:::backend
            B15["Ranking Functions (ranking-functions.js)"]:::backend
        end
    end

    %% Database Container
    subgraph "Database Container [PostgreSQL]"
        D1["Initialization Script (init.sql)"]:::database
        D2["PostgreSQL Database"]:::database
    end

    %% Communication Arrows
    %% Deployment orchestrates containers
    Dploy1 --- F6
    Dploy1 --- B1
    Dploy1 --- D2

    %% Frontend to Backend communication (HTTP API with JWT)
    F7 ---|"HTTP_API(JWT)"| B1
    B1 ---|"HTTP_Response"| F7

    %% Backend to Database communication
    B14 ---|"SQL_Query"| D2
    D2 ---|"SQL_Response"| B14

    %% Styles
    classDef frontend fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef backend fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef database fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef deployment fill:#f8d7da,stroke:#721c24,stroke-width:2px;

    %% Click Events - Backend Service
    click B1 "https://github.com/vorellana/ranking-services/blob/main/backend/src/app.js"
    click B2 "https://github.com/vorellana/ranking-services/blob/main/backend/src/config.js"
    click B3 "https://github.com/vorellana/ranking-services/blob/main/backend/src/middlewares/authJwt.js"
    click B4 "https://github.com/vorellana/ranking-services/blob/main/backend/src/routes/auth.routes.js"
    click B5 "https://github.com/vorellana/ranking-services/blob/main/backend/src/routes/games.routes.js"
    click B6 "https://github.com/vorellana/ranking-services/blob/main/backend/src/routes/players.routes.js"
    click B7 "https://github.com/vorellana/ranking-services/blob/main/backend/src/routes/ranked.routes.js"
    click B8 "https://github.com/vorellana/ranking-services/blob/main/backend/src/routes/ranking.routes.js"
    click B9 "https://github.com/vorellana/ranking-services/blob/main/backend/src/services/auth.service.js"
    click B10 "https://github.com/vorellana/ranking-services/blob/main/backend/src/services/games.service.js"
    click B11 "https://github.com/vorellana/ranking-services/blob/main/backend/src/services/players.service.js"
    click B12 "https://github.com/vorellana/ranking-services/blob/main/backend/src/services/ranked.service.js"
    click B13 "https://github.com/vorellana/ranking-services/blob/main/backend/src/services/ranking.service.js"
    click B14 "https://github.com/vorellana/ranking-services/blob/main/backend/src/utils/connection-db.js"
    click B15 "https://github.com/vorellana/ranking-services/blob/main/backend/src/utils/ranking-functions.js"

    %% Click Events - Frontend Service
    click F1 "https://github.com/vorellana/ranking-services/blob/main/frontend/src/components/login/Login.jsx"
    click F2 "https://github.com/vorellana/ranking-services/blob/main/frontend/src/components/menu/Menu.jsx"
    click F3 "https://github.com/vorellana/ranking-services/blob/main/frontend/src/components/players/Players.jsx"
    click F4 "https://github.com/vorellana/ranking-services/blob/main/frontend/src/components/ranking-board/RankingBoard.jsx"
    click F5 "https://github.com/vorellana/ranking-services/blob/main/frontend/src/components/ranking/Ranking.jsx"
    click F6 "https://github.com/vorellana/ranking-services/blob/main/frontend/src/routes/Routes.js"
    click F7a "https://github.com/vorellana/ranking-services/blob/main/frontend/src/services/auth.service.js"
    click F7b "https://github.com/vorellana/ranking-services/blob/main/frontend/src/services/games.service.js"
    click F7c "https://github.com/vorellana/ranking-services/blob/main/frontend/src/services/players.service.js"
    click F7d "https://github.com/vorellana/ranking-services/blob/main/frontend/src/services/ranked.service.js"
    click F7e "https://github.com/vorellana/ranking-services/blob/main/frontend/src/services/ranking.service.js"
    click F8 "https://github.com/vorellana/ranking-services/blob/main/frontend/nginx/default.conf"

    %% Click Events - Database Service
    click D1 "https://github.com/vorellana/ranking-services/blob/main/database/init.sql"

    %% Click Events - Deployment Setup
    click Dploy1 "https://github.com/vorellana/ranking-services/blob/main/docker-compose.yml"
    click Dploy2 "https://github.com/vorellana/ranking-services/tree/main/backend/Dockerfile"
    click Dploy3 "https://github.com/vorellana/ranking-services/tree/main/frontend/Dockerfile"
    click Dploy4 "https://github.com/vorellana/ranking-services/tree/main/database/Dockerfile"
```
