Skip to content

0007. ECS and data-first content (schemas as source of truth)

  • Status: Accepted
  • Date: 2026-11-26
  • Phase: 1

AI and non-coders work best with declarative data. Scenes, levels, entities and content packs must be generated, validated, diffed, versioned and hot-reloaded. Components must be serializable for save/load, the inspector, the MCP server and (later) netcode.

  • Own small ECS in @ludrel/core: entities are numeric IDs; components are plain data defined with Zod schemas (defineComponent('Health', z.object({ hp: z.number().int(), max: z.number().int() }))); systems are functions with declared queries and an explicit order/phase (fixedUpdate, update, render). Storage starts as typed maps per component (simple, debuggable); hot components can move to SoA later without changing the API.
  • Prefabs are JSON: a named bag of component values. Scenes and levels reference prefabs and override fields.
  • Schema source of truth: Zod definitions in @ludrel/schema emit JSON Schema 2020-12 files that are versioned and published. The same schemas validate content in the runtime, API, editor and MCP server, and are given to AI models as tool input schemas.
  • Formats: JSON is canonical on disk and over the wire. YAML is accepted as an authoring convenience and converted to JSON on import. Every document carries $schema and schemaVersion; we ship migration functions between schema versions.
  • Escape hatch: custom behaviour lives in TypeScript systems/scripts registered by name; data references them by name ("behaviors": ["patrol"]). Content packs may only reference behaviours the game already exposes.
  • bitECS: very fast SoA, but component data is typed arrays, awkward to serialize/inspect and to explain to AI.
  • miniplex: pleasant object ECS, but slower maintenance and no schema story.
  • Scene graph / OOP GameObjects (Phaser-style): familiar but harder to serialize and validate.
  • TypeBox instead of Zod: emits JSON Schema natively; Zod is more widely known to AI models and is what the MCP TypeScript SDK and AI SDK use, so one schema library everywhere wins.

We own ~1.5k lines of ECS code and its performance. Benchmarks in Phase 1 must show 5k+ moving entities at 60 fps in the stub-render benchmark. Schema migrations become a permanent responsibility.