How amdouyah/ft_transcendence works
Project type and purpose
• This is a full-stack, Docker-based web application (“ft_transcendence”) that allows users to register/login, chat, invite friends, enable 2FA, and play a real-time ping-pong game.
• It uses NGINX as a frontend server and reverse proxy, a Django/Django REST Framework backend (with Django Channels for WebSockets), and PostgreSQL for persistent storage.
File structure
• Top-level:
• frontend/ – Static assets (HTML, CSS, vanilla JS components) and NGINX config.
• backend/ – Dockerfile, a “project” directory that houses a Django project with modular apps:
– authentication (JWT, 2FA, profile, friend/block logic)
– chat (WebSocket consumers, REST endpoints)
– game (core ping-pong game logic)
– remote (real-time game rooms via Channels)
– tournament (tournament logic over WebSockets)
• docker-compose.yaml – Orchestrates three containers (NGINX, Django backend, PostgreSQL).
• .env.test, Makefile – Environment and helper scripts.
README for additional insights
• Confirms a three-container architecture (NGINX, Django REST + Channels, PostgreSQL).
• Frontend is vanilla JS served by NGINX on port 81 (HTTPS).
• Backend provides REST API endpoints secured by JWT and Channels endpoints for real-time messaging.
• Database stores users, game history, chat transcripts, friend requests, tournament data, etc.
• External integrations: 42-intra OAuth registration, TOTP 2FA.
a. Main components
• Client (Browser UI)
• NGINX container
• Django Backend container (REST + Channels) with subcomponents:
– Authentication Service (JWT, 2FA, user profiles, friend/block logic)
– REST API Layer (Django REST Framework)
– WebSocket Layer (Django Channels consumers: chat, game, remote, tournament)
– Static/media file handling (user avatars, game assets)
• PostgreSQL container
• (Optional) External OAuth Provider (42-intra)
b. Relationships & interactions
1. Browser → HTTPS → NGINX
– Serves static frontend files (HTML/CSS/JS).
– Proxies API calls (/api/*) to Django REST.
– Proxies WebSocket endpoints (/ws/chat/, /ws/remote/, /ws/tournament/) to Django Channels.
2. Django REST endpoints ↔ PostgreSQL
– CRUD on users, profiles, friend requests, tournaments.
3. Django Channels ↔ PostgreSQL
– Persist chat messages, game invitations, real-time state updates.
4. Django Authentication ↔ External OAuth (42-intra)
– User registration/login handshake.
5. Browser ↔ WebSockets
– Real-time chat and game data flows.
c. Architectural patterns & design principles
• Layered architecture: presentation (frontend), application/API (REST), real-time (WebSocket), data (PostgreSQL).
• Modular monolith backend: separate Django apps for authentication, chat, game, remote, tournament.
• Security best practices: JWT for stateless auth, 2FA TOTP, HTTPS.
• Containerization: each major component in its own Docker container.
d. Key technologies & libraries
• NGINX (static serving + reverse proxy)
• Django, Django REST Framework
• Django Channels (WebSocket routing and consumers)
• PostgreSQL
• Docker, Docker Compose
• Vanilla JavaScript frontend
• JWT (djangorestframework-simplejwt)
• TOTP 2FA libraries (e.g., PyOTP)