How accxlr8/chainreaction-backend works
Chain Reaction is a FastAPI backend for two-player games. Clients authenticate and create or join games over HTTP or connect to a game WebSocket; matchmaking is a separate entry path. The game service validates moves, advances the authoritative engine, updates clocks and persists moves/events; the WebSocket route then broadcasts accepted moves and refreshed snapshots. The README documents replay storage and other integrations, but the sampled sources do not establish which runtime components invoke replay storage, so that relationship is left unconnected. Edges reflect excerpts, indexed references, or README statements.
Main entry points: routes.py WebSocket routes · main.py FastAPI app · service.py Game orchestration · router.py HTTP router
Components 29
API and identity
- HTTP router
app/api/router.py - Game endpoints
app/api/games.py - User endpoints
app/api/users.py - Health endpoint
app/api/health.py - Matchmaking endpoint
app/api/matchmaking.py - HTTP auth
app/auth/dependencies.py - JWT authentication
app/auth/service.py
Game runtime
- WebSocket routes
app/websocket/routes.py - Connection manager
app/websocket/manager.py - Connection state
app/websocket/connection.py - Message protocol
app/websocket/protocol.py - Game orchestration
app/games/service.py - Game clocks
app/games/clock.py - Engine adapter
app/engine/adapter.py - Matchmaking service
app/matchmaking/service.py - Queue operations
app/matchmaking/queue.py
State and integrations
- Data repositories
app/database/repositories.py - Game data models
app/database/models.py - Postgres
- Database sessions
app/database/session.py - Redis client
app/redis/client.py - Redis
- Redis keys
app/redis/keys.py - Replay storage
app/storage/service.py
Application platform
- FastAPI app
app/main.py - Settings
app/config/settings.py
Other components
- Game clients
- Chain Reaction engine
- Azure Blob Storage
Connections 41
- Game clients → FastAPI app: sends HTTP
- Game clients → WebSocket routes: opens game socket
- FastAPI app → HTTP router: mounts
app/main.py - FastAPI app → WebSocket routes: mounts
app/main.py - FastAPI app → Database sessions: connects
app/main.py - FastAPI app → Redis client: connects
app/main.py - FastAPI app → Settings: loads
app/main.py - HTTP router → Game endpoints: routes to
app/api/router.py - HTTP router → User endpoints: routes to
app/api/router.py - HTTP router → Health endpoint: routes to
app/api/router.py - HTTP router → Matchmaking endpoint: routes to
app/api/router.py - Game endpoints → HTTP auth: authenticates with
app/api/games.py - User endpoints → HTTP auth: authenticates with
app/api/users.py - Matchmaking endpoint → HTTP auth: authenticates with
app/api/matchmaking.py - HTTP auth → JWT authentication: validates token
app/auth/dependencies.py - JWT authentication → Settings: reads secret
app/auth/service.py - Game endpoints → Game orchestration: delegates game actions
app/api/games.py - Game endpoints → Data repositories: queries data
app/api/games.py - Game endpoints → Database sessions: uses sessions
app/api/games.py - Matchmaking endpoint → Matchmaking service: delegates matching
app/api/matchmaking.py - Health endpoint → Database sessions: checks database
app/api/health.py - Health endpoint → Redis client: checks Redis
app/api/health.py - WebSocket routes → JWT authentication: authenticates token
app/websocket/routes.py - WebSocket routes → Game orchestration: submits moves
app/websocket/routes.py - WebSocket routes → Data repositories: loads snapshots
app/websocket/routes.py - WebSocket routes → Database sessions: opens sessions
app/websocket/routes.py - WebSocket routes → Connection manager: broadcasts messages
app/websocket/routes.py - WebSocket routes → Message protocol: parses messages
app/websocket/routes.py - Connection manager → Connection state: manages connections
app/websocket/manager.py - Game orchestration → Data repositories: reads and writes
app/games/service.py - Game orchestration → Engine adapter: applies moves
app/games/service.py - Game orchestration → Game clocks: advances clocks
app/games/service.py - Game orchestration → Settings: reads configuration
app/games/service.py - Engine adapter → Chain Reaction engine: invokes engine
- Data repositories → Game data models: queries models
app/database/repositories.py - Database sessions → Postgres: persists through
- Matchmaking service → Queue operations: uses queue
app/matchmaking/service.py - Matchmaking service → Redis client: uses Redis
app/matchmaking/service.py - Queue operations → Redis keys: uses keys
app/matchmaking/queue.py - Redis client → Redis: connects to
app/redis/client.py - Replay storage → Azure Blob Storage: stores replays