How chinoarror/coup-game works
Coup: Shadow Protocol is an authenticated browser game with a solo human-versus-two-AI match and separate authenticated multiplayer rooms. The principal path runs from the browser entry and login through a game view, turn/rule resolution, AI decisions where applicable, and Worker-backed persistence or room updates. Documented supporting capabilities include room invitations, realtime spectator-safe state, match history, leaderboard, and admin access-code controls. Sampled sources establish key frontend, engine, AI, and room paths; unsampled endpoints are represented only where README/tree evidence supports the subsystem, with uncertain internal wiring omitted.
Main entry points: worker.ts API Worker · index.tsx App entry · App.tsx Solo match · roomGame.ts Room Durable Object
Components 26
Browser experience
- App entry
index.tsx - Login
Login.tsx - Solo match
App.tsx - Room hub
GameHub.tsx - Room lobby
RoomLobby.tsx - Room match
RoomMatch.tsx - Match history
History.tsx - Leaderboard
Leaderboard.tsx - Admin dashboard
AdminPanel.tsx - Rules view
Rules.tsx
Game runtime
- Game engine
utils/gameEngine.ts - AI prompt
services/aiPrompt.ts - Solo AI client
services/geminiService.ts - Rules service
services/rules.ts
Worker services
- API Worker
worker.ts - Room Durable Object
roomGame.ts - Room API client
services/roomClient.ts - Room services
services/rooms.ts - State projection
services/roomState.ts - History service
services/history.ts - AI gateway
services/aiGateway.ts
External services
- Cloudflare D1
schema.sql - Auth Center
- AI relay
- AI providers
Other components
- Player
Connections 34
- Player → App entry: opens
- App entry → Login: shows
- App entry → Solo match: routes
- App entry → Room hub: routes
- App entry → Match history: routes
- App entry → Leaderboard: routes
- App entry → Admin dashboard: routes
- App entry → Rules view: routes
- Solo match → API Worker: loads session
- Solo match → Game engine: applies moves
- Solo match → Solo AI client: requests decisions
- Solo AI client → AI prompt: builds request
- Solo AI client → API Worker: posts decision
- Room hub → Room API client: calls room API
- Room hub → Room lobby: shows lobby
- Room hub → Room match: shows match
- Room API client → API Worker: requests routes
- API Worker → Auth Center: verifies session
- API Worker → Cloudflare D1: reads/writes
- API Worker → Room services: validates rooms
- API Worker → Room Durable Object: dispatches room calls
- Room Durable Object → Game engine: resolves moves
- Room Durable Object → State projection: projects state
- Room Durable Object → AI prompt: builds AI request
- Room Durable Object → AI gateway: requests channel
- API Worker → AI gateway: requests channel
- AI gateway → AI relay: sends signed request
- AI relay → AI providers: forwards request
- Solo match → History service: submits match
- History service → Cloudflare D1: stores records
- Match history → API Worker: loads history
- Leaderboard → API Worker: loads rankings
- Admin dashboard → API Worker: manages access
- Rules view → Rules service: renders rules