# vicode-dev/transcendence architecture

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

- Interactive diagram: https://gitdiagram.com/vicode-dev/transcendence
- Repository: https://github.com/vicode-dev/transcendence

## Overview

This project – Transcendence – is a full-stack microservices web application that lets users play pong (and connect 4) while also incorporating blockchain score storage, remote multiplayer and CLI gameplay. The codebase is organized into several parts: a CLI directory (with separate game implementations for pong and connect4), and a services directory that houses multiple Dockerized microservices (authentication, blockchain, game-serv, user management, ELK & monitoring stacks, nginx reverse proxy, and more). The README reinforces that the project’s architecture is based on Django for the backend, Bootstrap/vanilla JavaScript for the frontend, Postgres as a database, and Ethereum for blockchain score management.

##### Main Components
- Frontend:
– Web UI for gameplay, user management, and tournament pages.
– Static assets – HTML templates, CSS, JavaScript (including advanced 3D parts via ThreeJS/WebGL).
- Backend Microservices:
– Authentication Service (supports standard user management and OAuth 42-based remote authentication).
– Game Service (the “game-serv” service handling real-time pong gameplay, including different game modes through consumers, routing, and API integrations).
– User Management Service (handles profiles, friends, GDPR-compliant data handling, 2FA with JWT, settings, etc).
– Other domain-specific services (for blockchain score recording, tournament management, and chat/lobby functionality).
- CLI:
– A dedicated command-line interface offering offline or interconnected gameplay (against both AI and real players).
- Supporting Infrastructure:
– Database: PostgreSQL as the main data store.
– DevOps & Monitoring: ELK stack (Elasticsearch, Logstash, Kibana), Prometheus, Grafana, Filebeat.
– Reverse Proxy / Load Balancer: nginx.
– Container orchestration through Docker and docker-compose.
– Blockchain: Ethereum network with Solidity smart contracts to store tournament scores.

##### Relationships & Interactions
- User requests via the Web UI hit the nginx reverse proxy which forwards them to the appropriate backend microservice (or API gateway if applicable).
- Authentication and user management services communicate with the Postgres database and possibly with external APIs (e.g., OAuth 2.0 integration with 42).
- The game-serv module interacts with both the frontend (real-time game events via WebSockets or API endpoints) and the CLI interface.
- Microservices publish/log data that flows into the ELK stack; Prometheus and Grafana monitor health metrics.
- The blockchain service is responsible for interacting with Ethereum to record tournament score data; it may be called from within the user management or game service.
- The CLI components (found in the CLI folder) provide an alternative entry point that communicates with the same backend API endpoints, facilitating gameplay between web and terminal users.

##### Architectural Patterns and Design Principles
- Microservices Architecture: Each service is containerized (using Docker) and deployed separately, communicating via well-defined APIs.
- Separation of concerns: Frontend, game logic, authentication, and monitoring are all clearly isolated.
- Use of industry-standard frameworks: Django for backend applications, Bootstrap and vanilla JavaScript (with some ThreeJS) for the frontend; smart contract development in Solidity.
- Container orchestration: The docker-compose.yml file shows how services are interconnected.
- Secure design: Integration of JWT, 2FA, and GDPR compliance (user anonymization and deletion flows).

