# oettaqui/transcendence_42 architecture

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

- Interactive diagram: https://gitdiagram.com/oettaqui/transcendence_42
- Repository: https://github.com/oettaqui/transcendence_42

## Overview

##### Project type and purpose
- This is a full-stack, real-time multiplayer gaming platform (“ft_transcendence”) built on a microservices backend.
- Its purpose is to provide ping-pong gameplay, chat, tournaments, user management, and monitoring/logging in a containerized environment.

##### File structure
- Top-level ● backend ● front-end ● nginx ● infra ● docker-compose.yml ● Makefile
- backend/ contains five services (api-gateway, user, game, chat, tournament), each with its own Dockerfile, routes, controllers, models, and WebSocket or HTTP server entry point.
- front-end/ holds a TypeScript SPA powered by Vite.
- nginx/ contains reverse-proxy configuration.
- infra/ holds ELK Stack and Prometheus + Grafana definitions for logging and metrics.

##### Review README architecture section
- NGINX acts as a reverse proxy/load balancer.
- A SPA frontend communicates with an API Gateway on port 3000.
- The API Gateway routes to microservices: user (3001), chat (3005), game (3003/3006), tournament (3007).
- Each service uses SQLite (with shared volume auth_data for user/chat).
- Monitoring: ELK Stack for logs, Prometheus + Grafana for metrics.

- Blue for edge and API Gateway
- Green for microservices
- Orange for databases/volumes
- Gray for monitoring/logging
- Annotations for ports (3000, 3001, 3003/3006, 3005, 3007) and protocols (HTTP, HTTPS, WS)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Edge and Clients
    Browser["Browser (SPA)"]:::frontend
    Nginx["Nginx Reverse Proxy\nPorts 80/443"]:::edge
    SPA["Front-end SPA\nPort 3000"]:::frontend

    %% API Layer
    Gateway["API Gateway\nPort 3000"]:::gateway

    %% Microservices Cluster
    subgraph "Microservices" 
        direction TB
        User["User Service\nPort 3001"]:::micro
        Chat["Chat Service\nPort 3005"]:::micro
        Game["Game Service\nPorts 3003/3006"]:::micro
        Tour["Tournament Service\nPort 3007"]:::micro
    end

    %% Data Stores
    subgraph "Databases" 
        direction TB
        UserDB["auth.db\nSQLite"]:::db
        ChatDB["chat.db\nSQLite"]:::db
        GameDB["game.db\nSQLite"]:::db
        TourDB["tournament.db\nSQLite"]:::db
    end

    %% Observability
    subgraph "Logging & Monitoring"
        direction TB
        Logstash["Logstash"]:::obs
        Elasticsearch["Elasticsearch"]:::obs
        Kibana["Kibana"]:::obs
        Prometheus["Prometheus"]:::obs
        Grafana["Grafana"]:::obs
    end

    %% Connections
    Browser -->|HTTP/HTTPS| Nginx
    Nginx -->|static files| SPA
    Nginx -->|proxy REST/WS| Gateway
    SPA -->|API calls| Gateway

    Gateway -->|REST/WS| User
    Gateway -->|REST/WS| Chat
    Gateway -->|REST/WS| Game
    Gateway -->|REST/WS| Tour

    User -->|reads/writes| UserDB
    Chat -->|reads/writes| ChatDB
    Game -->|reads/writes| GameDB
    Tour -->|reads/writes| TourDB

    %% WebSocket real-time streams
    Chat -->|"WebSocket"| Browser
    Game -->|"WebSocket"| Browser

    %% Logging pipeline
    Gateway -->|logs| Logstash
    User -->|logs| Logstash
    Chat -->|logs| Logstash
    Game -->|logs| Logstash
    Tour -->|logs| Logstash

    Logstash --> Elasticsearch --> Kibana

    %% Metrics pipeline
    Gateway -->|metrics scrape| Prometheus
    User -->|metrics scrape| Prometheus
    Chat -->|metrics scrape| Prometheus
    Game -->|metrics scrape| Prometheus
    Tour -->|metrics scrape| Prometheus

    Prometheus --> Grafana

    %% Click Events
    click Nginx "https://github.com/oettaqui/transcendence_42/tree/main/nginx/"
    click SPA "https://github.com/oettaqui/transcendence_42/tree/main/front-end/"
    click Gateway "https://github.com/oettaqui/transcendence_42/tree/main/backend/api-gateway/"
    click User "https://github.com/oettaqui/transcendence_42/tree/main/backend/user-service/"
    click Chat "https://github.com/oettaqui/transcendence_42/tree/main/backend/chat-service/"
    click Game "https://github.com/oettaqui/transcendence_42/tree/main/backend/game-service/"
    click Tour "https://github.com/oettaqui/transcendence_42/tree/main/backend/tournament-service/"
    click Logstash "https://github.com/oettaqui/transcendence_42/tree/main/infra/elk/"
    click Prometheus "https://github.com/oettaqui/transcendence_42/tree/main/infra/monitoring/"

    %% Styles
    classDef edge fill:#cce5ff,stroke:#004085,color:#004085;
    classDef frontend fill:#e2e3e5,stroke:#383d41,color:#383d41;
    classDef gateway fill:#b8daff,stroke:#0056b3,color:#0056b3;
    classDef micro fill:#d4edda,stroke:#155724,color:#155724;
    classDef db fill:#fff3cd,stroke:#856404,color:#856404;
    classDef obs fill:#d6d8d9,stroke:#1b1e21,color:#1b1e21;
```
