# skelmkeyz/keyz-dice-game-luck-of-the-king architecture

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

- Interactive diagram: https://gitdiagram.com/skelmkeyz/keyz-dice-game-luck-of-the-king
- Repository: https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king

## Overview

This is a Next.js King-vs-Challenger dice game with room creation and joining, room-state display, dice rolling, live room updates, and a leaderboard. The visible room workflow is a player opening a room, rolling through the dice API, and receiving room events over Socket.IO; room creation, joining, and state retrieval are separate API operations. The repository also contains a distinct dice-processing and game-rules layer, but the sampled roll route does not call it. Socket channel wiring and several small modules were not shown, so their relationships are omitted.

Main entry points: [`lib/db.ts`](https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/lib/db.ts) (Postgres client), [`app/rooms/[id]/page.tsx`](https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/app/rooms/%5Bid%5D/page.tsx) (Room screen), [`lib/dice.ts`](https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/lib/dice.ts) (Dice processing), [`sockets/index.ts`](https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/sockets/index.ts) (Socket entry)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_experience["Player experience"]
  node_home["Home page<br/>[page.tsx]"]
  node_room_page["Room screen<br/>[page.tsx]"]
  node_dice_view["Dice view<br/>[Dice.tsx]"]
  node_room_client["Room client<br/>[RoomClient.tsx]"]
  node_leaderboard_page["Leaderboard page<br/>[page.tsx]"]
end

subgraph group_endpoints["HTTP endpoints"]
  node_create_api["Create room API<br/>[route.ts]"]
  node_join_api["Join room API<br/>[route.ts]"]
  node_state_api["Room state API<br/>[route.ts]"]
  node_roll_api["Dice roll API<br/>[route.ts]"]
end

subgraph group_game["Game logic"]
  node_dice_logic["Dice processing<br/>[dice.ts]"]
  node_game_rules["Game rules<br/>[game.ts]"]
  node_game_types["Game types<br/>[game.ts]"]
  node_room_helpers["Room helpers<br/>[rooms.ts]"]
  node_leaderboard_helpers["Leaderboard helpers<br/>[leaderboard.ts]"]
  node_validation["Validation helpers<br/>[validate.ts]"]
  node_auth["Auth helpers<br/>[auth.ts]"]
end

subgraph group_persistence["Persistence and realtime"]
  node_db_client["Postgres client<br/>[db.ts]"]
  node_database[("Postgres database")]
  node_socket_client["Socket client<br/>[socket.ts]"]
  node_socket_index["Socket entry<br/>[index.ts]"]
  node_room_channel["Room channel<br/>[roomChannel.ts]"]
  node_dice_channel["Dice channel<br/>[diceChannel.ts]"]
  node_chat_channel["Chat channel<br/>[chatChannel.ts]"]
end

node_player(("Player"))

node_player -->|"opens"| node_home
node_player -->|"opens"| node_room_page
node_player -->|"opens"| node_leaderboard_page
node_player -->|"creates room"| node_create_api
node_player -->|"joins room"| node_join_api
node_player -->|"requests state"| node_state_api
node_room_page -->|"posts roll"| node_roll_api
node_roll_api -->|"returns roll"| node_room_page
node_room_page -->|"joins room"| node_socket_client
node_socket_client -->|"delivers event"| node_room_page
node_create_api -->|"inserts room"| node_db_client
node_join_api -->|"updates room"| node_db_client
node_state_api -->|"reads room"| node_db_client
node_leaderboard_page -->|"queries rankings"| node_db_client
node_dice_logic -->|"reads and writes"| node_db_client
node_db_client -->|"queries"| node_database
node_dice_logic -->|"uses rules"| node_game_rules
node_game_rules -->|"uses type"| node_game_types
node_dice_logic -.->|"records rolls"| node_database
node_socket_index -.->|"registers"| node_room_channel
node_socket_index -.->|"registers"| node_dice_channel
node_socket_index -.->|"registers"| node_chat_channel

