Architecture and Code Connections¶
This page shows where the main code lives and how request handling, game logic, and persistence connect.
Request Flow¶
flowchart LR
A["HTTP Client"] --> B["Akka Route: Endpoints.route"]
B --> C["EngineBase interface"]
C --> D["Engine implementation"]
D --> E["StorageEngine interface"]
E --> F["H2Database (SQL)"]
D --> G["YAML Config (space.yaml)"]
B --> H["JsonSupport / Spray JSON"]
H --> A
Key Code Files¶
| File | Role |
|---|---|
src/main/scala/core/Omen.scala |
App entry point; loads config and binds HTTP server |
src/main/scala/core/base/EngineBase.scala |
Abstract service contract used by routes |
src/main/scala/core/api/Endpoints.scala |
REST endpoints, parameter parsing, response envelope |
src/main/scala/core/impl/Engine.scala |
Core game logic (create/upgrade/requirements/tasks/hourly updates) |
src/main/scala/core/base/StorageEngine.scala |
Storage abstraction |
src/main/scala/storage/H2Database.scala |
H2-backed storage implementation |
src/main/scala/model/json/JsonSupport.scala |
JSON codecs for request/response model |
src/main/resources/game_configs/space.yaml |
Entity graph, requirements, formulas |
src/test/scala/SpaceGameTest.scala |
End-to-end route-level behavior tests |
How Components Connect¶
Omen.start()creates anEngineand bindsengine.webRoutes.route.Endpointsreceives HTTP requests and wraps successful responses as:
{ "status": 200, "data": ... }
- Route handlers call
EngineBaseoperations (createEntity,computeRequirements,tasks, etc.). Engineapplies rules from YAML config (space.yaml) and computes formulas/requirements.Enginepersists and queries throughStorageEngine;H2Databasehandles SQL storage.JsonSupportand model protocols serialize Scala case classes to/from JSON.
Concrete Example: Upgrade Flow¶
- Client calls
POST /entities/{entityId}/upgrade/{to}. Endpointsresolves the entity and invokesomen.upgradeEntity(currentEntity, to).Engine.upgradeEntityincrementsamountand callsstorageEngine.save(...).H2Database.saveupdates theentities.amountrow.- Response is returned under the standard envelope.