BuilderOS

domain-model

Models the domain with the person: entities, states and transitions with who triggers them, invariants, awkward scenarios, a logic prototype, a data sketch. Use when things change state, who-can-do-what is unclear, a schema is due, or terms clash.
phase 4 · Shape## DOMAIN MODELED
Run by agents
ux-architect
Reached from commands
/builder-os:bos-shape

At a glance

Mode. Standalone models the supplied domain and returns the entities, the rules and the prototype. In the lifecycle it runs in phase 4 after the flows and before the visual direction and the stack (the store depends on the shape of the data), writes SPEC.md → Design → ## Domain model, and gate 4.10 checks it. Both per operating modes. Read the domain method for the tables, the scenario technique, the logic prototype and a worked example.

  1. 1Start from what is settled
  2. 2Name the things
  3. 3Give each entity its states and transitions
  4. 4Write the invariants
  5. 5Stress it with scenarios
  6. 6Put the rules to the person, in their words
  7. 7Build a logic prototype
  8. 8Sketch the data
  9. 9Record and explain

The skill

ux-architecture designs what the screen shows when something is empty, loading or broken. This skill designs the things the product is about: what they are, what states they move through, who moves them, what must always be true, and how they are stored. A ticket reopened after it is closed, an invoice edited after it is sent: these are product decisions, and left to the build an agent makes them silently, one if at a time.

Mode. Standalone models the supplied domain and returns the entities, the rules and the prototype. In the lifecycle it runs in phase 4 after the flows and before the visual direction and the stack (the store depends on the shape of the data), writes SPEC.md → Design → ## Domain model, and gate 4.10 checks it. Both per operating modes. Read the domain method for the tables, the scenario technique, the logic prototype and a worked example.

Procedure

  1. Start from what is settled. Read the project's DOMAIN.md, and the schema, migrations and status enums where repo.read resolved. On a product that exists, model the delta: the entities this work adds, the states and transitions it adds or changes, the invariants it touches. Every existing rule it changes is named as a change, with the initiative that set it, and asked as a round question. Where an invariant tightens, count the existing rows that already break it (db.query) and hand the number to the spec's Impact on what exists. Done when you can list what exists, what this work changes, and the rows affected.
  2. Name the things. From the flows, the spec scope and PRODUCT.md: the entities the person acts on, each with a one-line definition in the product's words, checked against PRODUCT.md → Language. A term used two ways, or two terms for one thing, is a question for the person ("is a project the same as a workspace?"), settled first and written into Language. Done when every term has one meaning.
  3. Give each entity its states and transitions. Per transition: who can trigger it, the guard (what must be true first), and the effect (notifications, other entities that change, what becomes irreversible). Draw each lifecycle under its table as a Mermaid stateDiagram-v2, one arrow per transition labeled with who, every state of the table in it (gate 4.20); the person reads the drawing when the rules are put to them. An entity with no lifecycle gets a line saying so. Done when every transition has who, guard and effect, and every lifecycle is drawn.
  4. Write the invariants: the rules that hold whatever happens ("a ticket has exactly one assignee or none", "a paid invoice changes only by credit note"). Each is a candidate test and, where the store allows, a constraint. Done when every rule the flows imply is written as an invariant.
  5. Stress it with scenarios. Walk concrete, awkward stories through the model: two people move the same ticket at once; the assignee leaves the team; a payment arrives for a cancelled order; the person undoes. Done when every scenario has an answer from the model or is listed as an undecided rule.
  6. Put the rules to the person, in their words. Every undecided rule becomes a pressure-testing round question: options with what each means for the people using the product, a recommendation and why ("Can a closed ticket be reopened? A. Yes, by anyone… B. Only by its author… C. A new one is opened and linked…"). Hard-to-reverse ones (deletion, money, permissions) become ADRs. Done when every undecided rule has the person's answer.
  7. Build a logic prototype when an entity has more than two states, a guarded transition, or a rule the person hesitated on: one HTML file at .builderos/initiatives/{initiative}/design/domain-prototype.html, a button per action, guided scenarios from step 4, the full state shown after every click, in the product's language. The logic sits in one pure, in-memory script module the build can lift. Done when the person has played it, before accepting the model.
  8. Sketch the data. Per entity: the fields that matter, the relationships, and what is deleted with what. The shape, short of a migration: enough for system-design (stack) to choose a store and for the build to write the schema with every rule already decided. Done when each entity has fields, relationships and deletion behavior.
  9. Record and explain. Write ## Domain model in SPEC.md → Design per the design template; at ship, phase 6 promotes it into DOMAIN.md (gate 6.9), and standalone work on a product with a DOMAIN.md proposes the edit there. Add a plain-language paragraph to the spec's ## What we chose: the main objects and the two or three rules that will surprise someone. New terms go into PRODUCT.md → Language. Done when gate 4.10 passes on the file.

