# hullqin/poker architecture

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

- Interactive diagram: https://gitdiagram.com/hullqin/poker
- Repository: https://github.com/hullqin/poker

## Overview

This is a small, in-memory backend for multiplayer Dou Dizhu. Players connect through the React client, join or create a room, and then play through WebSocket messages; room and game state is kept in process memory, with no database. The graph separates connection handling, room/presence management, and game phases. The README documents spectators, reconnects, and three- or four-player modes; some room and game implementation is omitted from the excerpts, so uncertain links are left out or marked unverified.

Main entry points: [`server.py`](https://github.com/hullqin/poker/blob/main/server.py) (WebSocket session), [`room.py`](https://github.com/hullqin/poker/blob/main/room.py) (Room lifecycle), [`error.py`](https://github.com/hullqin/poker/blob/main/error.py) (Disconnect errors)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_connections["Connections"]
  node_server["ASGI server<br/>[server.py]"]
  node_http_assets["HTTP asset serving<br/>[server.py]"]
  node_websocket_session["WebSocket session<br/>[server.py]"]
  node_disconnect_errors["Disconnect errors<br/>[error.py]"]
end

subgraph group_rooms["Rooms and presence"]
  node_room_registry["Room registry<br/>[server.py]"]
  node_room_lifecycle["Room lifecycle<br/>[room.py]"]
  node_seats_visitors["Seats and visitors<br/>[room.py]"]
  node_presence_recovery["Presence and recovery<br/>[room.py]"]
end

subgraph group_gameplay["Game play"]
  node_game_setup["Game setup and deal<br/>[room.py]"]
  node_landlord_phase["Landlord selection<br/>[room.py]"]
  node_card_play["Card play and undo<br/>[room.py]"]
  node_game_state_broadcast["Game state broadcast<br/>[room.py]"]
end

node_players(("Players"))
node_react_client["React client"]

node_players -->|"use"| node_react_client
node_react_client -->|"send messages"| node_websocket_session
node_react_client -->|"request assets"| node_http_assets
node_server -->|"routes HTTP"| node_http_assets
node_server -->|"routes WebSocket"| node_websocket_session
node_websocket_session -->|"raises"| node_disconnect_errors
node_websocket_session -->|"reads and updates"| node_room_registry
node_websocket_session -->|"calls room methods"| node_room_lifecycle
node_room_lifecycle -->|"manages membership"| node_seats_visitors
node_room_lifecycle -->|"tracks online state"| node_presence_recovery
node_websocket_session -->|"starts game"| node_game_setup
node_websocket_session -->|"calls selection"| node_landlord_phase
node_websocket_session -->|"calls play or undo"| node_card_play
node_game_setup -->|"sends game state"| node_game_state_broadcast
node_landlord_phase -->|"sends game state"| node_game_state_broadcast
node_card_play -->|"sends game state"| node_game_state_broadcast
node_room_lifecycle -.->|"creates game"| node_game_setup

click node_server "https://github.com/hullqin/poker/blob/main/server.py"
click node_http_assets "https://github.com/hullqin/poker/blob/main/server.py"
click node_websocket_session "https://github.com/hullqin/poker/blob/main/server.py"
click node_disconnect_errors "https://github.com/hullqin/poker/blob/main/error.py"
click node_room_registry "https://github.com/hullqin/poker/blob/main/server.py"
click node_room_lifecycle "https://github.com/hullqin/poker/blob/main/room.py"
click node_seats_visitors "https://github.com/hullqin/poker/blob/main/room.py"
click node_presence_recovery "https://github.com/hullqin/poker/blob/main/room.py"
click node_game_setup "https://github.com/hullqin/poker/blob/main/room.py"
click node_landlord_phase "https://github.com/hullqin/poker/blob/main/room.py"
click node_card_play "https://github.com/hullqin/poker/blob/main/room.py"
click node_game_state_broadcast "https://github.com/hullqin/poker/blob/main/room.py"

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_server,node_http_assets,node_websocket_session,node_disconnect_errors,node_react_client toneBlue
class node_room_registry,node_room_lifecycle,node_seats_visitors,node_presence_recovery toneAmber
class node_game_setup,node_landlord_phase,node_card_play,node_game_state_broadcast toneMint
class node_players toneIndigo
```

## Components

### Connections

- [ASGI server](https://github.com/hullqin/poker/blob/main/server.py): `server.py`
- [HTTP asset serving](https://github.com/hullqin/poker/blob/main/server.py): `server.py`
- [WebSocket session](https://github.com/hullqin/poker/blob/main/server.py): `server.py`
- [Disconnect errors](https://github.com/hullqin/poker/blob/main/error.py): `error.py`

### Rooms and presence

- [Room registry](https://github.com/hullqin/poker/blob/main/server.py): `server.py`
- [Room lifecycle](https://github.com/hullqin/poker/blob/main/room.py): `room.py`
- [Seats and visitors](https://github.com/hullqin/poker/blob/main/room.py): `room.py`
- [Presence and recovery](https://github.com/hullqin/poker/blob/main/room.py): `room.py`

### Game play

- [Game setup and deal](https://github.com/hullqin/poker/blob/main/room.py): `room.py`
- [Landlord selection](https://github.com/hullqin/poker/blob/main/room.py): `room.py`
- [Card play and undo](https://github.com/hullqin/poker/blob/main/room.py): `room.py`
- [Game state broadcast](https://github.com/hullqin/poker/blob/main/room.py): `room.py`

### Other components

- **Players**
- **React client**

## Connections

- Players → React client: use (evidence: `README.md`)
- React client → WebSocket session: send messages (evidence: `README.md`)
- React client → HTTP asset serving: request assets (evidence: `README.md`)
- ASGI server → HTTP asset serving: routes HTTP (evidence: `server.py`)
- ASGI server → WebSocket session: routes WebSocket (evidence: `server.py`)
- WebSocket session → Disconnect errors: raises (evidence: `server.py`)
- WebSocket session → Room registry: reads and updates (evidence: `server.py`)
- WebSocket session → Room lifecycle: calls room methods (evidence: `server.py`)
- Room lifecycle → Seats and visitors: manages membership (evidence: `room.py`)
- Room lifecycle → Presence and recovery: tracks online state (evidence: `room.py`)
- WebSocket session → Game setup and deal: starts game (evidence: `server.py`)
- WebSocket session → Landlord selection: calls selection (evidence: `server.py`)
- WebSocket session → Card play and undo: calls play or undo (evidence: `server.py`)
- Game setup and deal → Game state broadcast: sends game state (evidence: `room.py`)
- Landlord selection → Game state broadcast: sends game state (evidence: `room.py`)
- Card play and undo → Game state broadcast: sends game state (evidence: `room.py`)
- Room lifecycle → Game setup and deal: creates game (evidence: `room.py`)
