principles/principle-model-the-domain/SKILL.md

name: principle-model-the-domain description: "Apply to stateful or branchy code. Encode the domain in a structure instead of scattered conditionals."

Model the Domain

Encode the real domain in a data structure. Scattered booleans, repeated shape assumptions, and branching spread across files are accidental complexity.

Why: A structure that matches the domain makes invalid states unrepresentable and deletes branches. Choosing it at write time is cheap; recovering it later reads as a refactor and gets deferred.

Pattern:

  • State machine over scattered booleans or lifecycle flags.
  • Typed model over loose parameters or repeated shape assumptions.
  • Map, registry, table, or discriminated union over branching spread across files.
  • Reducer or command/event model over ad-hoc mutations.
  • Module around one body of domain knowledge, not a load-validate-transform-save sequence.
  • Do not force an abstraction. Boring code stays when the shape is already clear and local.
  • Tell you skipped this: one more branch on an existing if/else, or a second boolean that must stay in sync with the first.