# sspeev/beloteengine architecture

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

- Interactive diagram: https://gitdiagram.com/sspeev/beloteengine
- Repository: https://github.com/sspeev/beloteengine

## Overview

BeloteEngine is a real-time multiplayer Belote game. Players join or create lobbies through HTTP or the SignalR hub; the hub routes gameplay actions to lobby and game services, which manage bidding, card play, validation, trick resolution and scoring over domain state. The README documents broadcasts and the major game phases; the source index supports service and model dependencies. Some listed subsystems were not excerpted, so their internal links are omitted where evidence is unavailable.

Main entry points: [`src/BeloteEngine.Data/Entities/Models/Game.cs`](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Data/Entities/Models/Game.cs) (Game State), [`src/BeloteEngine.Api/Hubs/BeloteHub.cs`](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Api/Hubs/BeloteHub.cs) (Belote Hub), [`src/BeloteEngine.Services/Services/GameService.cs`](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Services/Services/GameService.cs) (Game Service), [`src/BeloteEngine.Services/Services/LobbyService.cs`](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Services/Services/LobbyService.cs) (Lobby Service)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API and Sessions"]
  node_lobby_http["Lobby Endpoints<br/>[LobbyController.cs]"]
  node_session_http["Session Endpoints"]
  node_session_service["Session Service<br/>[SessionService.cs]"]
  node_session_contract["Session Contract<br/>[ISessionService.cs]"]
end

subgraph group_realtime["Realtime Play"]
  node_hub["Belote Hub<br/>[BeloteHub.cs]"]
  node_client_contract["Client Callbacks<br/>[IBeloteClient.cs]"]
  node_afk_service["AFK Timer<br/>[AfkTimerService.cs]"]
end

subgraph group_services["Lobby and Game Services"]
  node_lobby_service["Lobby Service<br/>[LobbyService.cs]"]
  node_game_service["Game Service<br/>[GameService.cs]"]
  node_lobby_contract["Lobby Contract<br/>[ILobbyService.cs]"]
  node_game_contract["Game Contract<br/>[IGameService.cs]"]
  node_cache["In-memory Cache<br/>[CacheService.cs]"]
  node_limiter["Connection Limiter"]
end

subgraph group_rules["Game Rules"]
  node_input_validator["Input Validator<br/>[InputValidator.cs]"]
  node_play_validator["Play Validator<br/>[PlayValidator.cs]"]
  node_trick_evaluator["Trick Evaluator<br/>[TrickEvaluator.cs]"]
  node_score_calculator["Score Calculator<br/>[ScoreCalculator.cs]"]
end

subgraph group_domain["Game Domain"]
  node_lobby_model["Lobby State<br/>[Lobby.cs]"]
  node_game_model["Game State<br/>[Game.cs]"]
  node_player_model["Player State<br/>[Player.cs]"]
  node_round_model["Round State<br/>[Round.cs]"]
  node_trick_model["Trick State<br/>[Trick.cs]"]
  node_deck_model["Card Deck<br/>[Deck.cs]"]
  node_card_model["Card<br/>[Card.cs]"]
  node_team_model["Team<br/>[Team.cs]"]
  node_played_card_model["Played Card<br/>[PlayedCard.cs]"]
  node_announce_enum["Announce Types<br/>[Announces.cs]"]
  node_suit_enum["Suit Types<br/>[Suit.cs]"]
end

node_browser(("Browser Player"))

