# cyrikxxx/igroteka architecture

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

- Interactive diagram: https://gitdiagram.com/cyrikxxx/igroteka
- Repository: https://github.com/cyrikxxx/igroteka

## Overview

Игротека is a browser-based multiplayer party-game product for Alias and Mafia. Players enter through the web hub, create or join a room, then play through real-time Socket.IO sessions; Alias also supports local play, while Mafia provides role-based phases and game history. The web API creates rooms and issues connection credentials; the WebSocket service runs the live game loops. Redis holds live room state and PostgreSQL stores durable records. Several UI pages and subsystems are represented from the tree and README, since their source was not sampled.

Main entry points: [`apps/ws/src/prisma.ts`](https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/prisma.ts) (PostgreSQL records), [`apps/ws/src/games/mafia/engine.ts`](https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/games/mafia/engine.ts) (Mafia game engine), [`apps/ws/src/games/alias/handlers/round.ts`](https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/games/alias/handlers/round.ts) (Alias round handler), [`apps/web/src/app/api/mafia/rooms/route.ts`](https://github.com/cyrikxxx/igroteka/blob/main/apps/web/src/app/api/mafia/rooms/route.ts) (Mafia room API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web experience"]
  node_hub["Game hub<br/>[page.tsx]"]
  node_alias_ui["Alias pages<br/>[page.tsx]"]
  node_mafia_ui["Mafia pages<br/>[page.tsx]"]
  node_history_ui["Game history<br/>[page.tsx]"]
  node_room_api["Room API<br/>[route.ts]"]
  node_mafia_room_api["Mafia room API<br/>[route.ts]"]
  node_mafia_history_api["Mafia history API<br/>[route.ts]"]
  node_alias_rounds_api["Local Alias rounds<br/>[route.ts]"]
end

subgraph group_alias["Alias realtime"]
  node_socket_auth["Socket authentication<br/>[auth.ts]"]
  node_alias_round_handler["Alias round handler<br/>[round.ts]"]
  node_alias_game_service["Alias game service<br/>[game.ts]"]
  node_alias_words["Word queue<br/>[word.ts]"]
  node_alias_round_state["Round state<br/>[roundState.ts]"]
  node_alias_broadcast["Alias broadcasts<br/>[broadcast.ts]"]
  node_alias_snapshot["Alias snapshots<br/>[snapshot.ts]"]
end

subgraph group_mafia["Mafia realtime"]
  node_mafia_engine["Mafia game engine<br/>[engine.ts]"]
  node_mafia_core["Mafia rules engine<br/>[engine-core.ts]"]
  node_mafia_broadcast["Mafia broadcasts<br/>[broadcast.ts]"]
  node_mafia_view["Player-specific views<br/>[view.ts]"]
  node_mafia_snapshot["Mafia snapshots<br/>[snapshot.ts]"]
  node_mafia_persist["Mafia persistence<br/>[persist.ts]"]
end

subgraph group_shared["Contracts and storage"]
  node_shared_contract["Shared game contracts<br/>[mafia.ts]"]
  node_redis[("Redis live state<br/>[redis.ts]")]
  node_postgres[("PostgreSQL records<br/>[prisma.ts]")]
  node_room_lifecycle["Room lifecycle<br/>[room-lifecycle.ts]"]
end

node_player(("Players"))

node_player -->|"opens"| node_hub
node_hub -.->|"creates Alias room"| node_room_api
node_hub -.->|"creates Mafia room"| node_mafia_room_api
node_player -->|"plays Alias"| node_alias_ui
node_player -->|"plays Mafia"| node_mafia_ui
node_room_api -.->|"records room"| node_postgres
node_mafia_room_api -->|"creates room record"| node_postgres
node_mafia_room_api -->|"saves lobby snapshot"| node_redis
node_mafia_ui -.->|"requests room"| node_mafia_room_api
node_alias_ui -.->|"connects to game"| node_socket_auth
node_mafia_ui -.->|"connects to game"| node_socket_auth
node_socket_auth -->|"verifies token"| node_shared_contract
node_alias_round_handler -->|"fetches and advances words"| node_alias_words
node_alias_round_handler -->|"loads and saves round"| node_alias_round_state
node_alias_round_handler -->|"broadcasts state"| node_alias_broadcast
node_alias_round_handler -->|"loads room snapshot"| node_alias_snapshot
node_alias_broadcast -->|"loads snapshot"| node_alias_snapshot
node_alias_broadcast -->|"adds live timer"| node_alias_round_state
node_alias_round_state -->|"stores round state"| node_redis
node_alias_game_service -->|"reads and writes game data"| node_postgres
node_alias_game_service -->|"uses round state"| node_alias_round_state
node_mafia_engine -->|"applies game rules"| node_mafia_core
node_mafia_engine -->|"loads and mutates snapshots"| node_mafia_snapshot
node_mafia_engine -->|"broadcasts game state"| node_mafia_broadcast
node_mafia_engine -->|"closes room record"| node_room_lifecycle
node_mafia_snapshot -->|"stores live snapshot"| node_redis
node_mafia_broadcast -->|"loads snapshot"| node_mafia_snapshot
node_mafia_broadcast -->|"builds player view"| node_mafia_view
node_mafia_persist -->|"persists completed games"| node_postgres
node_room_lifecycle -->|"updates room record"| node_postgres
node_history_ui -.->|"loads history"| node_mafia_history_api
node_mafia_history_api -->|"reads finished games"| node_postgres
node_mafia_history_api -->|"loads live rooms"| node_mafia_snapshot
node_player -->|"submits local round"| node_alias_rounds_api
node_alias_rounds_api -->|"saves round results"| node_postgres
node_room_api -.->|"shares realtime contract"| node_shared_contract
node_mafia_engine -->|"uses game types"| node_shared_contract

click node_hub "https://github.com/cyrikxxx/igroteka/blob/main/apps/web/src/app/page.tsx"
click node_alias_ui "https://github.com/cyrikxxx/igroteka/blob/main/apps/web/src/app/alias/room/%5Bcode%5D/page.tsx"
click node_mafia_ui "https://github.com/cyrikxxx/igroteka/blob/main/apps/web/src/app/mafia/room/%5Bcode%5D/page.tsx"
click node_history_ui "https://github.com/cyrikxxx/igroteka/blob/main/apps/web/src/app/history/page.tsx"
click node_room_api "https://github.com/cyrikxxx/igroteka/blob/main/apps/web/src/app/api/rooms/route.ts"
click node_mafia_room_api "https://github.com/cyrikxxx/igroteka/blob/main/apps/web/src/app/api/mafia/rooms/route.ts"
click node_mafia_history_api "https://github.com/cyrikxxx/igroteka/blob/main/apps/web/src/app/api/mafia/history/route.ts"
click node_alias_rounds_api "https://github.com/cyrikxxx/igroteka/blob/main/apps/web/src/app/api/games/%5Bid%5D/rounds/route.ts"
click node_socket_auth "https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/auth.ts"
click node_alias_round_handler "https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/games/alias/handlers/round.ts"
click node_alias_game_service "https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/games/alias/services/game.ts"
click node_alias_words "https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/games/alias/services/word.ts"
click node_alias_round_state "https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/games/alias/services/roundState.ts"
click node_alias_broadcast "https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/games/alias/broadcast.ts"
click node_alias_snapshot "https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/games/alias/snapshot.ts"
click node_mafia_engine "https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/games/mafia/engine.ts"
click node_mafia_core "https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/games/mafia/engine-core.ts"
click node_mafia_broadcast "https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/games/mafia/broadcast.ts"
click node_mafia_view "https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/games/mafia/view.ts"
click node_mafia_snapshot "https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/games/mafia/snapshot.ts"
click node_mafia_persist "https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/games/mafia/services/persist.ts"
click node_shared_contract "https://github.com/cyrikxxx/igroteka/blob/main/packages/shared/src/mafia.ts"
click node_redis "https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/redis.ts"
click node_postgres "https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/prisma.ts"
click node_room_lifecycle "https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/services/room-lifecycle.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_hub,node_alias_ui,node_mafia_ui,node_history_ui,node_room_api,node_mafia_room_api,node_mafia_history_api,node_alias_rounds_api toneBlue
class node_socket_auth,node_alias_round_handler,node_alias_game_service,node_alias_words,node_alias_round_state,node_alias_broadcast,node_alias_snapshot toneAmber
class node_mafia_engine,node_mafia_core,node_mafia_broadcast,node_mafia_view,node_mafia_snapshot,node_mafia_persist toneMint
class node_shared_contract,node_redis,node_postgres,node_room_lifecycle toneRose
class node_player toneIndigo
```

## Components

### Web experience

- [Game hub](https://github.com/cyrikxxx/igroteka/blob/main/apps/web/src/app/page.tsx): `apps/web/src/app/page.tsx`
- [Alias pages](https://github.com/cyrikxxx/igroteka/blob/main/apps/web/src/app/alias/room/%5Bcode%5D/page.tsx): `apps/web/src/app/alias/room/[code]/page.tsx`
- [Mafia pages](https://github.com/cyrikxxx/igroteka/blob/main/apps/web/src/app/mafia/room/%5Bcode%5D/page.tsx): `apps/web/src/app/mafia/room/[code]/page.tsx`
- [Game history](https://github.com/cyrikxxx/igroteka/blob/main/apps/web/src/app/history/page.tsx): `apps/web/src/app/history/page.tsx`
- [Room API](https://github.com/cyrikxxx/igroteka/blob/main/apps/web/src/app/api/rooms/route.ts): `apps/web/src/app/api/rooms/route.ts`
- [Mafia room API](https://github.com/cyrikxxx/igroteka/blob/main/apps/web/src/app/api/mafia/rooms/route.ts): `apps/web/src/app/api/mafia/rooms/route.ts`
- [Mafia history API](https://github.com/cyrikxxx/igroteka/blob/main/apps/web/src/app/api/mafia/history/route.ts): `apps/web/src/app/api/mafia/history/route.ts`
- [Local Alias rounds](https://github.com/cyrikxxx/igroteka/blob/main/apps/web/src/app/api/games/%5Bid%5D/rounds/route.ts): `apps/web/src/app/api/games/[id]/rounds/route.ts`

### Alias realtime

- [Socket authentication](https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/auth.ts): `apps/ws/src/auth.ts`
- [Alias round handler](https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/games/alias/handlers/round.ts): `apps/ws/src/games/alias/handlers/round.ts`
- [Alias game service](https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/games/alias/services/game.ts): `apps/ws/src/games/alias/services/game.ts`
- [Word queue](https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/games/alias/services/word.ts): `apps/ws/src/games/alias/services/word.ts`
- [Round state](https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/games/alias/services/roundState.ts): `apps/ws/src/games/alias/services/roundState.ts`
- [Alias broadcasts](https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/games/alias/broadcast.ts): `apps/ws/src/games/alias/broadcast.ts`
- [Alias snapshots](https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/games/alias/snapshot.ts): `apps/ws/src/games/alias/snapshot.ts`

### Mafia realtime

- [Mafia game engine](https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/games/mafia/engine.ts): `apps/ws/src/games/mafia/engine.ts`
- [Mafia rules engine](https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/games/mafia/engine-core.ts): `apps/ws/src/games/mafia/engine-core.ts`
- [Mafia broadcasts](https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/games/mafia/broadcast.ts): `apps/ws/src/games/mafia/broadcast.ts`
- [Player-specific views](https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/games/mafia/view.ts): `apps/ws/src/games/mafia/view.ts`
- [Mafia snapshots](https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/games/mafia/snapshot.ts): `apps/ws/src/games/mafia/snapshot.ts`
- [Mafia persistence](https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/games/mafia/services/persist.ts): `apps/ws/src/games/mafia/services/persist.ts`

### Contracts and storage

- [Shared game contracts](https://github.com/cyrikxxx/igroteka/blob/main/packages/shared/src/mafia.ts): `packages/shared/src/mafia.ts`
- [Redis live state](https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/redis.ts): `apps/ws/src/redis.ts`
- [PostgreSQL records](https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/prisma.ts): `apps/ws/src/prisma.ts`
- [Room lifecycle](https://github.com/cyrikxxx/igroteka/blob/main/apps/ws/src/services/room-lifecycle.ts): `apps/ws/src/services/room-lifecycle.ts`

### Other components

- **Players**

## Connections

- Players → Game hub: opens (evidence: `README.md`)
- Game hub → Room API: creates Alias room
- Game hub → Mafia room API: creates Mafia room
- Players → Alias pages: plays Alias (evidence: `README.md`)
- Players → Mafia pages: plays Mafia (evidence: `README.md`)
- Room API → PostgreSQL records: records room
- Mafia room API → PostgreSQL records: creates room record (evidence: `apps/web/src/app/api/mafia/rooms/route.ts`)
- Mafia room API → Redis live state: saves lobby snapshot (evidence: `apps/web/src/app/api/mafia/rooms/route.ts`)
- Mafia pages → Mafia room API: requests room
- Alias pages → Socket authentication: connects to game
- Mafia pages → Socket authentication: connects to game
- Socket authentication → Shared game contracts: verifies token (evidence: `apps/ws/src/auth.ts`)
- Alias round handler → Word queue: fetches and advances words (evidence: `apps/ws/src/games/alias/handlers/round.ts`)
- Alias round handler → Round state: loads and saves round (evidence: `apps/ws/src/games/alias/handlers/round.ts`)
- Alias round handler → Alias broadcasts: broadcasts state (evidence: `apps/ws/src/games/alias/handlers/round.ts`)
- Alias round handler → Alias snapshots: loads room snapshot (evidence: `apps/ws/src/games/alias/handlers/round.ts`)
- Alias broadcasts → Alias snapshots: loads snapshot (evidence: `apps/ws/src/games/alias/broadcast.ts`)
- Alias broadcasts → Round state: adds live timer (evidence: `apps/ws/src/games/alias/broadcast.ts`)
- Round state → Redis live state: stores round state (evidence: `apps/ws/src/games/alias/services/roundState.ts`)
- Alias game service → PostgreSQL records: reads and writes game data (evidence: `apps/ws/src/games/alias/services/game.ts`)
- Alias game service → Round state: uses round state (evidence: `apps/ws/src/games/alias/services/game.ts`)
- Mafia game engine → Mafia rules engine: applies game rules (evidence: `apps/ws/src/games/mafia/engine.ts`)
- Mafia game engine → Mafia snapshots: loads and mutates snapshots (evidence: `apps/ws/src/games/mafia/engine.ts`)
- Mafia game engine → Mafia broadcasts: broadcasts game state (evidence: `apps/ws/src/games/mafia/engine.ts`)
- Mafia game engine → Room lifecycle: closes room record (evidence: `apps/ws/src/games/mafia/engine.ts`)
- Mafia snapshots → Redis live state: stores live snapshot (evidence: `apps/ws/src/games/mafia/snapshot.ts`)
- Mafia broadcasts → Mafia snapshots: loads snapshot (evidence: `apps/ws/src/games/mafia/broadcast.ts`)
- Mafia broadcasts → Player-specific views: builds player view (evidence: `apps/ws/src/games/mafia/broadcast.ts`)
- Mafia persistence → PostgreSQL records: persists completed games (evidence: `apps/ws/src/games/mafia/services/persist.ts`)
- Room lifecycle → PostgreSQL records: updates room record (evidence: `apps/ws/src/services/room-lifecycle.ts`)
- Game history → Mafia history API: loads history
- Mafia history API → PostgreSQL records: reads finished games (evidence: `apps/web/src/app/api/mafia/history/route.ts`)
- Mafia history API → Mafia snapshots: loads live rooms (evidence: `apps/web/src/app/api/mafia/history/route.ts`)
- Players → Local Alias rounds: submits local round (evidence: `apps/web/src/app/api/games/[id]/rounds/route.ts`)
- Local Alias rounds → PostgreSQL records: saves round results (evidence: `apps/web/src/app/api/games/[id]/rounds/route.ts`)
- Room API → Shared game contracts: shares realtime contract
- Mafia game engine → Shared game contracts: uses game types
