# herculesws/hercules architecture

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

- Interactive diagram: https://gitdiagram.com/herculesws/hercules
- Repository: https://github.com/herculesws/hercules

## Overview

#### Purpose and runtime topology
Hercules is a C-based MMORPG server package descended from Athena. It runs as cooperating server processes rather than a web application: login authentication, character/account coordination, authoritative map/game simulation, and an optional HTTP API. Build targets are defined by `CMakeLists.txt` and `src/CMakeLists.txt`; operational launchers include `login-server.sh`, `char-server.sh`, `map-server.sh`, and `api-server.sh`.

#### Process entry points and control flow
1. **Login server** accepts client authentication, manages accounts and IP bans, then directs authenticated users onward. Core boundary: `src/login/login.c`, `src/login/account.c`, `src/login/ipban.c`.
2. **Character server** owns character-selection and inter-server persistence services; it mediates login↔map communication and manages durable features such as parties, guilds, mail, storage, and quests. Core paths: `src/char/char.c`, `src/char/inter.c`, `src/char/mapif.c`.
3. **Map server** is the gameplay authority: client packets enter through its client interface, then drive player, combat, skill, map, NPC, and world systems. Core paths: `src/map/map.c`, `src/map/clif.c`, `src/map/pc.c`.
4. Inter-process socket protocols separate login, character, and map responsibilities; packet contracts are centralized in `src/common/charloginpackets.h`, `src/common/charmappackets.h`, and `src/common/mapcharpackets.h`.

#### Map simulation and game domain
The map server is the largest bounded context. It combines spatial/map management, pathfinding, units, player state, mobs, items, statuses, and combat rules. Key implementation anchors are `src/map/map.c`, `src/map/path.c`, `src/map/unit.c`, `src/map/mob.c`, `src/map/status.c`, `src/map/battle.c`, `src/map/skill.c`, and `src/map/itemdb.c`. Client-version packet compatibility is a material integration boundary, represented by `src/map/packets.h` and versioned packet tables under `src/common/packets/`.

#### Content loading and scripting boundary
Runtime behavior is heavily data-driven. Server startup loads game database definitions from `db/`, collision/navigation map caches from `maps/re/` or `maps/pre-re/`, and NPC scripts from `npc/`. The NPC scripting VM and parser are in `src/map/script.c` and `src/map/npc.c`; script inclusion roots are `npc/scripts.conf` and the ruleset-specific `npc/re/scripts.conf` / `npc/pre-re/scripts.conf`. Renewal (`re`) and pre-renewal (`pre-re`) are parallel content variants across database, NPC, and map-cache assets.

#### Persistence and configuration
MariaDB/MySQL is the primary external state store, configured through `conf/global/sql_connection.conf`; baseline schemas and migrations are under `sql-files/main.sql`, `sql-files/logs.sql`, and `sql-files/upgrades/`. The character and map services use SQL-facing persistence layers such as `src/char/inter.c` and `src/map/mapreg_sql.c`; common SQL abstraction is `src/common/sql.c`. Process-specific networking and behavior are configured in `conf/login/login-server.conf`, `conf/char/char-server.conf`, and `conf/map/map-server.conf`, with import templates supporting local overrides.

#### HTTP API and extensibility
The optional API server is a separate HTTP runtime with request parsing, routing/handlers, JSON serialization, and interfaces to the account/character side. Its core is `src/api/api.c`, `src/api/httpparser.c`, `src/api/handlers.c`, and `src/api/jsonwriter.c`; configuration is `conf/api/api-server.conf`. HTTP parsing depends on vendored parsers in `3rdparty/llhttp/` and `3rdparty/multipart-parser/`. The Hercules Plugin Manager provides native extension hooks across server processes through `src/common/HPM.c`, `src/plugins/HPMHooking/HPMHooking.c`, and per-process `HPM*` modules.

#### Shared platform layer and delivery
`src/common/` supplies lifecycle, sockets, timers, threading, configuration parsing, logging, memory management, packet primitives, and database access; architectural anchors are `src/common/core.c`, `src/common/socket.c`, `src/common/timer.c`, and `src/common/conf.c`. The project builds with CMake across GCC, Clang, and MSVC, and vendors libconfig plus protocol parsers in `3rdparty/`. CI covers these platform/database combinations through workflows including `.github/workflows/build.yml`, `.github/workflows/mariadb.yml`, and `.github/workflows/mysql.yml`.

