# fbenkaci/ft_transcendence architecture

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

- Interactive diagram: https://gitdiagram.com/fbenkaci/ft_transcendence
- Repository: https://github.com/fbenkaci/ft_transcendence
- Video tour (about a minute): https://gitdiagram.com/fbenkaci/ft_transcendence/video

## Overview

Transcendance is a Pong web game with local 1v1 and AI play, real-time online matchmaking, tournaments, blockchain match history, and social features including friends and chat. The main flow is a player choosing a game mode, playing through a browser canvas or WebSocket, and—when online or in a tournament—having match state and results handled by the backend. Django REST endpoints also support accounts and profiles; tournament progression is persisted and optionally recorded on-chain. The graph reflects documented capabilities, but unsampled frontend and backend integrations are not assigned speculative call paths.

Main entry points: [`backend/api/views.py`](https://github.com/fbenkaci/ft_transcendence/blob/main/backend/api/views.py) (REST API), [`frontend/app/online/useOnlineGame.ts`](https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/online/useOnlineGame.ts) (Online game client), [`backend/api/tournament_service.py`](https://github.com/fbenkaci/ft_transcendence/blob/main/backend/api/tournament_service.py) (Bracket progression), [`backend/api/consumers.py`](https://github.com/fbenkaci/ft_transcendence/blob/main/backend/api/consumers.py) (Pong WebSocket)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_play["Pong modes"]
  node_mode_select["Mode selection<br/>[page.tsx]"]
  node_local_game["Local 1v1 loop<br/>[useGameLoop.ts]"]
  node_local_canvas["1v1 canvas<br/>[PongCanvas.tsx]"]
  node_ai_game["AI game loop<br/>[useGameLoops.ts]"]
  node_ai_canvas["AI canvas<br/>[PongCanvas.tsx]"]
  node_online_client["Online game client<br/>[useOnlineGame.ts]"]
  node_online_canvas["Online canvas"]
end

subgraph group_server["Backend services"]
  node_ws_server["Pong WebSocket<br/>[consumers.py]"]
  node_ws_routes["WebSocket routes<br/>[routing.py]"]
  node_chat["Chat WebSocket<br/>[consumers.py]"]
  node_api["REST API<br/>[views.py]"]
  node_models[("Domain records<br/>[models.py]")]
  node_serializers["API serializers<br/>[serializers.py]"]
  node_auth["JWT authentication<br/>[jwt_middleware.py]"]
  node_metrics["Metrics endpoint<br/>[metrics.py]"]
end

subgraph group_tournament["Tournament play"]
  node_tournament_ui["Tournament pages<br/>[page.tsx]"]
  node_match_ui["Tournament match view<br/>[page.tsx]"]
  node_match_canvas["Match canvas"]
  node_bracket["Bracket progression"]
  node_chain["Blockchain history<br/>[service.py]"]
end

subgraph group_social["Accounts and social"]
  node_account_ui["Account and auth UI<br/>[page.tsx]"]
  node_friends_ui["Friends UI<br/>[page.tsx]"]
  node_chat_ui["Chat UI<br/>[page.tsx]"]
end

node_player(("Player"))

node_player -->|"chooses mode"| node_mode_select
node_player -->|"plays locally"| node_local_game
node_local_game -.->|"updates view"| node_local_canvas
node_player -->|"plays versus AI"| node_ai_game
node_ai_game -->|"updates view"| node_ai_canvas
node_player -->|"joins match"| node_online_client
node_online_client -->|"sends game actions"| node_ws_server
node_online_client -.->|"renders state"| node_online_canvas
node_ws_routes -->|"routes Pong"| node_ws_server
node_ws_routes -->|"routes chat"| node_chat
node_ws_server -->|"records match results"| node_models
node_player -->|"uses account services"| node_api
node_api -->|"reads and writes"| node_models
node_api -->|"serializes data"| node_serializers
node_account_ui -.->|"requests profile and auth"| node_api
node_friends_ui -.->|"manages friendships"| node_api
node_chat_ui -.->|"connects to chat"| node_chat
node_api -.->|"uses JWT protection"| node_auth
node_player -->|"enters tournament"| node_tournament_ui
node_tournament_ui -.->|"manages tournament"| node_api
node_match_ui -->|"renders match"| node_match_canvas
node_match_canvas -->|"uses online game"| node_online_client
node_api -->|"starts bracket"| node_bracket
node_bracket -->|"creates rounds"| node_models
node_api -->|"stores tournament"| node_chain
node_bracket -->|"stores match result"| node_chain
node_api -->|"exposes metrics"| node_metrics

click node_mode_select "https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/start/page.tsx"
click node_local_game "https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/1vs1/useGameLoop.ts"
click node_local_canvas "https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/1vs1/PongCanvas.tsx"
click node_ai_game "https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/ia_vs/useGameLoops.ts"
click node_ai_canvas "https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/ia_vs/PongCanvas.tsx"
click node_online_client "https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/online/useOnlineGame.ts"
click node_online_canvas "https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/online/OnlinePongCanvas.tsx"
click node_ws_server "https://github.com/fbenkaci/ft_transcendence/blob/main/backend/api/consumers.py"
click node_ws_routes "https://github.com/fbenkaci/ft_transcendence/blob/main/backend/api/routing.py"
click node_chat "https://github.com/fbenkaci/ft_transcendence/blob/main/backend/api/consumers.py"
click node_api "https://github.com/fbenkaci/ft_transcendence/blob/main/backend/api/views.py"
click node_models "https://github.com/fbenkaci/ft_transcendence/blob/main/backend/api/models.py"
click node_serializers "https://github.com/fbenkaci/ft_transcendence/blob/main/backend/api/serializers.py"
click node_tournament_ui "https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/tournaments/page.tsx"
click node_match_ui "https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/tournaments/%5Bid%5D/page.tsx"
click node_match_canvas "https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/tournaments/%5Bid%5D/TournamentMatchCanvas.tsx"
click node_bracket "https://github.com/fbenkaci/ft_transcendence/blob/main/backend/api/tournament_service.py"
click node_chain "https://github.com/fbenkaci/ft_transcendence/blob/main/backend/blockchain/service.py"
click node_account_ui "https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/account/page.tsx"
click node_friends_ui "https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/friends/page.tsx"
click node_chat_ui "https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/chat/page.tsx"
click node_auth "https://github.com/fbenkaci/ft_transcendence/blob/main/backend/api/jwt_middleware.py"
click node_metrics "https://github.com/fbenkaci/ft_transcendence/blob/main/backend/api/metrics.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_mode_select,node_local_game,node_local_canvas,node_ai_game,node_ai_canvas,node_online_client,node_online_canvas toneBlue
class node_ws_server,node_ws_routes,node_chat,node_api,node_models,node_serializers,node_auth,node_metrics toneAmber
class node_tournament_ui,node_match_ui,node_match_canvas,node_bracket,node_chain toneMint
class node_account_ui,node_friends_ui,node_chat_ui toneRose
class node_player toneIndigo
```

## Components

### Pong modes

- [Mode selection](https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/start/page.tsx): `frontend/app/start/page.tsx`
- [Local 1v1 loop](https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/1vs1/useGameLoop.ts): `frontend/app/1vs1/useGameLoop.ts`
- [1v1 canvas](https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/1vs1/PongCanvas.tsx): `frontend/app/1vs1/PongCanvas.tsx`
- [AI game loop](https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/ia_vs/useGameLoops.ts): `frontend/app/ia_vs/useGameLoops.ts`
- [AI canvas](https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/ia_vs/PongCanvas.tsx): `frontend/app/ia_vs/PongCanvas.tsx`
- [Online game client](https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/online/useOnlineGame.ts): `frontend/app/online/useOnlineGame.ts`
- [Online canvas](https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/online/OnlinePongCanvas.tsx): `frontend/app/online/OnlinePongCanvas.tsx`

### Backend services

- [Pong WebSocket](https://github.com/fbenkaci/ft_transcendence/blob/main/backend/api/consumers.py): `backend/api/consumers.py`
- [WebSocket routes](https://github.com/fbenkaci/ft_transcendence/blob/main/backend/api/routing.py): `backend/api/routing.py`
- [Chat WebSocket](https://github.com/fbenkaci/ft_transcendence/blob/main/backend/api/consumers.py): `backend/api/consumers.py`
- [REST API](https://github.com/fbenkaci/ft_transcendence/blob/main/backend/api/views.py): `backend/api/views.py`
- [Domain records](https://github.com/fbenkaci/ft_transcendence/blob/main/backend/api/models.py): `backend/api/models.py`
- [API serializers](https://github.com/fbenkaci/ft_transcendence/blob/main/backend/api/serializers.py): `backend/api/serializers.py`
- [JWT authentication](https://github.com/fbenkaci/ft_transcendence/blob/main/backend/api/jwt_middleware.py): `backend/api/jwt_middleware.py`
- [Metrics endpoint](https://github.com/fbenkaci/ft_transcendence/blob/main/backend/api/metrics.py): `backend/api/metrics.py`

### Tournament play

- [Tournament pages](https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/tournaments/page.tsx): `frontend/app/tournaments/page.tsx`
- [Tournament match view](https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/tournaments/%5Bid%5D/page.tsx): `frontend/app/tournaments/[id]/page.tsx`
- [Match canvas](https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/tournaments/%5Bid%5D/TournamentMatchCanvas.tsx): `frontend/app/tournaments/[id]/TournamentMatchCanvas.tsx`
- [Bracket progression](https://github.com/fbenkaci/ft_transcendence/blob/main/backend/api/tournament_service.py): `backend/api/tournament_service.py`
- [Blockchain history](https://github.com/fbenkaci/ft_transcendence/blob/main/backend/blockchain/service.py): `backend/blockchain/service.py`

### Accounts and social

- [Account and auth UI](https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/account/page.tsx): `frontend/app/account/page.tsx`
- [Friends UI](https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/friends/page.tsx): `frontend/app/friends/page.tsx`
- [Chat UI](https://github.com/fbenkaci/ft_transcendence/blob/main/frontend/app/chat/page.tsx): `frontend/app/chat/page.tsx`

### Other components

- **Player**

## Connections

- Player → Mode selection: chooses mode
- Player → Local 1v1 loop: plays locally (evidence: `frontend/app/1vs1/useGameLoop.ts`)
- Local 1v1 loop → 1v1 canvas: updates view
- Player → AI game loop: plays versus AI
- AI game loop → AI canvas: updates view (evidence: `frontend/app/ia_vs/page.tsx`)
- Player → Online game client: joins match
- Online game client → Pong WebSocket: sends game actions (evidence: `frontend/app/online/useOnlineGame.ts`)
- Online game client → Online canvas: renders state
- WebSocket routes → Pong WebSocket: routes Pong (evidence: `backend/api/routing.py`)
- WebSocket routes → Chat WebSocket: routes chat (evidence: `backend/api/routing.py`)
- Pong WebSocket → Domain records: records match results (evidence: `backend/api/consumers.py`)
- Player → REST API: uses account services
- REST API → Domain records: reads and writes (evidence: `backend/api/views.py`)
- REST API → API serializers: serializes data (evidence: `backend/api/views.py`)
- Account and auth UI → REST API: requests profile and auth
- Friends UI → REST API: manages friendships
- Chat UI → Chat WebSocket: connects to chat
- REST API → JWT authentication: uses JWT protection
- Player → Tournament pages: enters tournament
- Tournament pages → REST API: manages tournament
- Tournament match view → Match canvas: renders match (evidence: `frontend/app/tournaments/[id]/page.tsx`)
- Match canvas → Online game client: uses online game (evidence: `frontend/app/tournaments/[id]/TournamentMatchCanvas.tsx`)
- REST API → Bracket progression: starts bracket (evidence: `backend/api/views.py`)
- Bracket progression → Domain records: creates rounds (evidence: `backend/api/tournament_service.py`)
- REST API → Blockchain history: stores tournament (evidence: `backend/api/views.py`)
- Bracket progression → Blockchain history: stores match result (evidence: `backend/api/tournament_service.py`)
- REST API → Metrics endpoint: exposes metrics (evidence: `backend/backend/urls.py`)
