Code Add Domain Type

Table of Contents

When to use this skill

When you need to add a new domain type to an ORE Studio component with JSON I/O, table I/O, a test data generator, and repository CRUD support. This is the mandatory first step before any exposure layer (SQL schema, HTTP, CLI, shell, Wt, Qt) can be built. See the Entity lifecycle overview for the full layer ordering.

How to use this skill

Codegen is the primary path for a persisted, data-carrying entity (one with SQL storage, and usually a UI). Manual creation is appropriate — not a last resort — for a behaviour-heavy value type (parsing, comparison operators, computed methods) with no persistence or generated UI: none of codegen's entity-model types generate that shape, they generate flat data-carrying structs plus persistence/UI layers. See e.g. ores.analytics.quant's own domain types (currency_id, ccy_pair, …), which are hand-authored for exactly this reason — no codegen banner, not listed in compass codegen entity list. Justify the choice in the file header either way.

  1. Create an org-mode entity model under the target component's modeling/ directory (co-located org models — see the component_catalogue.org's modeling_dir column), following the ores.codegen.entity (full entity: C++ + SQL + Qt), ores.codegen.lookup_entity (SQL-only reference table), ores.codegen.field_group (flat C++ struct fragment composed into a parent entity), ores.codegen.table, or ores.codegen.junction schema — see Codegen input org-file schema reference for the authoritative frontmatter keywords and section hierarchy per type. (The legacy *_domain_entity.json=/=models/{component}/ format this step used to reference no longer exists in the repo — org-mode entity models superseded it.) Scaffold via compass add --type entity_org ... (or field_group=/=table=/=junction=/ =lookup_entity as appropriate) per How do I add a doc with compass?, then fill in the sections by hand.
  2. Generate the C++ artefacts via compass, not the generator script directly: compass codegen generate --model <path/to/model.org> --address ores.cpp (compass codegen entity generate <entity> regenerates an already-modelled entity's full supported set; compass codegen entity list / show / diff inspect what exists and whether it's stale).
  3. Build and verify: use cmake-runner to confirm the component library compiles cleanly.
  4. Raise PRs at phase boundaries — Phase 1: domain + I/O; Phase 2: generator; Phase 3: repository; Phase 4: tests + diagrams. Use feature-branch-manager to transition between branches and pr-manager to open each PR.
  5. Update diagrams after Phase 4: plantuml-class-modeler for the class diagram; plantuml-er-modeler for the ER diagram.

If codegen cannot express the pattern, extend the Mustache templates in library/templates/ first, then regenerate. See ORE Studio Codegen§"Profile catalogue" for what each profile generates and which library it uses.

Recipes

Reference

Templates

Runs via --address ores.cpp (combines domain · generator · repository · service · protocol). Full output paths are in Entity lifecycle§"Complete entity file checklist".

Sub-address Key templates
--address ores.cpp.domain cpp_domain_type_class.hpp.mustache (+ 6)
--address ores.cpp.generator cpp_domain_type_generator.hpp.mustache (+ 1)
--address ores.cpp.repository cpp_domain_type_entity.hpp.mustache (+ 5)
--address ores.cpp.service cpp_service.hpp.mustache (+ 1)
--address ores.cpp.protocol cpp_protocol.hpp.mustache

Read the template directly for the authoritative implementation — do not reproduce it here.

Emacs 29.3 (Org mode 9.6.15)