# taskinnasif144/greedy-game-backend architecture

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

- Interactive diagram: https://gitdiagram.com/taskinnasif144/greedy-game-backend
- Repository: https://github.com/taskinnasif144/greedy-game-backend

## Overview

This is a multiplayer, round-based betting game service with player entry, game-session APIs, real-time gameplay, automated bots, and administrative controls. The main player flow consumes an entry credential to establish a game session, then uses game APIs and WebSocket gameplay to bet in managed rounds whose results and rewards are persisted. The graph preserves those stages and the documented admin capabilities. Several use cases and bootstraps are unsampled, so their internals and links are omitted unless the shown application wiring supports them.

Main entry points: [`src/modules/game/application/services/RoundManager.ts`](https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/application/services/RoundManager.ts) (Round lifecycle), [`src/modules/player-entry/presentation/PlayerController.ts`](https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/player-entry/presentation/PlayerController.ts) (Entry API), [`src/modules/game/presentation/GameController.ts`](https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/presentation/GameController.ts) (Game API), [`src/modules/admin/presentation/AdminController.ts`](https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/admin/presentation/AdminController.ts) (Admin API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Player entry"]
  node_entry_api["Entry API"]
  node_entry_creation["Create entry session"]
  node_entry_store[("Entry sessions")]
end

subgraph group_game["Game runtime"]
  node_game_api["Game API<br/>[GameController.ts]"]
  node_game_session["Game sessions"]
  node_live_gateway["Live gameplay<br/>[GameGateway.ts]"]
  node_betting["Bet placement<br/>[PlaceBetUseCase.ts]"]
  node_round_manager["Round lifecycle<br/>[RoundManager.ts]"]
  node_round_model["Round entity<br/>[Round.ts]"]
  node_bet_model["Bet entity<br/>[Bet.ts]"]
  node_result_calc["Result selection"]
  node_round_compute["Compute result"]
  node_reward_distribution["Reward distribution"]
  node_round_storage[("Round persistence")]
  node_bet_storage[("Bet persistence")]
  node_session_storage[("Game sessions")]
  node_bots["Bot betting<br/>[BotManager.ts]"]
  node_webhooks["Webhook notifications<br/>[WebhookNotifier.ts]"]
end

subgraph group_admin["Administration"]
  node_admin_api["Admin API<br/>[AdminController.ts]"]
  node_admin_cases["Admin operations"]
  node_admin_auth["Admin authentication"]
end

subgraph group_shared["Shared domain"]
  node_player_entity["Player entity<br/>[Player.ts]"]
  node_timer["Timer service<br/>[ITimerService.ts]"]
end

node_player(("Player"))
node_service["Game service"]

node_player -->|"submits entry"| node_entry_api
node_entry_api -->|"invokes"| node_entry_creation
node_entry_creation -.->|"stores session"| node_entry_store
node_entry_api -->|"starts game"| node_game_api
node_game_api -->|"starts session"| node_game_session
node_game_api -.->|"queries rounds"| node_round_manager
node_player -.->|"connects"| node_live_gateway
node_live_gateway -.->|"places bet"| node_betting
node_betting -.->|"updates balance"| node_session_storage
node_round_manager -->|"creates round"| node_round_model
node_round_manager -->|"persists round"| node_round_storage
node_round_manager -->|"cleans bet data"| node_bet_storage
node_round_manager -->|"computes result"| node_round_compute
node_round_manager -->|"distributes rewards"| node_reward_distribution
node_round_manager -->|"schedules rounds"| node_timer
node_round_compute -.->|"selects outcome"| node_result_calc
node_bots -->|"places bets"| node_betting
node_bots -->|"creates sessions"| node_session_storage
node_admin_api -->|"invokes operations"| node_admin_cases
node_admin_api -->|"pauses game"| node_round_manager
node_player_entity -->|"reconstructed from"| node_session_storage
node_service -->|"mounts module"| node_entry_api
node_service -->|"mounts module"| node_game_api
node_service -->|"mounts module"| node_admin_api
node_service -->|"starts round loop"| node_round_manager

click node_entry_api "https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/player-entry/presentation/PlayerController.ts"
click node_entry_creation "https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/player-entry/application/use-cases/CreatePlayerEntryUseCase.ts"
click node_entry_store "https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/player-entry/infrastructure/repositories/RedisSessionRepository.ts"
click node_game_api "https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/presentation/GameController.ts"
click node_game_session "https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/application/use-cases/StartGameSessionUseCase.ts"
click node_live_gateway "https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/infrastructure/websocket/GameGateway.ts"
click node_betting "https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/application/use-cases/PlaceBetUseCase.ts"
click node_round_manager "https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/application/services/RoundManager.ts"
click node_round_model "https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/domain/entities/Round.ts"
click node_bet_model "https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/domain/entities/Bet.ts"
click node_result_calc "https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/domain/services/RoundResultService.ts"
click node_round_compute "https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/application/use-cases/ComputeRoundResultUseCase.ts"
click node_reward_distribution "https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/application/use-cases/DistributeRewardsUseCase.ts"
click node_round_storage "https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/infrastructure/repositories/MongoRoundRepository.ts"
click node_bet_storage "https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/infrastructure/repositories/MongoBetRepository.ts"
click node_session_storage "https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/infrastructure/repositories/RedisGameSessionRepository.ts"
click node_bots "https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/infrastructure/bots/BotManager.ts"
click node_webhooks "https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/infrastructure/webhooks/WebhookNotifier.ts"
click node_admin_api "https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/admin/presentation/AdminController.ts"
click node_admin_cases "https://github.com/taskinnasif144/greedy-game-backend/tree/main/src/modules/admin/application/use-cases"
click node_admin_auth "https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/admin/infrastructure/middleware/AdminAuthMiddleware.ts"
click node_player_entity "https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/shared/domain/entities/Player.ts"
click node_timer "https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/shared/application/interfaces/ITimerService.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_entry_api,node_entry_creation,node_entry_store toneBlue
class node_game_api,node_game_session,node_live_gateway,node_betting,node_round_manager,node_round_model,node_bet_model,node_result_calc,node_round_compute,node_reward_distribution,node_round_storage,node_bet_storage,node_session_storage,node_bots,node_webhooks toneAmber
class node_admin_api,node_admin_cases,node_admin_auth toneMint
class node_player_entity,node_timer toneRose
class node_player,node_service toneIndigo
```

## Components

### Player entry

- [Entry API](https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/player-entry/presentation/PlayerController.ts): `src/modules/player-entry/presentation/PlayerController.ts`
- [Create entry session](https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/player-entry/application/use-cases/CreatePlayerEntryUseCase.ts): `src/modules/player-entry/application/use-cases/CreatePlayerEntryUseCase.ts`
- [Entry sessions](https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/player-entry/infrastructure/repositories/RedisSessionRepository.ts): `src/modules/player-entry/infrastructure/repositories/RedisSessionRepository.ts`

### Game runtime

- [Game API](https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/presentation/GameController.ts): `src/modules/game/presentation/GameController.ts`
- [Game sessions](https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/application/use-cases/StartGameSessionUseCase.ts): `src/modules/game/application/use-cases/StartGameSessionUseCase.ts`
- [Live gameplay](https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/infrastructure/websocket/GameGateway.ts): `src/modules/game/infrastructure/websocket/GameGateway.ts`
- [Bet placement](https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/application/use-cases/PlaceBetUseCase.ts): `src/modules/game/application/use-cases/PlaceBetUseCase.ts`
- [Round lifecycle](https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/application/services/RoundManager.ts): `src/modules/game/application/services/RoundManager.ts`
- [Round entity](https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/domain/entities/Round.ts): `src/modules/game/domain/entities/Round.ts`
- [Bet entity](https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/domain/entities/Bet.ts): `src/modules/game/domain/entities/Bet.ts`
- [Result selection](https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/domain/services/RoundResultService.ts): `src/modules/game/domain/services/RoundResultService.ts`
- [Compute result](https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/application/use-cases/ComputeRoundResultUseCase.ts): `src/modules/game/application/use-cases/ComputeRoundResultUseCase.ts`
- [Reward distribution](https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/application/use-cases/DistributeRewardsUseCase.ts): `src/modules/game/application/use-cases/DistributeRewardsUseCase.ts`
- [Round persistence](https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/infrastructure/repositories/MongoRoundRepository.ts): `src/modules/game/infrastructure/repositories/MongoRoundRepository.ts`
- [Bet persistence](https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/infrastructure/repositories/MongoBetRepository.ts): `src/modules/game/infrastructure/repositories/MongoBetRepository.ts`
- [Game sessions](https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/infrastructure/repositories/RedisGameSessionRepository.ts): `src/modules/game/infrastructure/repositories/RedisGameSessionRepository.ts`
- [Bot betting](https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/infrastructure/bots/BotManager.ts): `src/modules/game/infrastructure/bots/BotManager.ts`
- [Webhook notifications](https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/game/infrastructure/webhooks/WebhookNotifier.ts): `src/modules/game/infrastructure/webhooks/WebhookNotifier.ts`

### Administration

- [Admin API](https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/admin/presentation/AdminController.ts): `src/modules/admin/presentation/AdminController.ts`
- [Admin operations](https://github.com/taskinnasif144/greedy-game-backend/tree/main/src/modules/admin/application/use-cases): `src/modules/admin/application/use-cases`
- [Admin authentication](https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/modules/admin/infrastructure/middleware/AdminAuthMiddleware.ts): `src/modules/admin/infrastructure/middleware/AdminAuthMiddleware.ts`

### Shared domain

- [Player entity](https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/shared/domain/entities/Player.ts): `src/shared/domain/entities/Player.ts`
- [Timer service](https://github.com/taskinnasif144/greedy-game-backend/blob/main/src/shared/application/interfaces/ITimerService.ts): `src/shared/application/interfaces/ITimerService.ts`

### Other components

- **Player**
- **Game service**

## Connections

- Player → Entry API: submits entry
- Entry API → Create entry session: invokes (evidence: `src/modules/player-entry/presentation/PlayerController.ts`)
- Create entry session → Entry sessions: stores session
- Entry API → Game API: starts game
- Game API → Game sessions: starts session (evidence: `src/modules/game/presentation/GameController.ts`)
- Game API → Round lifecycle: queries rounds
- Player → Live gameplay: connects
- Live gameplay → Bet placement: places bet
- Bet placement → Game sessions: updates balance
- Round lifecycle → Round entity: creates round (evidence: `src/modules/game/application/services/RoundManager.ts`)
- Round lifecycle → Round persistence: persists round (evidence: `src/modules/game/application/services/RoundManager.ts`)
- Round lifecycle → Bet persistence: cleans bet data (evidence: `src/modules/game/application/services/RoundManager.ts`)
- Round lifecycle → Compute result: computes result (evidence: `src/modules/game/application/services/RoundManager.ts`)
- Round lifecycle → Reward distribution: distributes rewards (evidence: `src/modules/game/application/services/RoundManager.ts`)
- Round lifecycle → Timer service: schedules rounds (evidence: `src/modules/game/application/services/RoundManager.ts`)
- Compute result → Result selection: selects outcome
- Bot betting → Bet placement: places bets (evidence: `src/modules/game/infrastructure/bots/BotManager.ts`)
- Bot betting → Game sessions: creates sessions (evidence: `src/modules/game/infrastructure/bots/BotManager.ts`)
- Admin API → Admin operations: invokes operations (evidence: `src/modules/admin/presentation/AdminController.ts`)
- Admin API → Round lifecycle: pauses game (evidence: `src/modules/admin/presentation/AdminController.ts`)
- Player entity → Game sessions: reconstructed from (evidence: `src/modules/game/infrastructure/repositories/RedisGameSessionRepository.ts`)
- Game service → Entry API: mounts module
- Game service → Game API: mounts module
- Game service → Admin API: mounts module
- Game service → Round lifecycle: starts round loop
