How skelmkeyz/keyz-dice-game-luck-of-the-king works
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: db.ts Postgres client · page.tsx Room screen · dice.ts Dice processing · index.ts Socket entry
Components 24
Player experience
- Home page
app/page.tsx - Room screen
app/rooms/[id]/page.tsx - Dice view
app/rooms/[id]/Dice.tsx - Room client
app/rooms/[id]/RoomClient.tsx - Leaderboard page
app/leaderboard/page.tsx
HTTP endpoints
- Create room API
app/api/rooms/create/route.ts - Join room API
app/api/rooms/join/route.ts - Room state API
app/api/rooms/state/route.ts - Dice roll API
app/api/dice/roll/route.ts
Game logic
- Dice processing
lib/dice.ts - Game rules
lib/game.ts - Game types
types/game.ts - Room helpers
lib/rooms.ts - Leaderboard helpers
lib/leaderboard.ts - Validation helpers
lib/validate.ts - Auth helpers
lib/auth.ts
Persistence and realtime
- Postgres client
lib/db.ts - Postgres database
- Socket client
lib/socket.ts - Socket entry
sockets/index.ts - Room channel
sockets/roomChannel.ts - Dice channel
sockets/diceChannel.ts - Chat channel
sockets/chatChannel.ts
Other components
- Player
Connections 22
- Player → Home page: opens
app/page.tsx - Player → Room screen: opens
app/rooms/[id]/page.tsx - Player → Leaderboard page: opens
app/leaderboard/page.tsx - Player → Create room API: creates room
app/api/rooms/create/route.ts - Player → Join room API: joins room
app/api/rooms/join/route.ts - Player → Room state API: requests state
app/api/rooms/state/route.ts - Room screen → Dice roll API: posts roll
app/rooms/[id]/page.tsx - Dice roll API → Room screen: returns roll
app/rooms/[id]/page.tsx - Room screen → Socket client: joins room
app/rooms/[id]/page.tsx - Socket client → Room screen: delivers event
app/rooms/[id]/page.tsx - Create room API → Postgres client: inserts room
app/api/rooms/create/route.ts - Join room API → Postgres client: updates room
app/api/rooms/join/route.ts - Room state API → Postgres client: reads room
app/api/rooms/state/route.ts - Leaderboard page → Postgres client: queries rankings
app/leaderboard/page.tsx - Dice processing → Postgres client: reads and writes
lib/dice.ts - Postgres client → Postgres database: queries
lib/db.ts - Dice processing → Game rules: uses rules
lib/dice.ts - Game rules → Game types: uses type
lib/game.ts - Dice processing → Postgres database: records rolls
- Socket entry → Room channel: registers
- Socket entry → Dice channel: registers
- Socket entry → Chat channel: registers