# zimbadev/crystalserver architecture

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

- Interactive diagram: https://gitdiagram.com/zimbadev/crystalserver
- Repository: https://github.com/zimbadev/crystalserver

## Overview

Crystal Server is a C++ MMORPG server emulator; a game client connects to it to play. The principal runtime path is client networking into game handling, which operates on players, creatures, items, and the world map; Lua supplies extensible gameplay behavior. Account and player data are persisted through database and I/O services, with scheduled saves as an internal lifecycle layer. The README also identifies multiworld support. Source excerpts are selective, so several gameplay and protocol links are shown only as unverified rather than asserted calls.

Main entry points: [`src/game/game.cpp`](https://github.com/zimbadev/crystalserver/blob/main/src/game/game.cpp) (Game coordinator), [`src/game/scheduling/save_manager.cpp`](https://github.com/zimbadev/crystalserver/blob/main/src/game/scheduling/save_manager.cpp) (Scheduled saves), [`src/creatures/players/player.cpp`](https://github.com/zimbadev/crystalserver/blob/main/src/creatures/players/player.cpp) (Player state), [`src/database/database.cpp`](https://github.com/zimbadev/crystalserver/blob/main/src/database/database.cpp) (Database access)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Server runtime"]
  node_server["Network server<br/>[server.cpp]"]
  node_protocol["Game protocol<br/>[protocolgame.cpp]"]
end

subgraph group_world["World and gameplay"]
  node_game["Game coordinator<br/>[game.cpp]"]
  node_player["Player state<br/>[player.cpp]"]
  node_creatures["Creature systems<br/>[creature.cpp]"]
  node_monsters["Monster management<br/>[monsters.hpp]"]
  node_items["Items and containers<br/>[item.cpp]"]
  node_map["World map<br/>[map.cpp]"]
  node_weekly["Weekly tasks<br/>[ioweeklytasks.cpp]"]
  node_worlds["Multiworld support<br/>[gameworlds.cpp]"]
end

subgraph group_scripting["Lua scripting"]
  node_lua["Lua runtime<br/>[luascript.cpp]"]
  node_lua_bindings["Lua game bindings"]
end

subgraph group_persistence["Persistence"]
  node_accounts["Account repository"]
  node_database[("Database access<br/>[database.cpp]")]
  node_db_manager["Database management"]
  node_player_io["Player load and save"]
end

subgraph group_operations["Configuration and services"]
  node_save_manager["Scheduled saves<br/>[save_manager.cpp]"]
  node_dispatcher["Task dispatcher<br/>[dispatcher.hpp]"]
  node_config["Configuration<br/>[configmanager.cpp]"]
  node_webhook["Webhook integration<br/>[webhook.cpp]"]
end

node_client(("Game client"))

node_client -->|"connects to"| node_server
node_server -.->|"routes through"| node_protocol
node_protocol -.->|"dispatches gameplay"| node_game
node_game -->|"manages players"| node_player
node_game -->|"uses map"| node_map
node_game -.->|"manages creatures"| node_creatures
node_game -.->|"handles items"| node_items
node_game -->|"uses monster systems"| node_monsters
node_player -->|"tracks tasks"| node_weekly
node_lua -.->|"loads bindings"| node_lua_bindings
node_lua_bindings -.->|"exposes game operations"| node_game
node_accounts -->|"queries and updates"| node_database
node_db_manager -->|"checks and migrates"| node_database
node_save_manager -->|"saves player state"| node_player
node_save_manager -->|"delegates player save"| node_player_io
node_save_manager -.->|"saves key-value data"| node_database
node_save_manager -.->|"schedules work"| node_dispatcher
node_config -->|"configures runtime"| node_game
node_config -->|"configures webhook"| node_webhook
node_game -->|"uses world registry"| node_worlds
node_weekly -->|"persists task data"| node_database
node_weekly -->|"updates task progress"| node_player

click node_server "https://github.com/zimbadev/crystalserver/blob/main/src/server/server.cpp"
click node_protocol "https://github.com/zimbadev/crystalserver/blob/main/src/server/network/protocol/protocolgame.cpp"
click node_game "https://github.com/zimbadev/crystalserver/blob/main/src/game/game.cpp"
click node_player "https://github.com/zimbadev/crystalserver/blob/main/src/creatures/players/player.cpp"
click node_creatures "https://github.com/zimbadev/crystalserver/blob/main/src/creatures/creature.cpp"
click node_monsters "https://github.com/zimbadev/crystalserver/blob/main/src/creatures/monsters/monsters.hpp"
click node_items "https://github.com/zimbadev/crystalserver/blob/main/src/items/item.cpp"
click node_map "https://github.com/zimbadev/crystalserver/blob/main/src/map/map.cpp"
click node_weekly "https://github.com/zimbadev/crystalserver/blob/main/src/io/ioweeklytasks.cpp"
click node_lua "https://github.com/zimbadev/crystalserver/blob/main/src/lua/scripts/luascript.cpp"
click node_lua_bindings "https://github.com/zimbadev/crystalserver/blob/main/src/lua/functions/lua_functions_loader.cpp"
click node_accounts "https://github.com/zimbadev/crystalserver/blob/main/src/account/account_repository_db.cpp"
click node_database "https://github.com/zimbadev/crystalserver/blob/main/src/database/database.cpp"
click node_db_manager "https://github.com/zimbadev/crystalserver/blob/main/src/database/databasemanager.cpp"
click node_player_io "https://github.com/zimbadev/crystalserver/blob/main/src/io/functions/iologindata_save_player.cpp"
click node_save_manager "https://github.com/zimbadev/crystalserver/blob/main/src/game/scheduling/save_manager.cpp"
click node_dispatcher "https://github.com/zimbadev/crystalserver/blob/main/src/game/scheduling/dispatcher.hpp"
click node_config "https://github.com/zimbadev/crystalserver/blob/main/src/config/configmanager.cpp"
click node_worlds "https://github.com/zimbadev/crystalserver/blob/main/src/game/worlds/gameworlds.cpp"
click node_webhook "https://github.com/zimbadev/crystalserver/blob/main/src/server/network/webhook/webhook.cpp"

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_server,node_protocol,node_client toneBlue
class node_game,node_player,node_creatures,node_monsters,node_items,node_map,node_weekly,node_worlds toneAmber
class node_lua,node_lua_bindings toneMint
class node_accounts,node_database,node_db_manager,node_player_io toneRose
class node_save_manager,node_dispatcher,node_config,node_webhook toneIndigo
```

## Components

### Server runtime

- [Network server](https://github.com/zimbadev/crystalserver/blob/main/src/server/server.cpp): `src/server/server.cpp`
- [Game protocol](https://github.com/zimbadev/crystalserver/blob/main/src/server/network/protocol/protocolgame.cpp): `src/server/network/protocol/protocolgame.cpp`

### World and gameplay

- [Game coordinator](https://github.com/zimbadev/crystalserver/blob/main/src/game/game.cpp): `src/game/game.cpp`
- [Player state](https://github.com/zimbadev/crystalserver/blob/main/src/creatures/players/player.cpp): `src/creatures/players/player.cpp`
- [Creature systems](https://github.com/zimbadev/crystalserver/blob/main/src/creatures/creature.cpp): `src/creatures/creature.cpp`
- [Monster management](https://github.com/zimbadev/crystalserver/blob/main/src/creatures/monsters/monsters.hpp): `src/creatures/monsters/monsters.hpp`
- [Items and containers](https://github.com/zimbadev/crystalserver/blob/main/src/items/item.cpp): `src/items/item.cpp`
- [World map](https://github.com/zimbadev/crystalserver/blob/main/src/map/map.cpp): `src/map/map.cpp`
- [Weekly tasks](https://github.com/zimbadev/crystalserver/blob/main/src/io/ioweeklytasks.cpp): `src/io/ioweeklytasks.cpp`
- [Multiworld support](https://github.com/zimbadev/crystalserver/blob/main/src/game/worlds/gameworlds.cpp): `src/game/worlds/gameworlds.cpp`

### Lua scripting

- [Lua runtime](https://github.com/zimbadev/crystalserver/blob/main/src/lua/scripts/luascript.cpp): `src/lua/scripts/luascript.cpp`
- [Lua game bindings](https://github.com/zimbadev/crystalserver/blob/main/src/lua/functions/lua_functions_loader.cpp): `src/lua/functions/lua_functions_loader.cpp`

### Persistence

- [Account repository](https://github.com/zimbadev/crystalserver/blob/main/src/account/account_repository_db.cpp): `src/account/account_repository_db.cpp`
- [Database access](https://github.com/zimbadev/crystalserver/blob/main/src/database/database.cpp): `src/database/database.cpp`
- [Database management](https://github.com/zimbadev/crystalserver/blob/main/src/database/databasemanager.cpp): `src/database/databasemanager.cpp`
- [Player load and save](https://github.com/zimbadev/crystalserver/blob/main/src/io/functions/iologindata_save_player.cpp): `src/io/functions/iologindata_save_player.cpp`

### Configuration and services

- [Scheduled saves](https://github.com/zimbadev/crystalserver/blob/main/src/game/scheduling/save_manager.cpp): `src/game/scheduling/save_manager.cpp`
- [Task dispatcher](https://github.com/zimbadev/crystalserver/blob/main/src/game/scheduling/dispatcher.hpp): `src/game/scheduling/dispatcher.hpp`
- [Configuration](https://github.com/zimbadev/crystalserver/blob/main/src/config/configmanager.cpp): `src/config/configmanager.cpp`
- [Webhook integration](https://github.com/zimbadev/crystalserver/blob/main/src/server/network/webhook/webhook.cpp): `src/server/network/webhook/webhook.cpp`

### Other components

- **Game client**

## Connections

- Game client → Network server: connects to (evidence: `README.md`)
- Network server → Game protocol: routes through
- Game protocol → Game coordinator: dispatches gameplay
- Game coordinator → Player state: manages players
- Game coordinator → World map: uses map
- Game coordinator → Creature systems: manages creatures
- Game coordinator → Items and containers: handles items
- Game coordinator → Monster management: uses monster systems
- Player state → Weekly tasks: tracks tasks (evidence: `src/io/ioweeklytasks.cpp`)
- Lua runtime → Lua game bindings: loads bindings
- Lua game bindings → Game coordinator: exposes game operations
- Account repository → Database access: queries and updates (evidence: `src/account/account_repository_db.cpp`)
- Database management → Database access: checks and migrates (evidence: `src/database/databasemanager.cpp`)
- Scheduled saves → Player state: saves player state (evidence: `src/game/scheduling/save_manager.cpp`)
- Scheduled saves → Player load and save: delegates player save (evidence: `src/game/scheduling/save_manager.cpp`)
- Scheduled saves → Database access: saves key-value data
- Scheduled saves → Task dispatcher: schedules work
- Configuration → Game coordinator: configures runtime (evidence: `src/config/configmanager.cpp`)
- Configuration → Webhook integration: configures webhook (evidence: `src/config/configmanager.cpp`)
- Game coordinator → Multiworld support: uses world registry
- Weekly tasks → Database access: persists task data (evidence: `src/io/ioweeklytasks.cpp`)
- Weekly tasks → Player state: updates task progress
