# xingjianwang001/coup_online architecture

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

- Interactive diagram: https://gitdiagram.com/xingjianwang001/coup_online
- Repository: https://github.com/xingjianwang001/coup_online

## Overview

Coup Online is a browser-based multiplayer Coup game. Players create or join a room, then send intents over Socket.IO; the server manages room membership and online-play concerns, while the pure engine validates and advances the authoritative game. Public state, private hands, and events return to each browser, where the client maintains session state and renders the table, rules, and localized narration. The README also documents computer players and temporary Cloudflare invite tunnels. Some client and server wiring is unsampled, so the graph omits uncertain links rather than inferring them.

Main entry points: [`packages/client/src/App.tsx`](https://github.com/xingjianwang001/coup_online/blob/dev/packages/client/src/App.tsx) (Game interface), [`packages/server/src/index.ts`](https://github.com/xingjianwang001/coup_online/blob/dev/packages/server/src/index.ts) (Socket server), [`packages/server/src/room.ts`](https://github.com/xingjianwang001/coup_online/blob/dev/packages/server/src/room.ts) (Room lifecycle), [`packages/client/src/socket.ts`](https://github.com/xingjianwang001/coup_online/blob/dev/packages/client/src/socket.ts) (Socket client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser client"]
  node_app["Game interface<br/>[App.tsx]"]
  node_socket["Socket client<br/>[socket.ts]"]
  node_session["Session state<br/>[session.ts]"]
  node_rules["Rules display<br/>[rules.ts]"]
  node_localization["Localization<br/>[localization.ts]"]
  node_narration["Game narration<br/>[narration.ts]"]
  node_clipboard["Invite copying<br/>[clipboard.ts]"]
  node_motion["Table animations<br/>[motion.ts]"]
  node_seating["Seat layout<br/>[seating.ts]"]
end

subgraph group_server["Room server"]
  node_server["Socket server<br/>[index.ts]"]
  node_room["Room lifecycle<br/>[room.ts]"]
  node_repository[("Game repository<br/>[repository.ts]")]
  node_computer["Computer players<br/>[computer.ts]"]
  node_limits["Room limits<br/>[room-limits.ts]"]
  node_errors["Client errors<br/>[errors.ts]"]
  node_tunnel["Invite tunnel<br/>[tunnel.ts]"]
end

subgraph group_engine["Game domain"]
  node_engine["Game rules engine<br/>[game.ts]"]
  node_types["Game state types<br/>[types.ts]"]
end

subgraph group_shared["Shared contract"]
  node_protocol["Intent and message protocol<br/>[protocol.ts]"]
end

node_player(("Player"))
node_cloudflare{{"Cloudflare Tunnel"}}

node_player -->|"plays through"| node_app
node_app -->|"sends intents"| node_socket
node_app -->|"rejoins with"| node_session
node_app -->|"renders rules"| node_rules
node_app -->|"uses narration"| node_narration
node_app -->|"uses copying"| node_clipboard
node_app -->|"uses animations"| node_motion
node_app -->|"uses seat layout"| node_seating
node_app -->|"renders localized text"| node_localization
node_narration -->|"translates events"| node_localization
node_narration -->|"names actions"| node_rules
node_socket -->|"connects by Socket.IO"| node_server
node_server -->|"routes intents"| node_room
node_server -->|"creates repository"| node_repository
node_server -->|"starts tunnel"| node_tunnel
node_server -->|"checks limits"| node_limits
node_server -->|"converts errors"| node_errors
node_room -->|"applies game actions"| node_engine
node_room -->|"saves game state"| node_repository
node_room -->|"delegates decisions"| node_computer
node_tunnel -.->|"starts Quick Tunnel"| node_cloudflare
node_engine -->|"uses state types"| node_types
node_session -->|"reduces server messages"| node_protocol
node_socket -->|"uses shared protocol"| node_protocol

click node_app "https://github.com/xingjianwang001/coup_online/blob/dev/packages/client/src/App.tsx"
click node_socket "https://github.com/xingjianwang001/coup_online/blob/dev/packages/client/src/socket.ts"
click node_session "https://github.com/xingjianwang001/coup_online/blob/dev/packages/client/src/session.ts"
click node_rules "https://github.com/xingjianwang001/coup_online/blob/dev/packages/client/src/rules.ts"
click node_localization "https://github.com/xingjianwang001/coup_online/blob/dev/packages/client/src/localization.ts"
click node_narration "https://github.com/xingjianwang001/coup_online/blob/dev/packages/client/src/narration.ts"
click node_clipboard "https://github.com/xingjianwang001/coup_online/blob/dev/packages/client/src/clipboard.ts"
click node_motion "https://github.com/xingjianwang001/coup_online/blob/dev/packages/client/src/motion.ts"
click node_seating "https://github.com/xingjianwang001/coup_online/blob/dev/packages/client/src/seating.ts"
click node_server "https://github.com/xingjianwang001/coup_online/blob/dev/packages/server/src/index.ts"
click node_room "https://github.com/xingjianwang001/coup_online/blob/dev/packages/server/src/room.ts"
click node_repository "https://github.com/xingjianwang001/coup_online/blob/dev/packages/server/src/repository.ts"
click node_computer "https://github.com/xingjianwang001/coup_online/blob/dev/packages/server/src/computer.ts"
click node_limits "https://github.com/xingjianwang001/coup_online/blob/dev/packages/server/src/room-limits.ts"
click node_errors "https://github.com/xingjianwang001/coup_online/blob/dev/packages/server/src/errors.ts"
click node_tunnel "https://github.com/xingjianwang001/coup_online/blob/dev/packages/server/src/tunnel.ts"
click node_engine "https://github.com/xingjianwang001/coup_online/blob/dev/packages/engine/src/game.ts"
click node_types "https://github.com/xingjianwang001/coup_online/blob/dev/packages/engine/src/types.ts"
click node_protocol "https://github.com/xingjianwang001/coup_online/blob/dev/packages/shared/src/protocol.ts"

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_app,node_socket,node_session,node_rules,node_localization,node_narration,node_clipboard,node_motion,node_seating toneBlue
class node_server,node_room,node_repository,node_computer,node_limits,node_errors,node_tunnel toneAmber
class node_engine,node_types toneMint
class node_protocol toneRose
class node_player,node_cloudflare toneIndigo
```

## Components

### Browser client

- [Game interface](https://github.com/xingjianwang001/coup_online/blob/dev/packages/client/src/App.tsx): `packages/client/src/App.tsx`
- [Socket client](https://github.com/xingjianwang001/coup_online/blob/dev/packages/client/src/socket.ts): `packages/client/src/socket.ts`
- [Session state](https://github.com/xingjianwang001/coup_online/blob/dev/packages/client/src/session.ts): `packages/client/src/session.ts`
- [Rules display](https://github.com/xingjianwang001/coup_online/blob/dev/packages/client/src/rules.ts): `packages/client/src/rules.ts`
- [Localization](https://github.com/xingjianwang001/coup_online/blob/dev/packages/client/src/localization.ts): `packages/client/src/localization.ts`
- [Game narration](https://github.com/xingjianwang001/coup_online/blob/dev/packages/client/src/narration.ts): `packages/client/src/narration.ts`
- [Invite copying](https://github.com/xingjianwang001/coup_online/blob/dev/packages/client/src/clipboard.ts): `packages/client/src/clipboard.ts`
- [Table animations](https://github.com/xingjianwang001/coup_online/blob/dev/packages/client/src/motion.ts): `packages/client/src/motion.ts`
- [Seat layout](https://github.com/xingjianwang001/coup_online/blob/dev/packages/client/src/seating.ts): `packages/client/src/seating.ts`

### Room server

- [Socket server](https://github.com/xingjianwang001/coup_online/blob/dev/packages/server/src/index.ts): `packages/server/src/index.ts`
- [Room lifecycle](https://github.com/xingjianwang001/coup_online/blob/dev/packages/server/src/room.ts): `packages/server/src/room.ts`
- [Game repository](https://github.com/xingjianwang001/coup_online/blob/dev/packages/server/src/repository.ts): `packages/server/src/repository.ts`
- [Computer players](https://github.com/xingjianwang001/coup_online/blob/dev/packages/server/src/computer.ts): `packages/server/src/computer.ts`
- [Room limits](https://github.com/xingjianwang001/coup_online/blob/dev/packages/server/src/room-limits.ts): `packages/server/src/room-limits.ts`
- [Client errors](https://github.com/xingjianwang001/coup_online/blob/dev/packages/server/src/errors.ts): `packages/server/src/errors.ts`
- [Invite tunnel](https://github.com/xingjianwang001/coup_online/blob/dev/packages/server/src/tunnel.ts): `packages/server/src/tunnel.ts`

### Game domain

- [Game rules engine](https://github.com/xingjianwang001/coup_online/blob/dev/packages/engine/src/game.ts): `packages/engine/src/game.ts`
- [Game state types](https://github.com/xingjianwang001/coup_online/blob/dev/packages/engine/src/types.ts): `packages/engine/src/types.ts`

### Shared contract

- [Intent and message protocol](https://github.com/xingjianwang001/coup_online/blob/dev/packages/shared/src/protocol.ts): `packages/shared/src/protocol.ts`

### Other components

- **Player**
- **Cloudflare Tunnel**

## Connections

- Player → Game interface: plays through (evidence: `README.md`)
- Game interface → Socket client: sends intents (evidence: `packages/client/src/App.tsx`)
- Game interface → Session state: rejoins with (evidence: `packages/client/src/App.tsx`)
- Game interface → Rules display: renders rules (evidence: `packages/client/src/App.tsx`)
- Game interface → Game narration: uses narration (evidence: `packages/client/src/App.tsx`)
- Game interface → Invite copying: uses copying (evidence: `packages/client/src/App.tsx`)
- Game interface → Table animations: uses animations (evidence: `packages/client/src/App.tsx`)
- Game interface → Seat layout: uses seat layout (evidence: `packages/client/src/App.tsx`)
- Game interface → Localization: renders localized text (evidence: `packages/client/src/App.tsx`)
- Game narration → Localization: translates events (evidence: `packages/client/src/narration.ts`)
- Game narration → Rules display: names actions (evidence: `packages/client/src/narration.ts`)
- Socket client → Socket server: connects by Socket.IO (evidence: `README.md`)
- Socket server → Room lifecycle: routes intents (evidence: `packages/server/src/index.ts`)
- Socket server → Game repository: creates repository (evidence: `packages/server/src/index.ts`)
- Socket server → Invite tunnel: starts tunnel (evidence: `packages/server/src/index.ts`)
- Socket server → Room limits: checks limits (evidence: `packages/server/src/index.ts`)
- Socket server → Client errors: converts errors (evidence: `packages/server/src/index.ts`)
- Room lifecycle → Game rules engine: applies game actions (evidence: `packages/server/src/room.ts`)
- Room lifecycle → Game repository: saves game state (evidence: `packages/server/src/room.ts`)
- Room lifecycle → Computer players: delegates decisions (evidence: `packages/server/src/room.ts`)
- Invite tunnel → Cloudflare Tunnel: starts Quick Tunnel (evidence: `README.md`)
- Game rules engine → Game state types: uses state types (evidence: `packages/engine/src/game.ts`)
- Session state → Intent and message protocol: reduces server messages (evidence: `packages/client/src/session.ts`)
- Socket client → Intent and message protocol: uses shared protocol (evidence: `packages/client/src/socket.ts`)