Main entry points: [`src/map/map.c`](https://github.com/herculesws/hercules/blob/stable/src/map/map.c) (Map simulation), [`src/char/char.c`](https://github.com/herculesws/hercules/blob/stable/src/char/char.c) (Character server), [`src/login/login.c`](https://github.com/herculesws/hercules/blob/stable/src/login/login.c) (Login server), [`src/common/core.c`](https://github.com/herculesws/hercules/blob/stable/src/common/core.c) (Common platform)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtimes["Server runtimes"]
  node_login{{"Login server<br/>auth runtime<br/>[login.c]"}}
  node_character{{"Character server<br/>coordination runtime<br/>[char.c]"}}
  node_map_gateway["Map client interface<br/>packet gateway<br/>[clif.c]"]
  node_api{{"API server<br/>HTTP runtime<br/>[api.c]"}}
end

subgraph group_map_domain["Map gameplay"]
  node_map_simulation{{"Map simulation<br/>game authority<br/>[map.c]"}}
  node_world_navigation["World navigation<br/>spatial subsystem<br/>[path.c]"]
  node_npc_scripting["NPC scripting<br/>script VM<br/>[script.c]"]
  node_game_content["Ruleset content<br/>runtime assets"]
end

subgraph group_shared["Shared platform"]
  node_packet_contracts["Inter-server contracts<br/>packet definitions<br/>[charloginpackets.h]"]
  node_common_platform["Common platform<br/>native runtime layer<br/>[core.c]"]
  node_plugins["Plugin manager<br/>extension framework<br/>[HPM.c]"]
end

subgraph group_state["Persistence"]
  node_sql_persistence["SQL persistence<br/>data access layer<br/>[inter.c]"]
  node_mariadb[("MariaDB/MySQL<br/>external database")]
  node_schema_migrations["Schemas &amp; migrations<br/>SQL assets<br/>[main.sql]"]
end

node_build["CMake build<br/>build system<br/>[CMakeLists.txt]"]
node_server_config["Server configuration<br/>operational config<br/>[login-server.conf]"]

node_build -->|"builds"| node_login
node_build -->|"builds"| node_character
node_build -->|"builds"| node_map_simulation
node_build -->|"builds"| node_api
node_login -->|"authenticated sessions"| node_character
node_character -->|"map handoff"| node_map_simulation
node_packet_contracts -.->|"protocol"| node_login
node_packet_contracts -.->|"protocol"| node_character
node_packet_contracts -.->|"protocol"| node_map_simulation
node_map_gateway -->|"client actions"| node_map_simulation
node_map_simulation -->|"spatial queries"| node_world_navigation
node_map_simulation -->|"script events"| node_npc_scripting
node_game_content -->|"loads definitions"| node_map_simulation
node_game_content -->|"loads map caches"| node_world_navigation
node_game_content -->|"loads NPC scripts"| node_npc_scripting
node_character -->|"characters and services"| node_sql_persistence
node_map_simulation -->|"map state"| node_sql_persistence
node_sql_persistence -->|"SQL"| node_mariadb
node_schema_migrations -->|"initializes and upgrades"| node_mariadb
node_api -->|"account/character interface"| node_character
node_common_platform -.->|"runtime services"| node_login
node_common_platform -.->|"runtime services"| node_character
node_common_platform -.->|"runtime services"| node_map_simulation
node_common_platform -.->|"runtime services"| node_api
node_plugins -.->|"native hooks"| node_login
node_plugins -.->|"native hooks"| node_character
node_plugins -.->|"native hooks"| node_map_simulation
node_server_config -.->|"configures"| node_login
node_server_config -.->|"configures"| node_character
node_server_config -.->|"configures"| node_map_simulation

click node_build "https://github.com/herculesws/hercules/blob/stable/CMakeLists.txt"
click node_login "https://github.com/herculesws/hercules/blob/stable/src/login/login.c"
click node_character "https://github.com/herculesws/hercules/blob/stable/src/char/char.c"
click node_map_gateway "https://github.com/herculesws/hercules/blob/stable/src/map/clif.c"
click node_map_simulation "https://github.com/herculesws/hercules/blob/stable/src/map/map.c"
click node_world_navigation "https://github.com/herculesws/hercules/blob/stable/src/map/path.c"
click node_npc_scripting "https://github.com/herculesws/hercules/blob/stable/src/map/script.c"
click node_api "https://github.com/herculesws/hercules/blob/stable/src/api/api.c"
click node_packet_contracts "https://github.com/herculesws/hercules/blob/stable/src/common/charloginpackets.h"
click node_common_platform "https://github.com/herculesws/hercules/blob/stable/src/common/core.c"
click node_plugins "https://github.com/herculesws/hercules/blob/stable/src/common/HPM.c"
click node_sql_persistence "https://github.com/herculesws/hercules/blob/stable/src/char/inter.c"
click node_mariadb "https://github.com/herculesws/hercules/blob/stable/conf/global/sql_connection.conf"
click node_schema_migrations "https://github.com/herculesws/hercules/blob/stable/sql-files/main.sql"
click node_server_config "https://github.com/herculesws/hercules/blob/stable/conf/login/login-server.conf"

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_login,node_character,node_map_gateway,node_api toneBlue
class node_map_simulation,node_world_navigation,node_npc_scripting,node_game_content toneAmber
class node_packet_contracts,node_common_platform,node_plugins toneMint
class node_sql_persistence,node_mariadb,node_schema_migrations toneRose
class node_build,node_server_config toneNeutral
```

## Components

### Server runtimes

Cooperating native server processes.

- [Login server](https://github.com/herculesws/hercules/blob/stable/src/login/login.c): auth runtime · Authenticates clients and enforces account/IP policies. · `src/login/login.c`
- [Character server](https://github.com/herculesws/hercules/blob/stable/src/char/char.c): coordination runtime · Owns character selection and inter-server persistence. · `src/char/char.c`
- [Map client interface](https://github.com/herculesws/hercules/blob/stable/src/map/clif.c): packet gateway · Accepts gameplay client packets. · `src/map/clif.c`
- [API server](https://github.com/herculesws/hercules/blob/stable/src/api/api.c): HTTP runtime · Optional HTTP routing, handlers, and JSON responses. · `src/api/api.c`

### Map gameplay

Authoritative game simulation and data-driven behavior.

- [Map simulation](https://github.com/herculesws/hercules/blob/stable/src/map/map.c): game authority · Runs player, combat, skill, unit, and world rules. · `src/map/map.c`
- [World navigation](https://github.com/herculesws/hercules/blob/stable/src/map/path.c): spatial subsystem · Manages maps, collision data, and pathfinding. · `src/map/path.c`
- [NPC scripting](https://github.com/herculesws/hercules/blob/stable/src/map/script.c): script VM · Parses and executes NPC-driven gameplay. · `src/map/script.c`
- **Ruleset content**: runtime assets · Parallel renewal and pre-renewal databases, NPCs, and map caches.

### Shared platform

Common runtime services and protocol contracts.

- [Inter-server contracts](https://github.com/herculesws/hercules/blob/stable/src/common/charloginpackets.h): packet definitions · Login/char/map socket protocol contracts. · `src/common/charloginpackets.h`
- [Common platform](https://github.com/herculesws/hercules/blob/stable/src/common/core.c): native runtime layer · Lifecycle, sockets, timers, configuration, logging, and SQL abstractions. · `src/common/core.c`
- [Plugin manager](https://github.com/herculesws/hercules/blob/stable/src/common/HPM.c): extension framework · Native hooks available across server processes. · `src/common/HPM.c`

### Persistence

SQL-backed durable state and schema assets.

- [SQL persistence](https://github.com/herculesws/hercules/blob/stable/src/char/inter.c): data access layer · Character and map persistence over the shared SQL abstraction. · `src/char/inter.c`
- [MariaDB/MySQL](https://github.com/herculesws/hercules/blob/stable/conf/global/sql_connection.conf): external database · Primary durable account and game state store. · `conf/global/sql_connection.conf`
- [Schemas & migrations](https://github.com/herculesws/hercules/blob/stable/sql-files/main.sql): SQL assets · `sql-files/main.sql`

### Other components

- [CMake build](https://github.com/herculesws/hercules/blob/stable/CMakeLists.txt): build system · `CMakeLists.txt`
- [Server configuration](https://github.com/herculesws/hercules/blob/stable/conf/login/login-server.conf): operational config · Per-process networking and behavior settings. · `conf/login/login-server.conf`

## Connections

- CMake build → Login server: builds
- CMake build → Character server: builds
- CMake build → Map simulation: builds
- CMake build → API server: builds
- Login server → Character server: authenticated sessions
- Character server → Map simulation: map handoff
- Inter-server contracts → Login server: protocol
- Inter-server contracts → Character server: protocol
- Inter-server contracts → Map simulation: protocol
- Map client interface → Map simulation: client actions
- Map simulation → World navigation: spatial queries
- Map simulation → NPC scripting: script events
- Ruleset content → Map simulation: loads definitions
- Ruleset content → World navigation: loads map caches
- Ruleset content → NPC scripting: loads NPC scripts
- Character server → SQL persistence: characters and services
- Map simulation → SQL persistence: map state
- SQL persistence → MariaDB/MySQL: SQL
- Schemas & migrations → MariaDB/MySQL: initializes and upgrades
- API server → Character server: account/character interface
- Common platform → Login server: runtime services
- Common platform → Character server: runtime services
- Common platform → Map simulation: runtime services
- Common platform → API server: runtime services
- Plugin manager → Login server: native hooks
- Plugin manager → Character server: native hooks
- Plugin manager → Map simulation: native hooks
- Server configuration → Login server: configures
- Server configuration → Character server: configures
- Server configuration → Map simulation: configures