click node_home "https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/app/page.tsx"
click node_room_page "https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/app/rooms/%5Bid%5D/page.tsx"
click node_dice_view "https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/app/rooms/%5Bid%5D/Dice.tsx"
click node_room_client "https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/app/rooms/%5Bid%5D/RoomClient.tsx"
click node_leaderboard_page "https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/app/leaderboard/page.tsx"
click node_create_api "https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/app/api/rooms/create/route.ts"
click node_join_api "https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/app/api/rooms/join/route.ts"
click node_state_api "https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/app/api/rooms/state/route.ts"
click node_roll_api "https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/app/api/dice/roll/route.ts"
click node_dice_logic "https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/lib/dice.ts"
click node_game_rules "https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/lib/game.ts"
click node_game_types "https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/types/game.ts"
click node_room_helpers "https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/lib/rooms.ts"
click node_leaderboard_helpers "https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/lib/leaderboard.ts"
click node_validation "https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/lib/validate.ts"
click node_auth "https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/lib/auth.ts"
click node_db_client "https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/lib/db.ts"
click node_socket_client "https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/lib/socket.ts"
click node_socket_index "https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/sockets/index.ts"
click node_room_channel "https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/sockets/roomChannel.ts"
click node_dice_channel "https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/sockets/diceChannel.ts"
click node_chat_channel "https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/sockets/chatChannel.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_home,node_room_page,node_dice_view,node_room_client,node_leaderboard_page toneBlue
class node_create_api,node_join_api,node_state_api,node_roll_api toneAmber
class node_dice_logic,node_game_rules,node_game_types,node_room_helpers,node_leaderboard_helpers,node_validation,node_auth toneMint
class node_db_client,node_database,node_socket_client,node_socket_index,node_room_channel,node_dice_channel,node_chat_channel toneRose
class node_player toneIndigo
```

## Components

### Player experience

- [Home page](https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/app/page.tsx): `app/page.tsx`
- [Room screen](https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/app/rooms/%5Bid%5D/page.tsx): `app/rooms/[id]/page.tsx`
- [Dice view](https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/app/rooms/%5Bid%5D/Dice.tsx): `app/rooms/[id]/Dice.tsx`
- [Room client](https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/app/rooms/%5Bid%5D/RoomClient.tsx): `app/rooms/[id]/RoomClient.tsx`
- [Leaderboard page](https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/app/leaderboard/page.tsx): `app/leaderboard/page.tsx`

### HTTP endpoints

- [Create room API](https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/app/api/rooms/create/route.ts): `app/api/rooms/create/route.ts`
- [Join room API](https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/app/api/rooms/join/route.ts): `app/api/rooms/join/route.ts`
- [Room state API](https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/app/api/rooms/state/route.ts): `app/api/rooms/state/route.ts`
- [Dice roll API](https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/app/api/dice/roll/route.ts): `app/api/dice/roll/route.ts`

### Game logic

- [Dice processing](https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/lib/dice.ts): `lib/dice.ts`
- [Game rules](https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/lib/game.ts): `lib/game.ts`
- [Game types](https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/types/game.ts): `types/game.ts`
- [Room helpers](https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/lib/rooms.ts): `lib/rooms.ts`
- [Leaderboard helpers](https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/lib/leaderboard.ts): `lib/leaderboard.ts`
- [Validation helpers](https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/lib/validate.ts): `lib/validate.ts`
- [Auth helpers](https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/lib/auth.ts): `lib/auth.ts`

### Persistence and realtime

- [Postgres client](https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/lib/db.ts): `lib/db.ts`
- **Postgres database**
- [Socket client](https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/lib/socket.ts): `lib/socket.ts`
- [Socket entry](https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/sockets/index.ts): `sockets/index.ts`
- [Room channel](https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/sockets/roomChannel.ts): `sockets/roomChannel.ts`
- [Dice channel](https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/sockets/diceChannel.ts): `sockets/diceChannel.ts`
- [Chat channel](https://github.com/skelmkeyz/keyz-dice-game-luck-of-the-king/blob/main/sockets/chatChannel.ts): `sockets/chatChannel.ts`

### Other components

- **Player**

## Connections

- Player → Home page: opens (evidence: `app/page.tsx`)
- Player → Room screen: opens (evidence: `app/rooms/[id]/page.tsx`)
- Player → Leaderboard page: opens (evidence: `app/leaderboard/page.tsx`)
- Player → Create room API: creates room (evidence: `app/api/rooms/create/route.ts`)
- Player → Join room API: joins room (evidence: `app/api/rooms/join/route.ts`)
- Player → Room state API: requests state (evidence: `app/api/rooms/state/route.ts`)
- Room screen → Dice roll API: posts roll (evidence: `app/rooms/[id]/page.tsx`)
- Dice roll API → Room screen: returns roll (evidence: `app/rooms/[id]/page.tsx`)
- Room screen → Socket client: joins room (evidence: `app/rooms/[id]/page.tsx`)
- Socket client → Room screen: delivers event (evidence: `app/rooms/[id]/page.tsx`)
- Create room API → Postgres client: inserts room (evidence: `app/api/rooms/create/route.ts`)
- Join room API → Postgres client: updates room (evidence: `app/api/rooms/join/route.ts`)
- Room state API → Postgres client: reads room (evidence: `app/api/rooms/state/route.ts`)
- Leaderboard page → Postgres client: queries rankings (evidence: `app/leaderboard/page.tsx`)
- Dice processing → Postgres client: reads and writes (evidence: `lib/dice.ts`)
- Postgres client → Postgres database: queries (evidence: `lib/db.ts`)
- Dice processing → Game rules: uses rules (evidence: `lib/dice.ts`)
- Game rules → Game types: uses type (evidence: `lib/game.ts`)
- Dice processing → Postgres database: records rolls
- Socket entry → Room channel: registers
- Socket entry → Dice channel: registers
- Socket entry → Chat channel: registers
