# mohcine-ghalmi/ft_transcendence architecture

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

- Interactive diagram: https://gitdiagram.com/mohcine-ghalmi/ft_transcendence
- Repository: https://github.com/mohcine-ghalmi/ft_transcendence

## Overview

##### Project Type and Purpose
- This is a full-stack, containerized microservices web application (“ft_transcendence”) offering real-time chat, multiplayer games, user management and social features.
- The README confirms it uses separate Node.js/TypeScript services for chat, game logic and core application logic, a Next.js/React frontend, Redis and SQLite databases, all wired together with Docker Compose and Nginx as a reverse proxy.

##### File Structure
- Top-level directories:
- frontend/ – Next.js app (React + Zustand)
- backend/ – three sub-services (chat/, game/, main/) each with its own Dockerfile, TS code, database connection (SQLite/Redis) and WebSocket integration
- nginx/ – Dockerfile + conf for reverse proxy
- redis/ – Dockerfile + init scripts
- sqlite/ – Dockerfile + SQL schema
- docker-compose.yml, Makefile, env files for each service
- Pattern: three independent backend microservices exposing REST/WebSocket endpoints, a single frontend container, two data stores, and an Nginx container fronting everything.

##### README for Additional Insights
- Tech stack: Next.js, React, Zustand, Node.js + Fastify/Express, WebSocket, Redis, SQLite, Docker, Docker Compose, Nginx.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Outer orchestration
    subgraph "Docker Compose" 
        direction TB
        Compose["Docker Compose"]:::infra

        subgraph "Client"
            direction TB
            Browser["Browser"]:::external
        end

        subgraph "Infrastructure"
            direction TB
            Nginx["Nginx Reverse Proxy"]:::proxy
        end

        subgraph "Services"
            direction TB
            Frontend["Frontend Service (Next.js)"]:::frontend
            subgraph "Backend Services"
                direction TB
                MainService["Main Service (REST API)"]:::backend
                ChatService["Chat Service (WebSocket Chat)"]:::backend
                GameService["Game Service (WebSocket Game)"]:::backend
            end
        end

        subgraph "Datastores"
            direction TB
            Redis["Redis"]:::db
            SQLite["SQLite"]:::db
        end

        %% Connections
        Browser -->|"HTTPS"| Nginx
        Nginx -->|"Route /"| Frontend
        Nginx -->|"Route /api/main"| MainService
        Nginx -->|"Route /api/chat"| ChatService
        Nginx -->|"Route /api/game"| GameService
        Nginx -->|"WS /socket.io/chat"| ChatService
        Nginx -->|"WS /socket.io/game"| GameService

        Frontend -->|"REST API calls"| MainService
        Frontend -->|"WebSocket"| ChatService
        Frontend -->|"WebSocket"| GameService

        MainService -->|"Reads/Writes"| SQLite
        MainService -->|"Caches/Sessions"| Redis

        ChatService -->|"Pub/Sub"| Redis
        ChatService -->|"Persists Chat"| SQLite

        GameService -->|"Pub/Sub"| Redis
        GameService -->|"Persists Game Data"| SQLite

        %% Orchestration link
        Compose --> Browser
        Compose --> Nginx
        Compose --> Frontend
        Compose --> MainService
        Compose --> ChatService
        Compose --> GameService
        Compose --> Redis
        Compose --> SQLite
    end

    %% Click Events
    click Nginx "https://github.com/mohcine-ghalmi/ft_transcendence/blob/main/nginx/nginx.conf"
    click Frontend "https://github.com/mohcine-ghalmi/ft_transcendence/blob/main/frontend/next.config.ts"
    click MainService "https://github.com/mohcine-ghalmi/ft_transcendence/blob/main/backend/main/src/app.ts"
    click ChatService "https://github.com/mohcine-ghalmi/ft_transcendence/blob/main/backend/chat/src/app.ts"
    click GameService "https://github.com/mohcine-ghalmi/ft_transcendence/blob/main/backend/game/src/app.ts"
    click Redis "https://github.com/mohcine-ghalmi/ft_transcendence/tree/main/redis/Dockerfile"
    click SQLite "https://github.com/mohcine-ghalmi/ft_transcendence/tree/main/sqlite/dockerfile"
    click Compose "https://github.com/mohcine-ghalmi/ft_transcendence/blob/main/docker-compose.yml"

    %% Styles
    classDef external fill:#AED6F1,stroke:#2980B9,color:#1B4F72
    classDef proxy fill:#D7BDE2,stroke:#8E44AD,color:#4A235A
    classDef frontend fill:#85C1E9,stroke:#1F618D,color:#154360
    classDef backend fill:#82E0AA,stroke:#239B56,color:#1D8348
    classDef db fill:#F5B041,stroke:#B9770E,color:#7E5109
    classDef infra fill:#D5D8DC,stroke:#566573,color:#212F3D
```
