# alikhaled17/guess-who-game architecture

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

- Interactive diagram: https://gitdiagram.com/alikhaled17/guess-who-game
- Repository: https://github.com/alikhaled17/guess-who-game

## Overview

Guess Who is a two-device, peer-to-peer character-guessing game delivered as a web PWA. A host starts a game and shares its invite link; a guest joins, then both browsers use WebSocket signaling only to establish a direct WebRTC connection. The session hook connects the UI to the pure game engine and peer network; gameplay messages travel over the DataChannel, while questions and answers are spoken aloud. The Worker routes signaling sockets to room Durable Objects. The graph reflects documented responsibilities and sampled imports; some client networking details are documented but their implementation excerpts were not shown.

Main entry points: [`web/src/hooks/useGameSession.ts`](https://github.com/alikhaled17/guess-who-game/blob/master/web/src/hooks/useGameSession.ts) (Session hook), [`web/src/networking/connection/connectionManager.ts`](https://github.com/alikhaled17/guess-who-game/blob/master/web/src/networking/connection/connectionManager.ts) (Connection manager), [`web/src/app/game/[gameId]/GameClientPage.tsx`](https://github.com/alikhaled17/guess-who-game/blob/master/web/src/app/game/%5BgameId%5D/GameClientPage.tsx) (Game page), [`web/src/game/engine/engine.ts`](https://github.com/alikhaled17/guess-who-game/blob/master/web/src/game/engine/engine.ts) (Game engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Player experience"]
  node_home["Home and invites<br/>[page.tsx]"]
  node_join["Join flow<br/>[JoinClientPage.tsx]"]
  node_game_page["Game page<br/>[GameClientPage.tsx]"]
  node_game_screens["Game screens"]
  node_translations["Translations<br/>[translations.ts]"]
end

subgraph group_gameplay["Game rules and content"]
  node_session["Session hook<br/>[useGameSession.ts]"]
  node_engine["Game engine<br/>[engine.ts]"]
  node_rules["Rules and validation"]
  node_game_state["Initial game state<br/>[initialState.ts]"]
  node_actions["Local actions<br/>[actions.ts]"]
  node_game_types["Game types<br/>[index.ts]"]
  node_characters["Character roster<br/>[characters.ts]"]
  node_question_content["Questions and difficulty<br/>[questions.ts]"]
end

subgraph group_peer_network["Peer networking"]
  node_connection_manager["Connection manager"]
  node_signaling_client["Signaling client<br/>[signalingClient.ts]"]
  node_peer_connection["WebRTC peer<br/>[peerConnection.ts]"]
  node_protocol_messages["Gameplay messages<br/>[messages.ts]"]
  node_protocol_envelope["Message envelope<br/>[envelope.ts]"]
  node_protocol_validation["Protocol validation<br/>[validate.ts]"]
end

subgraph group_signaling["Signaling service"]
  node_worker["Room router<br/>[worker.ts]"]
  node_durable_room["Signaling room<br/>[signalingRoom.ts]"]
  node_signaling_types["Signaling types<br/>[types.ts]"]
end

subgraph group_legacy["Legacy signaling"]
  node_legacy_server["Legacy WebSocket server<br/>[server.js]"]
  node_legacy_rooms["Legacy room registry<br/>[rooms.js]"]
end

node_player(("Players"))

node_player -->|"starts game"| node_home
node_player -->|"opens invite"| node_join
node_home -->|"enters host game"| node_game_page
node_join -->|"navigates to"| node_game_page
node_game_page -->|"starts session"| node_session
node_game_page -->|"renders"| node_game_screens
node_game_screens -->|"dispatches actions"| node_session
node_session -->|"uses game logic"| node_engine
node_session -->|"coordinates networking"| node_connection_manager
node_engine -.->|"applies rules"| node_rules
node_engine -.->|"initializes state"| node_game_state
node_session -->|"accepts local actions"| node_actions
node_characters -.->|"supplies game content"| node_engine
node_connection_manager -->|"uses signaling"| node_signaling_client
node_connection_manager -->|"establishes peer link"| node_peer_connection
node_connection_manager -->|"exchanges gameplay events"| node_protocol_messages
node_protocol_validation -->|"validates messages"| node_protocol_messages
node_protocol_validation -->|"validates envelope"| node_protocol_envelope
node_signaling_client -->|"opens signaling socket"| node_worker
node_worker -->|"routes room request"| node_durable_room
node_worker -->|"validates game id"| node_signaling_types
node_durable_room -->|"parses client messages"| node_signaling_types
node_legacy_server -->|"manages room slots"| node_legacy_rooms

click node_home "https://github.com/alikhaled17/guess-who-game/blob/master/web/src/app/page.tsx"
click node_join "https://github.com/alikhaled17/guess-who-game/blob/master/web/src/app/join/%5BgameId%5D/JoinClientPage.tsx"
click node_game_page "https://github.com/alikhaled17/guess-who-game/blob/master/web/src/app/game/%5BgameId%5D/GameClientPage.tsx"
click node_game_screens "https://github.com/alikhaled17/guess-who-game/tree/master/web/src/components/screens"
click node_session "https://github.com/alikhaled17/guess-who-game/blob/master/web/src/hooks/useGameSession.ts"
click node_engine "https://github.com/alikhaled17/guess-who-game/blob/master/web/src/game/engine/engine.ts"
click node_rules "https://github.com/alikhaled17/guess-who-game/tree/master/web/src/game/rules"
click node_game_state "https://github.com/alikhaled17/guess-who-game/blob/master/web/src/game/state/initialState.ts"
click node_actions "https://github.com/alikhaled17/guess-who-game/blob/master/web/src/game/events/actions.ts"
click node_game_types "https://github.com/alikhaled17/guess-who-game/blob/master/web/src/game/types/index.ts"
click node_characters "https://github.com/alikhaled17/guess-who-game/blob/master/web/src/data/characters.ts"
click node_question_content "https://github.com/alikhaled17/guess-who-game/blob/master/web/src/data/questions.ts"
click node_translations "https://github.com/alikhaled17/guess-who-game/blob/master/web/src/lib/i18n/translations.ts"
click node_connection_manager "https://github.com/alikhaled17/guess-who-game/blob/master/web/src/networking/connection/connectionManager.ts"
click node_signaling_client "https://github.com/alikhaled17/guess-who-game/blob/master/web/src/networking/signaling/signalingClient.ts"
click node_peer_connection "https://github.com/alikhaled17/guess-who-game/blob/master/web/src/networking/webrtc/peerConnection.ts"
click node_protocol_messages "https://github.com/alikhaled17/guess-who-game/blob/master/web/src/networking/protocol/messages.ts"
click node_protocol_envelope "https://github.com/alikhaled17/guess-who-game/blob/master/web/src/networking/protocol/envelope.ts"
click node_protocol_validation "https://github.com/alikhaled17/guess-who-game/blob/master/web/src/networking/protocol/validate.ts"
click node_worker "https://github.com/alikhaled17/guess-who-game/blob/master/signaling-server/src/worker.ts"
click node_durable_room "https://github.com/alikhaled17/guess-who-game/blob/master/signaling-server/src/signalingRoom.ts"
click node_signaling_types "https://github.com/alikhaled17/guess-who-game/blob/master/signaling-server/src/types.ts"
click node_legacy_server "https://github.com/alikhaled17/guess-who-game/blob/master/signaling-server/legacy-node-server/src/server.js"
click node_legacy_rooms "https://github.com/alikhaled17/guess-who-game/blob/master/signaling-server/legacy-node-server/src/rooms.js"

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_home,node_join,node_game_page,node_game_screens,node_translations toneBlue
class node_session,node_engine,node_rules,node_game_state,node_actions,node_game_types,node_characters,node_question_content toneAmber
class node_connection_manager,node_signaling_client,node_peer_connection,node_protocol_messages,node_protocol_envelope,node_protocol_validation toneMint
class node_worker,node_durable_room,node_signaling_types toneRose
class node_legacy_server,node_legacy_rooms,node_player toneIndigo
```

## Components

### Player experience

- [Home and invites](https://github.com/alikhaled17/guess-who-game/blob/master/web/src/app/page.tsx): `web/src/app/page.tsx`
- [Join flow](https://github.com/alikhaled17/guess-who-game/blob/master/web/src/app/join/%5BgameId%5D/JoinClientPage.tsx): `web/src/app/join/[gameId]/JoinClientPage.tsx`
- [Game page](https://github.com/alikhaled17/guess-who-game/blob/master/web/src/app/game/%5BgameId%5D/GameClientPage.tsx): `web/src/app/game/[gameId]/GameClientPage.tsx`
- [Game screens](https://github.com/alikhaled17/guess-who-game/tree/master/web/src/components/screens): `web/src/components/screens`
- [Translations](https://github.com/alikhaled17/guess-who-game/blob/master/web/src/lib/i18n/translations.ts): `web/src/lib/i18n/translations.ts`

### Game rules and content

- [Session hook](https://github.com/alikhaled17/guess-who-game/blob/master/web/src/hooks/useGameSession.ts): `web/src/hooks/useGameSession.ts`
- [Game engine](https://github.com/alikhaled17/guess-who-game/blob/master/web/src/game/engine/engine.ts): `web/src/game/engine/engine.ts`
- [Rules and validation](https://github.com/alikhaled17/guess-who-game/tree/master/web/src/game/rules): `web/src/game/rules`
- [Initial game state](https://github.com/alikhaled17/guess-who-game/blob/master/web/src/game/state/initialState.ts): `web/src/game/state/initialState.ts`
- [Local actions](https://github.com/alikhaled17/guess-who-game/blob/master/web/src/game/events/actions.ts): `web/src/game/events/actions.ts`
- [Game types](https://github.com/alikhaled17/guess-who-game/blob/master/web/src/game/types/index.ts): `web/src/game/types/index.ts`
- [Character roster](https://github.com/alikhaled17/guess-who-game/blob/master/web/src/data/characters.ts): `web/src/data/characters.ts`
- [Questions and difficulty](https://github.com/alikhaled17/guess-who-game/blob/master/web/src/data/questions.ts): `web/src/data/questions.ts`

### Peer networking

- [Connection manager](https://github.com/alikhaled17/guess-who-game/blob/master/web/src/networking/connection/connectionManager.ts): `web/src/networking/connection/connectionManager.ts`
- [Signaling client](https://github.com/alikhaled17/guess-who-game/blob/master/web/src/networking/signaling/signalingClient.ts): `web/src/networking/signaling/signalingClient.ts`
- [WebRTC peer](https://github.com/alikhaled17/guess-who-game/blob/master/web/src/networking/webrtc/peerConnection.ts): `web/src/networking/webrtc/peerConnection.ts`
- [Gameplay messages](https://github.com/alikhaled17/guess-who-game/blob/master/web/src/networking/protocol/messages.ts): `web/src/networking/protocol/messages.ts`
- [Message envelope](https://github.com/alikhaled17/guess-who-game/blob/master/web/src/networking/protocol/envelope.ts): `web/src/networking/protocol/envelope.ts`
- [Protocol validation](https://github.com/alikhaled17/guess-who-game/blob/master/web/src/networking/protocol/validate.ts): `web/src/networking/protocol/validate.ts`

### Signaling service

- [Room router](https://github.com/alikhaled17/guess-who-game/blob/master/signaling-server/src/worker.ts): `signaling-server/src/worker.ts`
- [Signaling room](https://github.com/alikhaled17/guess-who-game/blob/master/signaling-server/src/signalingRoom.ts): `signaling-server/src/signalingRoom.ts`
- [Signaling types](https://github.com/alikhaled17/guess-who-game/blob/master/signaling-server/src/types.ts): `signaling-server/src/types.ts`

### Legacy signaling

- [Legacy WebSocket server](https://github.com/alikhaled17/guess-who-game/blob/master/signaling-server/legacy-node-server/src/server.js): `signaling-server/legacy-node-server/src/server.js`
- [Legacy room registry](https://github.com/alikhaled17/guess-who-game/blob/master/signaling-server/legacy-node-server/src/rooms.js): `signaling-server/legacy-node-server/src/rooms.js`

### Other components

- **Players**

## Connections

- Players → Home and invites: starts game
- Players → Join flow: opens invite
- Home and invites → Game page: enters host game
- Join flow → Game page: navigates to (evidence: `web/src/app/join/[gameId]/JoinClientPage.tsx`)
- Game page → Session hook: starts session (evidence: `web/src/app/game/[gameId]/GameClientPage.tsx`)
- Game page → Game screens: renders (evidence: `web/src/app/game/[gameId]/GameClientPage.tsx`)
- Game screens → Session hook: dispatches actions
- Session hook → Game engine: uses game logic
- Session hook → Connection manager: coordinates networking
- Game engine → Rules and validation: applies rules
- Game engine → Initial game state: initializes state
- Session hook → Local actions: accepts local actions
- Character roster → Game engine: supplies game content
- Connection manager → Signaling client: uses signaling
- Connection manager → WebRTC peer: establishes peer link
- Connection manager → Gameplay messages: exchanges gameplay events
- Protocol validation → Gameplay messages: validates messages (evidence: `web/src/networking/protocol/validate.ts`)
- Protocol validation → Message envelope: validates envelope (evidence: `web/src/networking/protocol/validate.ts`)
- Signaling client → Room router: opens signaling socket (evidence: `web/src/networking/signaling/signalingClient.ts`)
- Room router → Signaling room: routes room request (evidence: `signaling-server/src/worker.ts`)
- Room router → Signaling types: validates game id (evidence: `signaling-server/src/worker.ts`)
- Signaling room → Signaling types: parses client messages (evidence: `signaling-server/src/signalingRoom.ts`)
- Legacy WebSocket server → Legacy room registry: manages room slots (evidence: `signaling-server/legacy-node-server/src/server.js`)