##### Technologies and Frameworks
- Backend/Django, Frontend/Bootstrap & JavaScript (with advanced 3D via ThreeJS/WebGL), PostgreSQL, Ethereum (via Solidity contracts).
- DevOps: Docker, docker-compose, ELK stack (Elasticsearch, Logstash, Kibana), Prometheus, Grafana.
- Reverse proxy: nginx.
- CLI: Python-based CLI tools for game play.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        Browser["Web Browser (Client)"]:::client
        subgraph "Frontend Assets"
            GFE["Game Frontend"]:::frontend
            UFE["User Management Frontend"]:::frontend
        end
        CLI["CLI Interface"]:::cli
    end

    %% API Gateway / Reverse Proxy
    subgraph "API Gateway / Reverse Proxy"
        nginx["nginx Reverse Proxy"]:::infra
    end

    %% Backend Microservices
    subgraph "Backend Microservices"
        Auth["Authentication Service (JWT,2FA)"]:::backend
        Game["Game Service (Real-time,WebSockets)"]:::backend
        UserM["User Management Service"]:::backend
        Blockchain["Blockchain Service"]:::backend
    end

    %% Data & Monitoring and Orchestration
    subgraph "Data & Monitoring"
        PostgreSQL["PostgreSQL Database"]:::infra
        subgraph "DevOps & Monitoring"
            Elasticsearch["Elasticsearch"]:::infra
            Logstash["Logstash"]:::infra
            Filebeat["Filebeat"]:::infra
            Prometheus["Prometheus"]:::infra
            Grafana["Grafana"]:::infra
        end
        Ethereum["Ethereum Blockchain"]:::infra
        Orchestration["Docker Compose Orchestration"]:::infra
    end

    %% Connections from Clients to API Gateway
    Browser -->|"HTTP_Request"| nginx
    CLI -->|"API_Requests"| nginx

    %% API Gateway to Backend Microservices
    nginx -->|"Auth_API"| Auth
    nginx -->|"Game_API"| Game
    nginx -->|"User_API"| UserM
    nginx -->|"Blockchain_API"| Blockchain

    %% Backend Microservices Interactions
    Auth -->|"DB_Query"| PostgreSQL
    UserM -->|"DB_Query"| PostgreSQL
    Game -->|"RealTimeEvents"| Browser
    Game -->|"CLI_API"| CLI

    %% Logging & Monitoring Data Flow
    Auth -->|"Log_Data"| Elasticsearch
    Game -->|"Log_Data"| Logstash
    UserM -->|"Log_Data"| Filebeat
    Blockchain -->|"Log_Data"| Prometheus
    Blockchain -->|"BlockchainTx"| Ethereum

    %% Container Orchestration connections
    Orchestration -->|"Orchestrates"| Auth
    Orchestration -->|"Orchestrates"| Game
    Orchestration -->|"Orchestrates"| UserM
    Orchestration -->|"Orchestrates"| Blockchain
    Orchestration -->|"Orchestrates"| nginx

    %% Styles
    classDef client fill:#b3e5fc,stroke:#0277bd,stroke-width:2px;
    classDef frontend fill:#80deea,stroke:#00838f,stroke-width:2px;
    classDef cli fill:#d1c4e9,stroke:#512da8,stroke-width:2px;
    classDef backend fill:#ffe082,stroke:#ff6f00,stroke-width:2px;
    classDef infra fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;

    %% Click Events for Frontend Assets
    click GFE "https://github.com/vicode-dev/transcendence/tree/main/services/game-serv/app/app/templates"
    click GFE "https://github.com/vicode-dev/transcendence/tree/main/services/game-serv/app/app/static"
    click UFE "https://github.com/vicode-dev/transcendence/tree/main/services/user-management/app/profile/templates"
    click UFE "https://github.com/vicode-dev/transcendence/tree/main/services/user-management/app/profile/static"

    %% Click Events for Backend Services
    click Auth "https://github.com/vicode-dev/transcendence/tree/main/services/authentication"
    click Game "https://github.com/vicode-dev/transcendence/tree/main/services/game-serv"
    click Game "https://github.com/vicode-dev/transcendence/tree/main/services/game-serv/app/app/consumers"
    click Game "https://github.com/vicode-dev/transcendence/blob/main/services/game-serv/app/app/routing.py"
    click UserM "https://github.com/vicode-dev/transcendence/tree/main/services/user-management/app/profile"
    click Blockchain "https://github.com/vicode-dev/transcendence/tree/main/services/blockchain"

    %% Click Event for CLI Interface
    click CLI "https://github.com/vicode-dev/transcendence/tree/main/CLI"

    %% Click Event for Reverse Proxy
    click nginx "https://github.com/vicode-dev/transcendence/tree/main/services/nginx"

    %% Click Events for DevOps & Monitoring Tools
    click Elasticsearch "https://github.com/vicode-dev/transcendence/tree/main/services/elasticsearch"
    click Logstash "https://github.com/vicode-dev/transcendence/tree/main/services/logstash"
    click Filebeat "https://github.com/vicode-dev/transcendence/tree/main/services/filebeat"
    click Prometheus "https://github.com/vicode-dev/transcendence/tree/main/services/prometheus"
    click Grafana "https://github.com/vicode-dev/transcendence/tree/main/services/grafana"

    %% Click Event for Container Orchestration
    click Orchestration "https://github.com/vicode-dev/transcendence/blob/main/docker-compose.yml"
```
