This section explains how to build a domain layer atop the common engine. OSRIC (osric-engine/) is the exemplar: it supplies a domain store, entities, commands, shared rules, post-processing, and a scenario script.
- Provide store implementing EngineStore interface semantics.
- Define domain entities & helpers.
- Implement commands via the common DSL (importing
commandfrom engine package root re-export). - Post-process successful effects (battle mirroring) in wrapper.
- Supply deterministic scenario(s) for regression & reproducibility.
osric-engine/
engine.ts
memoryStore.ts
domain/entities/battle.ts
commands/*.ts
shared-rules/characterExist.ts
effects/mirrorBattleEffects.ts
scenarios/determinism.ts
index.ts
DomainEngine composes core Engine and, after each successful execution / batch, augments effects via mirrorBattleEffects (idempotent). It never mutates core engine internals.
Commands declare params interface + result interface (for consumers) and register rule functions across stages. Shared logic (character existence) extracted to shared-rules only after reuse threshold.
Promote only when:
- Pure relative to provided ctx (except sanctioned store reads)
- Used by ≥2 commands
- Stable semantic (unlikely to diverge across commands)
scenarios/determinism.ts runs a fixed command sequence and returns { seed, outcomes, effects, finalState }. Test ensures same seed -> identical JSON.
- Create
commands/yourCommand.tsimportingcommandDSL. - Define params/result interfaces.
- Add stage rules (validate/load/calc/mutate/emit) in logical order.
- Reuse shared rules if criteria met.
- Add unit test under
__tests__/domain/verifying success/failure + determinism if RNG used.
Extend wrapper only (e.g., new effect transformation). Keep pure: accept previous effects, return appended list.
Add new entity arrays & helpers inside memoryStore.ts. Ensure snapshot-friendly (plain objects, no functions).
- Update domain barrel
index.tsif exposing new types. - Extend scenario if new behavior materially changes aggregated output (or create a second scenario file).