GUIDE
Start a project with an ontology, run every change through it, and let machines check the code against it. This guide shows the whole flow in diagrams, from the first file to a pipeline where people review the ontology and most code review is automated.
Requirements and prompts feed the ontology. Code is built from the ontology.
In ontology-driven development (ODD), a small machine-readable ontology is written after the requirements and before the design. It records what exists (object types, properties, links) and how it may change (action types with parameters, rules, rejection conditions and side effects). Each element names the requirement IDs it realizes.
The ontology is not documentation that follows the code. It comes first, and everything else is built from it or checked against it.
Change the ontology before the code. When behavior changes, the requirements and the ontology change first, in their own commit.
Implement from the ontology, never from the prompt. A request that the ontology does not cover is turned into ontology changes first.
Leave evidence. Commits, code, tests and the pull request show which element each change came from, so it can be checked without asking.
Five steps from an empty repository (or an existing one) to an ontology that CI and agents use.
Install the Ontology-Driven Development VS Code extension for diagnostics and the diagram. Install the oont CLI with npm install -D @yaggytter/object-ontology-cli. Copy the ontology-driven-development skill into your project, for example to skills/ontology-driven-development/.
Copy the requirements template to ontology/requirements.md. In a new project, number what the user asks for. In an existing project, derive the requirements from what it already promises: user documentation, feature lists, policies and test names. Aim for 15–30 to start.
Nouns become object types, relations become link types, verbs become action types, business rules become validations. Put every requirement ID on the elements that realize it. In an existing project, write only behavior you confirmed in the code, and set x-implementedBy and x-tests to today's files.
oont validate --strict ontology
# 1 file checked: 0 errors, 0 warningsOpen the diagram (Cmd+Alt+O / Ctrl+Alt+O). Walk through object types, actions and their rejection conditions with the people who know the business. Questions without an answer go to the "Open questions" list instead of being guessed.
Add oont validate --strict ontology to CI. Paste the skill's CLAUDE.md snippet so the agent loads the workflow and the ontology in every session.
repository/
├── CLAUDE.md # project settings; loads the skill and the ontology
├── ontology/
│ ├── app.oont.yaml # the source of truth
│ └── requirements.md # requirement bodies and open questions
├── skills/ontology-driven-development/
└── src/ … # built from the ontologyEvery change in behavior goes through the ontology. People decide the "what"; the agent builds the "how".
requirements.md, the registry and the elements. Write each rejection condition as a validation with description and expr.oont validate --strict, commit the ontology on its own, and agree on the diff.A request arrives: "an item can be lent to only one member at a time". The agent does not open the code. It changes the ontology first:
# ontology/app.oont.yaml (commit 1: docs(ontology): add REQ-002 to borrowItem)
requirements:
REQ-002: { title: An item can be lent to one member at a time, source: requirements.md }
actionTypes:
borrowItem:
requirements: [REQ-001, REQ-002]
x-implementedBy: [src/lending/borrowItem.ts]
x-tests: [src/lending/borrowItem.test.ts]
validations:
- description: Only an available item can be borrowed.
requirements: [REQ-002]
expr: "item.status == 'available'"
After the ontology diff is agreed, the tests and the code follow, and both point back to the element:
// src/lending/borrowItem.test.ts
it("REQ-002 borrowItem: rejects an item that is already lent", …)
// src/lending/borrowItem.ts
// Ontology: actionTypes.borrowItem (REQ-001, REQ-002)
export function borrowItem(item: Item, member: Member): Item { … }
# commit 2
feat(lending): reject borrowing an item that is already lent
Ontology: actionTypes.borrowItem
Requirements: REQ-002
| Element | Requirements | Ontology commit | Implemented in | Tests |
|---|---|---|---|---|
actionTypes.borrowItem | REQ-001, REQ-002 | a1b2c3d | src/lending/borrowItem.ts | borrowItem.test.ts (2 tests) |
The trace report in the pull request. Below it: oont validate --strict 0/0 and the test result.
Turn the rules into gates that fail the build. NOW works with today's tools. G7 also needs an agent that you run.
| Gate | What it proves | How |
|---|---|---|
| G1 NOW | The ontology is well-formed, every reference resolves, and every requirement is realized by some element. | oont validate --strict ontology |
| G2 NOW | Every action type says where it is implemented and tested, and those files exist. | oont trace --strict ontology from the repository root. Run it on the head of the pull request: the ontology commit may name files that a later commit adds. |
| G3 NOW | The ontology came first: every element a code commit names in its Ontology: trailer was already in the ontology before that commit, and its Requirements: IDs are in the registry. | oont commits <base>..<head> --ontology ontology/app.oont.yaml --code src. A commit with no behavior change says Ontology: none. --since skips history from before the trailers. |
| G4 NOW | Each requirement that a validation realizes is named, with its action, in a test of that action. | oont coverage --strict ontology, with tests named like REQ-002 borrowItem: rejects …. |
| G5 NOW | Agent tool definitions and the context summary checked into the repository match the ontology. | oont export tools / summary, then git diff --exit-code. |
| G6 NOW | The behavior described by the validations holds. | The project's test command (tests named after requirements and elements). |
| G7 NOW | The diff does what the named elements say, and nothing they do not say. | oont review-context writes the material; an agent other than the author reviews it with the skill's review guide. See section 5. |
G1–G5 use only the oont CLI (G3 and G7 need the full history: fetch-depth: 0). The G7 step only writes the review context; running the agent on it depends on your setup (see section 5). Adjust the paths to your project.
name: ontology-gates
on: pull_request
jobs:
gates:
runs-on: ubuntu-latest
env:
ONTOLOGY: ontology/app.oont.yaml
steps:
- uses: actions/checkout@v4
with: { fetch-depth: 0 }
- uses: actions/setup-node@v4
with: { node-version: 20 }
- run: npm install -g @yaggytter/object-ontology-cli@0.7
- name: G1 ontology is valid
run: oont validate --strict ontology
- name: G2 traceability
run: oont trace --strict ontology
- name: G3 ontology first
run: |
oont commits "${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}" \
--ontology "$ONTOLOGY" --code src
- name: G4 validation coverage
run: oont coverage --strict ontology
- name: G5 generated artifacts are in sync
run: |
oont export tools "$ONTOLOGY" -o generated/agent-tools.json
oont export summary "$ONTOLOGY" -o generated/ontology-summary.md
git diff --exit-code generated/
- name: G6 tests
run: npm test
# G7: the material for the AI review; an agent reviews it (section 5)
- name: G7 review context
run: |
oont review-context "${{ github.event.pull_request.base.sha }}..${{ github.event.pull_request.head.sha }}" \
--ontology "$ONTOLOGY" --code src -o review-context.md
The tools do not evaluate validation expr; it documents the rule for people and agents. G4 checks that a requirement is tested, not that the test is right. G3 trusts the Ontology: none claim; G7 is where that claim is checked.
Proposed practices for making most human code review unnecessary. People review the ontology; machines review the code against it.
Code review is expensive because the reviewer has to rebuild the intent from the diff. In ODD, the intent is already written down and agreed: it is the ontology. That lets us split review in two. People review the "what", the ontology diff, where business knowledge is needed. Machines review the "how", whether the code matches the agreed ontology, which can be checked step by step.
PROPOSAL The review material (oont review-context) and the review guide in the agent skill are available now. Routing, auto-merge and the metrics below are practices to try.
| Change | Required review | Merge |
|---|---|---|
| Ontology diff: a new concept, action, validation or requirement | PEOPLE The domain owner approves the ontology. The AI review checks it for contradictions and open questions. | Human approval |
| Code that implements an already-approved ontology change | Layer 0 passes and the AI review has no blocking findings. | Automatic |
No change in behavior (Ontology: none): refactoring, tests, dependencies | Layer 0 passes and the AI review confirms that behavior did not change. | Automatic |
| The AI review finds behavior that no element describes, or a conflict with the ontology | PEOPLE Decide: add it to the ontology, or remove it from the code. | Human decision |
Touches a cross-cutting requirement (NFR-: security, privacy, accessibility) | PEOPLE A person reviews, even if everything passes. | Human approval |
Booking?", to decide which tests and which owners a change involves.oont review-context (commits, trailers, the named elements as written, their requirements, the diffs) and the ontology summary (oont export summary). Nothing else defines "correct".Ontology: none claim true?{ "element": "actionTypes.borrowItem",
"verdict": "mismatch",
"kind": "undeclared-behavior",
"evidence": "src/lending/borrowItem.ts:42 sends an email; sideEffects lists only the return date notice",
"action": "add the side effect to the ontology, or remove it from the code",
"blocking": true }
An example finding. Because it names an element and a line, both a person and a script can check it.
Ontology: none changes, then implementation of approved ontology diffs.A defect traced to the ontology is fixed in the ontology. A defect that slipped past the gates becomes a new gate.