# axiaaa/ft_transcendance architecture

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

- Interactive diagram: https://gitdiagram.com/axiaaa/ft_transcendance
- Repository: https://github.com/axiaaa/ft_transcendance

## Overview

##### Project type and purpose
- This is a full-stack, containerized web application (“ft_transcendance” aka “Windows XPong”) that provides a Windows XP–style desktop environment in the browser, real-time multiplayer Pong, chat, profiles, matchmaking/tournaments, AI opponents, and social features.
- It uses micro-service–style backend components, a static/TS-based rich frontend, an Nginx reverse proxy, and a full observability/logging/monitoring stack.

##### File structure
- Top-level:
- docker-compose.yaml – orchestrates all containers
- nginx/ – Nginx reverse-proxy container
- backend/ – three small API services plus a DB service
- frontend/ – static HTML/CSS/TS app plus Pong AI model
- services/ – monitoring & logging stack (Prometheus, Grafana, ELK, cAdvisor, Alertmanager, etc.)
- backend/ is split into:
- db/ – database initialization (SQL), packaged as its own container
- user-route/, upload-route/, matchs-route/ – three isolated TypeScript API services (each with its own Dockerfile, package.json, routes folder, rate limiting middleware)
- frontend/ contains a TS-based UI (XP desktop, start menu, apps, Pong integration) and static assets (CSS, fonts, images).
- services/ holds multiple Dockerfiles and configuration for observability:
- Prometheus + Alertmanager
- Elasticsearch, Logstash, Filebeat, Kibana (ELK)
- Grafana + dashboards
- cAdvisor, certificate generation scripts, etc.
- nginx/config/nginx.conf is the entry-point that routes HTTPS traffic to frontend and API services.

##### README for additional insights
- Outlines use of NestJS (backend framework), PostgreSQL or SQLite (database), Docker & Docker Compose, TypeScript (frontend + backend), BabylonJS for 3D, and a full monitoring stack.
- Describes features: authentication, profile customization, real-time chat, matchmaking, AI opponents, tournaments, responsive XP theme.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "User-facing"
        Browser("Browser"):::external
    end

    subgraph "Reverse Proxy"
        Nginx["Nginx Reverse Proxy"]:::proxy
    end

    subgraph "Frontend Layer"
        Frontend["Frontend Service"]:::frontend
    end

    subgraph "API Services"
        UserAPI["User-Route API Service"]:::api
        UploadAPI["Upload-Route API Service"]:::api
        MatchsAPI["Matchs-Route API Service"]:::api
    end

    subgraph "Database Service"
        DB[(Database Service)]:::db
    end

    subgraph "TypeScript Compiler"
        TS["TypeScript Compiler Service"]:::tool
    end

    subgraph "Monitoring & Logging Stack"
        Prometheus["Prometheus"]:::monitor
        Alertmanager["Alertmanager"]:::monitor
        cAdvisor["cAdvisor"]:::monitor
        Filebeat["Filebeat"]:::monitor
        Logstash["Logstash"]:::monitor
        Elasticsearch["Elasticsearch"]:::monitor
        Kibana["Kibana"]:::monitor
        Grafana["Grafana"]:::monitor
    end

    %% Request flow
    Browser -->|"HTTPS"| Nginx
    Nginx -->|"/"| Frontend
    Nginx -->|"/api/users"| UserAPI
    Nginx -->|"/api/upload"| UploadAPI
    Nginx -->|"/api/matchs"| MatchsAPI

    %% API to DB
    UserAPI -->|queries| DB
    UploadAPI -->|queries| DB
    MatchsAPI -->|queries| DB

    %% Build service
    TS -->|watches TS files| Frontend
    TS -->|watches TS files| UserAPI
    TS -->|watches TS files| UploadAPI
    TS -->|watches TS files| MatchsAPI

    %% Metrics flow
    UserAPI -.->|metrics| Prometheus
    UploadAPI -.->|metrics| Prometheus
    MatchsAPI -.->|metrics| Prometheus
    Frontend -.->|metrics| Prometheus
    DB -.->|metrics| cAdvisor
    Nginx -.->|metrics| cAdvisor

    Prometheus -->|alerts| Alertmanager
    Prometheus -->|data| Grafana

    %% Logs flow
    UserAPI -.->|logs| Filebeat
    UploadAPI -.->|logs| Filebeat
    MatchsAPI -.->|logs| Filebeat
    Frontend -.->|logs| Filebeat
    Nginx -.->|logs| Filebeat

    Filebeat --> Logstash
    Logstash --> Elasticsearch
    Elasticsearch --> Kibana
    Elasticsearch --> Grafana

    %% Click events
    click Nginx "https://github.com/axiaaa/ft_transcendance/tree/main/nginx/"
    click Frontend "https://github.com/axiaaa/ft_transcendance/blob/main/frontend/index.html"
    click UserAPI "https://github.com/axiaaa/ft_transcendance/tree/main/backend/user-route/"
    click UploadAPI "https://github.com/axiaaa/ft_transcendance/tree/main/backend/upload-route/"
    click MatchsAPI "https://github.com/axiaaa/ft_transcendance/tree/main/backend/matchs-route/"
    click DB "https://github.com/axiaaa/ft_transcendance/tree/main/backend/db/Dockerfile"
    click TS "https://github.com/axiaaa/ft_transcendance/tree/main/services/ts-compiler/"
    click Prometheus "https://github.com/axiaaa/ft_transcendance/tree/main/services/prometheus/"
    click Alertmanager "https://github.com/axiaaa/ft_transcendance/tree/main/services/alertmanager/"
    click cAdvisor "https://github.com/axiaaa/ft_transcendance/tree/main/services/cadvisor/"
    click Filebeat "https://github.com/axiaaa/ft_transcendance/tree/main/services/filebeat/"
    click Logstash "https://github.com/axiaaa/ft_transcendance/tree/main/services/logstash/"
    click Elasticsearch "https://github.com/axiaaa/ft_transcendance/tree/main/services/elasticsearch/"
    click Kibana "https://github.com/axiaaa/ft_transcendance/tree/main/services/kibana/"
    click Grafana "https://github.com/axiaaa/ft_transcendance/tree/main/services/grafana/"

    %% Styles
    classDef external fill:#ffffff,stroke:#333,stroke-width:1px
    classDef proxy fill:#ffcccc,stroke:#333,stroke-width:1px
    classDef frontend fill:#ddeeff,stroke:#333,stroke-width:1px
    classDef api fill:#ccffcc,stroke:#333,stroke-width:1px
    classDef db fill:#ffebcc,stroke:#333,stroke-width:1px
    classDef tool fill:#e0e0e0,stroke:#333,stroke-width:1px
    classDef monitor fill:#ffe0b3,stroke:#333,stroke-width:1px
```
