# sofie-kirk22/death-mahjong architecture

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

- Interactive diagram: https://gitdiagram.com/sofie-kirk22/death-mahjong
- Repository: https://github.com/sofie-kirk22/death-mahjong

## Overview

Death Mahjong is a multiplayer drinking game: players create or join rooms, take turns drawing drawable tiles, and see sip totals and end-of-game results. The backend API owns room actions, delegates game rules to GameEngine, and publishes room updates through SignalR; the frontend provides lobby, play, profile, and leaderboard views. Persistent entities and statistics are represented in the backend data layer, although the README describes room state as in-memory. API route details and several pages are supported by the README/tree rather than sampled implementation, so uncertain call wiring is omitted.

Main entry points: [`frontend/death-mahjong-client/lib/api.ts`](https://github.com/sofie-kirk22/death-mahjong/blob/master/frontend/death-mahjong-client/lib/api.ts) (REST client), [`backend/DeathMahjong/Program.cs`](https://github.com/sofie-kirk22/death-mahjong/blob/master/backend/DeathMahjong/Program.cs) (HTTP API), [`backend/DeathMahjong/Data/AppDbContext.cs`](https://github.com/sofie-kirk22/death-mahjong/blob/master/backend/DeathMahjong/Data/AppDbContext.cs) (EF data access), [`frontend/death-mahjong-client/app/page.tsx`](https://github.com/sofie-kirk22/death-mahjong/blob/master/frontend/death-mahjong-client/app/page.tsx) (Room entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Player experience"]
  node_home["Room entry<br/>[page.tsx]"]
  node_lobby["Room lobby<br/>[page.tsx]"]
  node_play["Live game view<br/>[page.tsx]"]
  node_endview["Game results<br/>[page.tsx]"]
  node_profile["Player profile<br/>[page.tsx]"]
  node_stats["Leaderboards<br/>[page.tsx]"]
  node_session["Room session<br/>[gameSession.ts]"]
end

subgraph group_runtime["Game runtime"]
  node_api["HTTP API<br/>[Program.cs]"]
  node_engine["Game rules<br/>[GameEngine.cs]"]
  node_room_store[("Room store<br/>[GameRoomStore.cs]")]
  node_room_model["Room state<br/>[GameRoom.cs]"]
end

subgraph group_records["Accounts and records"]
  node_user_session["User session<br/>[userSession.ts]"]
  node_db_context["EF data access<br/>[AppDbContext.cs]"]
  node_entities["Room and game records<br/>[GameRoomEntity.cs]"]
  node_users["User records<br/>[UserEntity.cs]"]
  node_completed["Completed-game records"]
  node_database[("Relational database")]
  node_leaderboard_data["Statistics records"]
end

subgraph group_transport["Realtime transport"]
  node_api_client["REST client<br/>[api.ts]"]
  node_hub["SignalR hub<br/>[GameHub.cs]"]
  node_hub_client["Live connection<br/>[gameHub.ts]"]
end

node_players(("Players"))

node_players -->|"create or join"| node_home
node_home -->|"requests"| node_api_client
node_home -->|"saves identity"| node_session
node_home -->|"saves user"| node_user_session
node_lobby -->|"room actions"| node_api_client
node_play -->|"draw or abort"| node_api_client
node_play -->|"reads player"| node_session
node_profile -->|"loads profile"| node_api_client
node_profile -->|"reads and saves"| node_user_session
node_stats -->|"loads statistics"| node_api_client
node_api_client -->|"HTTP requests"| node_api
node_api -->|"delegates rules"| node_engine
node_api -->|"reads and writes"| node_room_store
node_api -->|"updates state"| node_room_model
node_api -->|"broadcasts events"| node_hub
node_play -->|"subscribes"| node_hub_client
node_hub_client -->|"SignalR connection"| node_hub
node_hub -->|"live updates"| node_play
node_api -->|"persists and queries"| node_db_context
node_db_context -->|"maps records"| node_entities
node_db_context -->|"maps users"| node_users
node_db_context -->|"maps completed games"| node_completed
node_db_context -->|"maps player statistics"| node_leaderboard_data
node_db_context -->|"reads and writes"| node_database
node_endview -->|"loads room results"| node_api_client
node_players -->|"view profile"| node_profile
node_players -->|"view leaderboards"| node_stats

click node_home "https://github.com/sofie-kirk22/death-mahjong/blob/master/frontend/death-mahjong-client/app/page.tsx"
click node_lobby "https://github.com/sofie-kirk22/death-mahjong/blob/master/frontend/death-mahjong-client/app/room/%5BroomId%5D/page.tsx"
click node_play "https://github.com/sofie-kirk22/death-mahjong/blob/master/frontend/death-mahjong-client/app/game/%5BroomId%5D/page.tsx"
click node_endview "https://github.com/sofie-kirk22/death-mahjong/blob/master/frontend/death-mahjong-client/app/game-end/%5BroomId%5D/page.tsx"
click node_profile "https://github.com/sofie-kirk22/death-mahjong/blob/master/frontend/death-mahjong-client/app/profile/page.tsx"
click node_stats "https://github.com/sofie-kirk22/death-mahjong/blob/master/frontend/death-mahjong-client/app/stats/page.tsx"
click node_api_client "https://github.com/sofie-kirk22/death-mahjong/blob/master/frontend/death-mahjong-client/lib/api.ts"
click node_session "https://github.com/sofie-kirk22/death-mahjong/blob/master/frontend/death-mahjong-client/lib/gameSession.ts"
click node_user_session "https://github.com/sofie-kirk22/death-mahjong/blob/master/frontend/death-mahjong-client/lib/userSession.ts"
click node_api "https://github.com/sofie-kirk22/death-mahjong/blob/master/backend/DeathMahjong/Program.cs"
click node_engine "https://github.com/sofie-kirk22/death-mahjong/blob/master/backend/DeathMahjong/Services/GameEngine.cs"
click node_room_store "https://github.com/sofie-kirk22/death-mahjong/blob/master/backend/DeathMahjong/Services/GameRoomStore.cs"
click node_room_model "https://github.com/sofie-kirk22/death-mahjong/blob/master/backend/DeathMahjong/Models/GameRoom.cs"
click node_hub "https://github.com/sofie-kirk22/death-mahjong/blob/master/backend/DeathMahjong/Hubs/GameHub.cs"
click node_hub_client "https://github.com/sofie-kirk22/death-mahjong/blob/master/frontend/death-mahjong-client/lib/gameHub.ts"
click node_db_context "https://github.com/sofie-kirk22/death-mahjong/blob/master/backend/DeathMahjong/Data/AppDbContext.cs"
click node_entities "https://github.com/sofie-kirk22/death-mahjong/blob/master/backend/DeathMahjong/Data/Entities/GameRoomEntity.cs"
click node_users "https://github.com/sofie-kirk22/death-mahjong/blob/master/backend/DeathMahjong/Data/Entities/UserEntity.cs"
click node_completed "https://github.com/sofie-kirk22/death-mahjong/blob/master/backend/DeathMahjong/Data/Entities/CompletedGameEntity.cs"
click node_leaderboard_data "https://github.com/sofie-kirk22/death-mahjong/blob/master/backend/DeathMahjong/Data/Entities/CompletedGamePlayerEntity.cs"

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_lobby,node_play,node_endview,node_profile,node_stats,node_session toneBlue
class node_api,node_engine,node_room_store,node_room_model toneAmber
class node_user_session,node_db_context,node_entities,node_users,node_completed,node_database,node_leaderboard_data toneMint
class node_api_client,node_hub,node_hub_client toneRose
class node_players toneIndigo
```

## Components

### Player experience

- [Room entry](https://github.com/sofie-kirk22/death-mahjong/blob/master/frontend/death-mahjong-client/app/page.tsx): `frontend/death-mahjong-client/app/page.tsx`
- [Room lobby](https://github.com/sofie-kirk22/death-mahjong/blob/master/frontend/death-mahjong-client/app/room/%5BroomId%5D/page.tsx): `frontend/death-mahjong-client/app/room/[roomId]/page.tsx`
- [Live game view](https://github.com/sofie-kirk22/death-mahjong/blob/master/frontend/death-mahjong-client/app/game/%5BroomId%5D/page.tsx): `frontend/death-mahjong-client/app/game/[roomId]/page.tsx`
- [Game results](https://github.com/sofie-kirk22/death-mahjong/blob/master/frontend/death-mahjong-client/app/game-end/%5BroomId%5D/page.tsx): `frontend/death-mahjong-client/app/game-end/[roomId]/page.tsx`
- [Player profile](https://github.com/sofie-kirk22/death-mahjong/blob/master/frontend/death-mahjong-client/app/profile/page.tsx): `frontend/death-mahjong-client/app/profile/page.tsx`
- [Leaderboards](https://github.com/sofie-kirk22/death-mahjong/blob/master/frontend/death-mahjong-client/app/stats/page.tsx): `frontend/death-mahjong-client/app/stats/page.tsx`
- [Room session](https://github.com/sofie-kirk22/death-mahjong/blob/master/frontend/death-mahjong-client/lib/gameSession.ts): `frontend/death-mahjong-client/lib/gameSession.ts`

### Game runtime

- [HTTP API](https://github.com/sofie-kirk22/death-mahjong/blob/master/backend/DeathMahjong/Program.cs): `backend/DeathMahjong/Program.cs`
- [Game rules](https://github.com/sofie-kirk22/death-mahjong/blob/master/backend/DeathMahjong/Services/GameEngine.cs): `backend/DeathMahjong/Services/GameEngine.cs`
- [Room store](https://github.com/sofie-kirk22/death-mahjong/blob/master/backend/DeathMahjong/Services/GameRoomStore.cs): `backend/DeathMahjong/Services/GameRoomStore.cs`
- [Room state](https://github.com/sofie-kirk22/death-mahjong/blob/master/backend/DeathMahjong/Models/GameRoom.cs): `backend/DeathMahjong/Models/GameRoom.cs`

### Accounts and records

- [User session](https://github.com/sofie-kirk22/death-mahjong/blob/master/frontend/death-mahjong-client/lib/userSession.ts): `frontend/death-mahjong-client/lib/userSession.ts`
- [EF data access](https://github.com/sofie-kirk22/death-mahjong/blob/master/backend/DeathMahjong/Data/AppDbContext.cs): `backend/DeathMahjong/Data/AppDbContext.cs`
- [Room and game records](https://github.com/sofie-kirk22/death-mahjong/blob/master/backend/DeathMahjong/Data/Entities/GameRoomEntity.cs): `backend/DeathMahjong/Data/Entities/GameRoomEntity.cs`
- [User records](https://github.com/sofie-kirk22/death-mahjong/blob/master/backend/DeathMahjong/Data/Entities/UserEntity.cs): `backend/DeathMahjong/Data/Entities/UserEntity.cs`
- [Completed-game records](https://github.com/sofie-kirk22/death-mahjong/blob/master/backend/DeathMahjong/Data/Entities/CompletedGameEntity.cs): `backend/DeathMahjong/Data/Entities/CompletedGameEntity.cs`
- **Relational database**
- [Statistics records](https://github.com/sofie-kirk22/death-mahjong/blob/master/backend/DeathMahjong/Data/Entities/CompletedGamePlayerEntity.cs): `backend/DeathMahjong/Data/Entities/CompletedGamePlayerEntity.cs`

### Realtime transport

- [REST client](https://github.com/sofie-kirk22/death-mahjong/blob/master/frontend/death-mahjong-client/lib/api.ts): `frontend/death-mahjong-client/lib/api.ts`
- [SignalR hub](https://github.com/sofie-kirk22/death-mahjong/blob/master/backend/DeathMahjong/Hubs/GameHub.cs): `backend/DeathMahjong/Hubs/GameHub.cs`
- [Live connection](https://github.com/sofie-kirk22/death-mahjong/blob/master/frontend/death-mahjong-client/lib/gameHub.ts): `frontend/death-mahjong-client/lib/gameHub.ts`

### Other components

- **Players**

## Connections

- Players → Room entry: create or join
- Room entry → REST client: requests
- Room entry → Room session: saves identity
- Room entry → User session: saves user
- Room lobby → REST client: room actions
- Live game view → REST client: draw or abort
- Live game view → Room session: reads player
- Player profile → REST client: loads profile
- Player profile → User session: reads and saves
- Leaderboards → REST client: loads statistics
- REST client → HTTP API: HTTP requests
- HTTP API → Game rules: delegates rules
- HTTP API → Room store: reads and writes
- HTTP API → Room state: updates state
- HTTP API → SignalR hub: broadcasts events
- Live game view → Live connection: subscribes
- Live connection → SignalR hub: SignalR connection
- SignalR hub → Live game view: live updates
- HTTP API → EF data access: persists and queries
- EF data access → Room and game records: maps records
- EF data access → User records: maps users
- EF data access → Completed-game records: maps completed games
- EF data access → Statistics records: maps player statistics
- EF data access → Relational database: reads and writes
- Game results → REST client: loads room results
- Players → Player profile: view profile
- Players → Leaderboards: view leaderboards
