All three servers are plain Spring Boot applications (ZoneServerApplication.kt, LoginServerApplication.kt and ApiServerApplication.kt, each a @SpringBootApplication with a fun main). There is no custom application container, no Akka, no actor cluster — Spring’s dependency injection wires together plain Kotlin classes, most of them @Component/@Service beans.

Boot sequence

zone-server starts up as an ordered chain of Spring CommandLineRunner/ApplicationRunner beans, each carrying a @Order that fixes its position in the chain. Most live under zone-server/src/main/kotlin/net/bestia/zone/boot/, but a few live next to the domain they serve and simply share the same @Order numbering scheme. There are more than fifty; these are the ones that shape the order:

OrderRunnerPurpose
1WorldGenerationBootRunnerGenerate or load the world. First and slowest step — everything else stands on it (entities load at positions in it, mobs spawn onto its terrain), so it fails fast rather than after importing everything else.
8ChunkEditBootRunnerPut back the terrain players dug, saved by an earlier run
100ItemImporterBootRunnerImport item definitions
101MobImporterBootRunnerImport mob definitions
102SkillImporterBootRunnerImport skill definitions
103MasterSkillTreeImporterBootRunnerImport the player skill tree
104StatusEffectImporterBootRunnerImport status effect definitions
110EntityLoaderBootRunnerReload persisted entities into the ECS World
150EquipmentScriptBinderBootRunnerBind equipment scripts to their items
200ContentValidationBootRunnerRun every CatalogValidator (skills, status effects, dialogs, item scripts, occupations, economy, mint chain) — fails boot on a mismatch, before any login or tick
LOWEST_PRECEDENCE - 2ZoneReadyBootRunnerFlip ZoneReadinessService to ready, so logins are accepted only once everything above has finished
LOWEST_PRECEDENCE - 1WorldBootRunnerStart ZoneEngine — the ECS tick loop begins running
LOWEST_PRECEDENCESocketServerBootRunnerBind the Netty socket and start accepting connections

The ordering is deliberate: the socket only opens after the tick loop is running, and ZoneReadyBootRunner gates client logins so nobody connects into a half-loaded world (see ClientMessageHandler.handleAuthenticationSuccess, which checks zoneReadinessService.isReady() before accepting an otherwise-valid login).

login-server and api-server have no comparable boot chain. Flyway migrates their schema while the Spring context starts, and they are ready when it is.

Code layout: slices and tiers

The zone-server code is cut into slices: one top-level package under net.bestia.zone per feature (battle, item, party, townsfolk, …) or per piece of shared machinery (message, persistence, engine, …). Inside a slice, the code is sorted by what it is:

PackageHolds
<slice>services, configs, and the SMSGs the slice sends
<slice>.ecscomponents, systems and intents; each *ComponentSMSG sits next to its component
<slice>.netwhat a client can send the slice: CMSGs, their handlers, chat commands
<slice>.persistenceJPA entities, repositories and entity persisters

FeatureSliceRulesTest keeps the last two packages honest: nothing outside a net package depends on one, and every entity and repository lives in a persistence package.

The slices form a stack, lowest first. A slice may only depend on slices below it:

  root < util < geometry < ecs (the kernel, ecs.core) < config < bus < message < session < sync
< persistence < notebook < identity < aoi < entity < logout < navigation < movement < world < structure
< water < script < place < skill < dialog < battle < weather < ground < item < quest < bestia < spoor
< prop < settlement < casting < emote < travel < ai < spawn < workexp < worldboss < account < party
< guild < compendium < economy < crafting < cartography < treasure < townsfolk < honor < postal
< master < respawn < trade < auction < blackboard < capture < spellscroll < teleport < spellbinding
< scry < breeding < fishing < chat < poi < control < companion < socket < metrics < engine < boot
  

FeatureSliceRulesTest reads the compiled classes and fails on any dependency that points up the stack, and on a new top-level package that has no place in it. A stack cannot hold a cycle, so the slices never form one.

When a lower slice needs a higher one

The lower slice declares a small interface, a port, and the higher slice implements it. Spring wires in the implementation. For example, battle makes a pristine prop fightable through CombatTargetPromotion, which the prop slice’s PropPromotionService implements, and the item slice loads the rows that hold containers through ContainerOwners, which the account slice implements. Most ports have exactly one implementation. A few are listeners and take any number: spawn’s KillExpLevy (the guild’s tax) and battle’s LevelUpListener (which refreshes party and guild rosters). Systems follow the same rule: a system in a higher slice declares before when the lower system may not name it (see ECS).

Where a new class goes

  • Into the slice of the feature it belongs to. A new feature is a new top-level package; give it a place in the stack in FeatureSliceRulesTest.
  • Components and systems into <slice>.ecs, CMSGs and handlers into <slice>.net, entities and repositories into <slice>.persistence.
  • When the class needs a slice above its own, add a port to its own slice instead.
  • ecs.core is the kernel. It may only use util, the root BestiaException and the JDK. util and geometry use nothing else in the zone.

Last updated 04 Dec 2026, 01:08 +0100 . history