Watch for

DoInstead of
States, transitions, who, guard, effectA status string whose rules get decided inside handlers
Ask "can it be reopened?" as a round questionA product rule made by whoever wrote the endpoint
One word per thing, written in LanguageTwo tables for one concept
An in-memory prototype with buttonsA prototype wired to the real database, testing plumbing
The entities this work touchesWeeks modeling the whole product
"Not applicable" only when nothing changes state or shapeSkipping the riskiest rules on a status change

Capabilities

CapabilityUsed forFloor if absent
repo.readExisting entities, schemas, migrations, enums, status fieldsAsk what exists; mark the model unverified against the code
db.queryThe real distribution of states and the rows that break the rules todayModel from the rules; mark counts unknown
ui.renderShowing the logic prototypeA self-contained HTML file the person opens
files.read / files.writePRODUCT.md → Language, SPEC.md → Design, the prototypeInline answers need no write; lifecycle writes require it

Output Contract

## DOMAIN MODELED with the entities, the transitions with who and guard, the invariants, the rules the person decided, the prototype path when built, and the data sketch.

References

Read only when a step needs them, so they cost no context until then.

Domain Methodreferences/domain-method.md

The tables, scenarios, prototype rules and example behind domain-model. Read the section the current step needs.

Tables

markdown
### Entities
| Entity | Means | Lifecycle |
|--------|-------|-----------|
| Ticket | A piece of work someone is accountable for | yes |
| Comment | A note on a ticket; never edited after 10 minutes | no |

### Transitions: Ticket
| From | To | Who | Only if | Then |
|------|----|-----|---------|------|
| todo | in progress | assignee | it has an assignee | the assignee is notified once |
| in review | done | reviewer, not the assignee | every checklist item is ticked | the reporter is notified; reopening needs a new ticket |

```mermaid
stateDiagram-v2
  [*] --> todo
  todo --> in_progress : assignee
  in_progress --> in_review : assignee
  in_review --> done : reviewer
  done --> [*]
```

### Invariants
- A ticket has exactly one assignee or none.
- A done ticket's fields are read-only.

### Data
| Entity | Key fields | Relations | Deleted with |
|--------|-----------|-----------|--------------|
| Ticket | title, state, assignee, reporter, team | many comments; one team | its team (soft delete) |

Scenarios

The model is finished when awkward stories stop producing new questions. Run these families against every entity with a lifecycle:

FamilyAsk
ConcurrencyTwo people trigger conflicting transitions at the same moment. Who wins, what does the loser see?
People changeThe owner leaves, loses permission, or is deleted mid-lifecycle
Going backUndo, reopen, revert, cancel after partial completion
Money and timeA payment, a deadline or a scheduled job arrives in a state that no longer expects it
VolumeZero, one, many, too many children (comments, items, members)
Outside worldAn integration sends an update the model has no state for

Write each scenario as one line with its answer, or as the round question it raised.

Logic Prototype

One self-contained HTML file the user opens with a double click. It answers "do these rules feel right?", not "does the backend work".

  • The question at the top, in a visible paragraph: what model is being tested and which rules are new.
  • A pure module in a single