node_browser -->|"requests lobby"| node_lobby_http
node_browser -->|"manages session"| node_session_http
node_session_http -->|"uses session"| node_session_service
node_session_service -->|"implements"| node_session_contract
node_session_http -->|"validates input"| node_input_validator
node_browser -->|"plays in realtime"| node_hub
node_lobby_http -->|"manages lobby"| node_lobby_service
node_hub -->|"routes lobby actions"| node_lobby_service
node_hub -->|"routes game actions"| node_game_service
node_hub -->|"checks connections"| node_limiter
node_hub -->|"uses AFK timer"| node_afk_service
node_hub -->|"checks sessions"| node_session_service
node_hub -->|"broadcasts updates"| node_client_contract
node_lobby_service -->|"starts games"| node_game_service
node_lobby_service -->|"sanitizes names"| node_input_validator
node_game_service -->|"validates plays"| node_play_validator
node_game_service -->|"evaluates tricks"| node_trick_evaluator
node_game_service -->|"calculates scores"| node_score_calculator
node_lobby_service -->|"updates state"| node_lobby_model
node_game_service -->|"updates state"| node_game_model
node_lobby_model -->|"contains players"| node_player_model
node_lobby_model -->|"holds game"| node_game_model
node_game_model -->|"tracks players"| node_player_model
node_game_model -->|"holds deck"| node_deck_model
node_game_model -->|"tracks round"| node_round_model
node_game_model -->|"tracks trick"| node_trick_model
node_game_model -->|"tracks teams"| node_team_model
node_deck_model -->|"creates cards"| node_card_model
node_card_model -->|"uses suit"| node_suit_enum
node_game_model -->|"uses bids"| node_announce_enum
node_game_model -->|"uses suits"| node_suit_enum

click node_lobby_http "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Api/Controllers/LobbyController.cs"
click node_session_http "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Api/Controllers/SessionController.cs"
click node_session_service "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Api/Services/SessionService.cs"
click node_session_contract "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Api/Contracts/ISessionService.cs"
click node_hub "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Api/Hubs/BeloteHub.cs"
click node_client_contract "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Api/Hubs/IBeloteClient.cs"
click node_afk_service "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Api/Services/AfkTimerService.cs"
click node_lobby_service "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Services/Services/LobbyService.cs"
click node_game_service "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Services/Services/GameService.cs"
click node_lobby_contract "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Services/Contracts/ILobbyService.cs"
click node_game_contract "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Services/Contracts/IGameService.cs"
click node_cache "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Services/Services/CacheService.cs"
click node_limiter "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Services/Services/ConnectionLimiter.cs"
click node_input_validator "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Services/Security/InputValidator.cs"
click node_play_validator "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Services/Rules/PlayValidator.cs"
click node_trick_evaluator "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Services/Rules/TrickEvaluator.cs"
click node_score_calculator "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Services/Rules/ScoreCalculator.cs"
click node_lobby_model "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Data/Entities/Models/Lobby.cs"
click node_game_model "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Data/Entities/Models/Game.cs"
click node_player_model "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Data/Entities/Models/Player.cs"
click node_round_model "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Data/Entities/Models/Round.cs"
click node_trick_model "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Data/Entities/Models/Trick.cs"
click node_deck_model "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Data/Entities/Models/Deck.cs"
click node_card_model "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Data/Entities/Models/Card.cs"
click node_team_model "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Data/Entities/Models/Team.cs"
click node_played_card_model "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Data/Entities/Models/PlayedCard.cs"
click node_announce_enum "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Data/Entities/Enums/Announces.cs"
click node_suit_enum "https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Data/Entities/Enums/Suit.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_lobby_http,node_session_http,node_session_service,node_session_contract,node_browser toneBlue
class node_hub,node_client_contract,node_afk_service toneAmber
class node_lobby_service,node_game_service,node_lobby_contract,node_game_contract,node_cache,node_limiter toneMint
class node_input_validator,node_play_validator,node_trick_evaluator,node_score_calculator toneRose
class node_lobby_model,node_game_model,node_player_model,node_round_model,node_trick_model,node_deck_model,node_card_model,node_team_model,node_played_card_model,node_announce_enum,node_suit_enum toneIndigo
```

## Components

### API and Sessions

- [Lobby Endpoints](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Api/Controllers/LobbyController.cs): `src/BeloteEngine.Api/Controllers/LobbyController.cs`
- [Session Endpoints](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Api/Controllers/SessionController.cs): `src/BeloteEngine.Api/Controllers/SessionController.cs`
- [Session Service](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Api/Services/SessionService.cs): `src/BeloteEngine.Api/Services/SessionService.cs`
- [Session Contract](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Api/Contracts/ISessionService.cs): `src/BeloteEngine.Api/Contracts/ISessionService.cs`

### Realtime Play

- [Belote Hub](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Api/Hubs/BeloteHub.cs): `src/BeloteEngine.Api/Hubs/BeloteHub.cs`
- [Client Callbacks](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Api/Hubs/IBeloteClient.cs): `src/BeloteEngine.Api/Hubs/IBeloteClient.cs`
- [AFK Timer](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Api/Services/AfkTimerService.cs): `src/BeloteEngine.Api/Services/AfkTimerService.cs`

### Lobby and Game Services

- [Lobby Service](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Services/Services/LobbyService.cs): `src/BeloteEngine.Services/Services/LobbyService.cs`
- [Game Service](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Services/Services/GameService.cs): `src/BeloteEngine.Services/Services/GameService.cs`
- [Lobby Contract](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Services/Contracts/ILobbyService.cs): `src/BeloteEngine.Services/Contracts/ILobbyService.cs`
- [Game Contract](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Services/Contracts/IGameService.cs): `src/BeloteEngine.Services/Contracts/IGameService.cs`
- [In-memory Cache](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Services/Services/CacheService.cs): `src/BeloteEngine.Services/Services/CacheService.cs`
- [Connection Limiter](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Services/Services/ConnectionLimiter.cs): `src/BeloteEngine.Services/Services/ConnectionLimiter.cs`

### Game Rules

- [Input Validator](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Services/Security/InputValidator.cs): `src/BeloteEngine.Services/Security/InputValidator.cs`
- [Play Validator](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Services/Rules/PlayValidator.cs): `src/BeloteEngine.Services/Rules/PlayValidator.cs`
- [Trick Evaluator](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Services/Rules/TrickEvaluator.cs): `src/BeloteEngine.Services/Rules/TrickEvaluator.cs`
- [Score Calculator](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Services/Rules/ScoreCalculator.cs): `src/BeloteEngine.Services/Rules/ScoreCalculator.cs`

### Game Domain

- [Lobby State](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Data/Entities/Models/Lobby.cs): `src/BeloteEngine.Data/Entities/Models/Lobby.cs`
- [Game State](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Data/Entities/Models/Game.cs): `src/BeloteEngine.Data/Entities/Models/Game.cs`
- [Player State](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Data/Entities/Models/Player.cs): `src/BeloteEngine.Data/Entities/Models/Player.cs`
- [Round State](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Data/Entities/Models/Round.cs): `src/BeloteEngine.Data/Entities/Models/Round.cs`
- [Trick State](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Data/Entities/Models/Trick.cs): `src/BeloteEngine.Data/Entities/Models/Trick.cs`
- [Card Deck](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Data/Entities/Models/Deck.cs): `src/BeloteEngine.Data/Entities/Models/Deck.cs`
- [Card](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Data/Entities/Models/Card.cs): `src/BeloteEngine.Data/Entities/Models/Card.cs`
- [Team](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Data/Entities/Models/Team.cs): `src/BeloteEngine.Data/Entities/Models/Team.cs`
- [Played Card](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Data/Entities/Models/PlayedCard.cs): `src/BeloteEngine.Data/Entities/Models/PlayedCard.cs`
- [Announce Types](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Data/Entities/Enums/Announces.cs): `src/BeloteEngine.Data/Entities/Enums/Announces.cs`
- [Suit Types](https://github.com/sspeev/beloteengine/blob/main/src/BeloteEngine.Data/Entities/Enums/Suit.cs): `src/BeloteEngine.Data/Entities/Enums/Suit.cs`

### Other components

- **Browser Player**

## Connections

- Browser Player → Lobby Endpoints: requests lobby
- Browser Player → Session Endpoints: manages session (evidence: `src/BeloteEngine.Api/Controllers/SessionController.cs`)
- Session Endpoints → Session Service: uses session (evidence: `src/BeloteEngine.Api/Controllers/SessionController.cs`)
- Session Service → Session Contract: implements (evidence: `src/BeloteEngine.Api/Services/SessionService.cs`)
- Session Endpoints → Input Validator: validates input (evidence: `src/BeloteEngine.Api/Controllers/SessionController.cs`)
- Browser Player → Belote Hub: plays in realtime
- Lobby Endpoints → Lobby Service: manages lobby (evidence: `src/BeloteEngine.Api/Controllers/LobbyController.cs`)
- Belote Hub → Lobby Service: routes lobby actions (evidence: `src/BeloteEngine.Api/Hubs/BeloteHub.cs`)
- Belote Hub → Game Service: routes game actions (evidence: `src/BeloteEngine.Api/Hubs/BeloteHub.cs`)
- Belote Hub → Connection Limiter: checks connections (evidence: `src/BeloteEngine.Api/Hubs/BeloteHub.cs`)
- Belote Hub → AFK Timer: uses AFK timer (evidence: `src/BeloteEngine.Api/Hubs/BeloteHub.cs`)
- Belote Hub → Session Service: checks sessions (evidence: `src/BeloteEngine.Api/Hubs/BeloteHub.cs`)
- Belote Hub → Client Callbacks: broadcasts updates (evidence: `src/BeloteEngine.Api/Hubs/BeloteHub.cs`)
- Lobby Service → Game Service: starts games (evidence: `src/BeloteEngine.Services/Services/LobbyService.cs`)
- Lobby Service → Input Validator: sanitizes names (evidence: `src/BeloteEngine.Services/Services/LobbyService.cs`)
- Game Service → Play Validator: validates plays (evidence: `src/BeloteEngine.Services/Services/GameService.cs`)
- Game Service → Trick Evaluator: evaluates tricks (evidence: `src/BeloteEngine.Services/Services/GameService.cs`)
- Game Service → Score Calculator: calculates scores (evidence: `src/BeloteEngine.Services/Services/GameService.cs`)
- Lobby Service → Lobby State: updates state (evidence: `src/BeloteEngine.Services/Services/LobbyService.cs`)
- Game Service → Game State: updates state (evidence: `src/BeloteEngine.Services/Services/GameService.cs`)
- Lobby State → Player State: contains players (evidence: `src/BeloteEngine.Data/Entities/Models/Lobby.cs`)
- Lobby State → Game State: holds game (evidence: `src/BeloteEngine.Data/Entities/Models/Lobby.cs`)
- Game State → Player State: tracks players (evidence: `src/BeloteEngine.Data/Entities/Models/Game.cs`)
- Game State → Card Deck: holds deck (evidence: `src/BeloteEngine.Data/Entities/Models/Game.cs`)
- Game State → Round State: tracks round (evidence: `src/BeloteEngine.Data/Entities/Models/Game.cs`)
- Game State → Trick State: tracks trick (evidence: `src/BeloteEngine.Data/Entities/Models/Game.cs`)
- Game State → Team: tracks teams (evidence: `src/BeloteEngine.Data/Entities/Models/Game.cs`)
- Card Deck → Card: creates cards (evidence: `src/BeloteEngine.Data/Entities/Models/Deck.cs`)
- Card → Suit Types: uses suit (evidence: `src/BeloteEngine.Data/Entities/Models/Card.cs`)
- Game State → Announce Types: uses bids (evidence: `src/BeloteEngine.Data/Entities/Models/Game.cs`)
- Game State → Suit Types: uses suits (evidence: `src/BeloteEngine.Data/Entities/Models/Game.cs`)
