Skip to content

The example with the Issues area open: the toolbar chip reads 5 warnings and 6 notes; the details panel lists the findings grouped by severity and rule, the first one current: the verdict "No arrow carries this step", the Flows tag, the chips Annotator → BoundingBoxCanvas and Annotate + submit · step 14, its sentence and a diagram with the missing arrow dashed in orange; a card at the map's top left shows the same finding; on the map the boxes of the findings are ringed with a severity badge, the step no arrow carries is a dashed line with a numbered chip, and the rest of the map is faded

A finding opened in the Issues area of the example, with its card on the map: the verdict "No arrow carries this step" in bold, the chips Annotator → BoundingBoxCanvas and Annotate + submit · step 14, a diagram with the two boxes and a dashed red arrow labelled "step 14 · no arrow", and in grey the arrow Annotator does have, to AnnotatePage; below, "How this was found" opened: the rule's logic with the names, what matched, and what was checked and not found

Coherence rules

A model can pass the validator (every id exists, every field has the right shape) and still tell an incoherent story: a flow that hops between two boxes no arrow joins, a step that writes into a database its boxes cannot reach, a queue nobody reads, two services that wait on each other, a lifecycle state nothing leads to. The coherence rules look for that. Each is a SPARQL pattern over the model's RDF graph (the c4:, c4d: and c4v: terms the explorer already exports), and each finding names the boxes, arrow or step it is about, so a reader or an agent can go straight to it.

Why rules over the graph, and not proofs

A model is finite and every rule is a decidable question about it ("is there an arrow between these two boxes, or between the boxes around or inside them?"). Running the rule is the proof for that model, and the finding (or its absence) is the certificate: there is nothing a theorem prover such as Lean would add for one model, and it would need the whole model restated in its own language. Where formal proofs would pay off is the explorer's own algorithms (that lifting a flow to a level keeps its order, that a layout never overlaps two boxes), not the content of a model.

Writing the rules as SPARQL over the published graph keeps them where the model already is, runnable by any SPARQL or SHACL engine:

  • rete-graph (WebAssembly, the .rete export's engine) runs them in check-coherence.mjs, in build-explorer.mjs (the findings are embedded in the page), in the MCP server's check_coherence tool, and in the page (Issues → Re-check);
  • SHACL: ontology/c4-coherence-shapes.ttl holds the same rules as SHACL-SPARQL constraints (sh:sparql, sh:message, sh:severity), for pyshacl, TopBraid or any engine with SPARQL-based constraints: pyshacl -s c4-coherence-shapes.ttl architecture.ttl. The file is written from the rules (check-coherence.mjs --write-shapes), and CI checks it is current.

Running them

Where How
A page, a model.js or a graph node scripts/check-coherence.mjs <index.html \| model.js \| graph.ttl>: one line per finding (ISSUE for errors, WARN, INFO), then a summary. --explain adds, under each finding, how it was found (below), --sparql the two queries, --log what the run did per rule (below). --json the whole report, --rule id[,id] some rules, --all the dismissed ones too, --strict warnings fail. Exit 1 on an error (or a warning with --strict), 2 without rete-graph.
With the other checks node scripts/check-model.mjs index.html --coherence: a COHERENCE section (information; check-coherence.mjs has the exit codes).
In the page, offline build-explorer.mjs runs the rules when rete-graph is installed (the plugin's mcp/ folder has it: npm install there) and embeds the findings, so the Issues area works from disk. --no-coherence leaves them out.
In the page, after edits Issues → ↻ Re-check runs the rules on the model as it is now, with the rete builder from the CDN (the .rete export's): it needs the network.
An agent in the page list_issues, get_issue, next_issue, focus_issue, recheck_issues, dismiss_issue, restore_issue (below).
An agent over MCP check_coherence with a model: the same findings as JSON, the run's log per rule (candidates, kept, findings, dismissed, ms), and with explain: true how each finding was found.
SHACL pyshacl -s ontology/c4-coherence-shapes.ttl architecture.ttl (slow on large graphs: minutes for the example's 5 000 triples, where rete takes a second).

rete-graph is found in the working directory, the input's folder, the script's folder and the plugin's mcp/ folder.

Findings, ids and dismissals

A finding has an id, rule@key, where the key says what it is about in model ids, so it stays the same across runs and rebuilds as long as the model does: a box id (minio), an arrow from>to (web>db), a step scenario#number (review#5), an entity entity:id, a pair of boxes a|b (sorted). It also has a severity (error, warning, info), an area (flows, data, infrastructure, states), a message that names the boxes, why it matters, how to fix it, and its focus: the boxes, the arrow (by its index in edges) and the step (scenario and number) it points at.

Some findings are right as they are: code-level calls deliberately left out of the arrows, export files read by another system. Dismiss them with a reason instead of bending the model: the model keeps the exception in view.coherence.ignore, so the finding stays dismissed across rebuilds and is listed, marked, with the reason:

view: {
  coherence: {
    ignore: [
      { rule: 'flow.call-without-arrow', focus: 'upload#4', reason: 'Code-level calls inside the API are not drawn.' },
      { rule: 'data.written-never-read', focus: '*', reason: 'The COCO files are read by the training pipeline, outside this system.' }
    ]
  }
}

focus is the finding's key, or * for every finding of that rule. The validator checks the shape (rule, focus and a reason are required); the page warns about a rule id it does not know. In the RDF graph each exception is a c4v:Dismissal (c4v:coherenceRule, c4v:focusKey, dcterms:description), so the graph stays lossless.

The rules

Flows

Rule Severity Finds
flow.step-without-arrow warning A scenario step between two boxes in different containers (or a person or system and a box) that no arrow joins, in either direction, at any level: not between them, nor between the boxes around or inside them. The map and the flows disagree; on the map the step can only be a dotted line. Fix: add the relationship at the most specific level that is true, or correct the step's ends.
flow.call-without-arrow info The same inside one container: two of its components or code boxes call each other in a flow, and no arrow shows it. Often on purpose (code-level calls are not drawn); then dismiss it with that reason.
flow.step-against-arrow warning A step that runs against the only arrow between its ends and is not marked as a reply (reply: true). An arrow points from the box that starts the interaction. A step that a store or queue sends (an answer, a delivered message) does not count.
flow.broken-chain warning A step whose sender comes out of nowhere: it is not the scenario's actor, it is not the first step, and no earlier step involves it, its container, or a box it is connected to by an arrow. Usually a missing trigger step or a wrong sender. A queue's consumer is fine: it is connected to the queue an earlier step wrote to.
flow.actor-absent warning A scenario (use case) whose actor never takes part in its steps.
flow.data-out-of-reach warning A step reads or writes data that lives in a data store, but neither of its ends, nor their containers, is connected to that store. The access belongs to the step that reaches the store (usually the call into the store), or an arrow is missing.

Data

Rule Severity Finds
data.read-never-written info An entity of a data store that scenarios read but none writes. Often written outside the modelled flows (migrations, an import, another system): dismiss it with where it comes from.
data.written-never-read info An entity of a data store that scenarios write but none reads: read by another system, or dead weight.
data.store-untouched info A data store that holds data (a schema lives in it) but that no scenario reaches, reads or writes.

Infrastructure

Rule Severity Finds
infra.queue-one-sided warning A store that looks like a queue (its tag or technology says queue, Kafka, RabbitMQ, SQS, Pub/Sub, NATS, RQ, Celery, MQTT, …) with fewer than two parties (containers, people or external systems) connected to it: messages go in and nobody takes them out, or the other way round. Producers and consumers both point at the queue.
infra.sync-cycle warning Two containers that call each other synchronously (solid arrows both ways, at any depth inside them): tight coupling, a failure in one takes the other with it. One direction should be asynchronous (dashed: a queue, an event). Longer cycles are not looked for.
infra.frontend-to-database warning A front end (its tag or technology says React, Vue, Angular, Svelte, SPA, browser, mobile, iOS, Android, Flutter, …) with an arrow straight to a database or a queue. Object storage reached with signed URLs (a store tagged or named S3, MinIO, object, bucket, blob, CDN) is left alone.

States

Rule Severity Finds
state.no-initial error A lifecycle (the states inside one box) with no initial state.
state.unreachable warning A state no transition leads to from the initial state.
state.final-exits warning A final state with a transition to another state.
state.dead-end warning A state that is not final and that no transition leaves: an item there is stuck.

The modelling guide's hints (check-model.mjs, references/modelling.md) are about the shape of the model (a library drawn as a container, a group too large, an arrow labelled "uses"); the coherence rules are about whether its parts agree with each other. They do not repeat each other: a box with no arrow at all is a hint, not a finding.

The Issues area

The page's toolbar has a chip with the open findings by severity (⚠ 5 i 6); it opens the Issues area in the details panel: every finding grouped by severity and rule, filters (severity, area, rule, open / dismissed / all) and a search. A finding reads at a glance: the verdict in bold ("No arrow carries this step"), the area as a tag, its boxes and step as chips in the box's colour with its icon (a click goes there), and the plain sentence under them; the severity is its icon and colour band. Opened, it shows the diagram of what was found, why it matters, how to fix it, and How this was found (closed until you open it: the explanation above). A card on the map shows the finding you are on, with the same diagram and its own How this was found (wider screens; on a phone the details sheet has it). The Log tab shows what each run did (above); dismiss… asks for the reason and records it in the model (an edit: edit mode turns on, one undoable step), restore takes it back. While the area is open the map marks the findings: rings and a severity badge on their boxes, a dashed halo on their arrows, a chip with the step number on the arrow that carries a step (or a dashed line when no arrow does), the rest faded a little. A click on a finding (or on a badge) marks just its parts and fits them; ← → step through the findings. In the Dynamic view the steps a finding names are marked. Findings come from the build; ↻ Re-check runs the rules on the model as it is now (needs the network).

How a finding is explained

A rule is two parts: where, a pattern that finds candidates (a step between two boxes in different containers, say), and, for most rules, unless, an exception that clears a candidate (an arrow between those boxes, at any level). A candidate is a finding when its exception is not found. Every finding carries the values that matched (the run keeps them, compactly, in the page), so the page, check-coherence.mjs --explain, get_issue and check_coherence with explain: true can all tell how it was found:

  • The verdict, short: "No arrow carries this step".
  • The logic in words, with the names filled in: "A step from “Annotator” to “BoundingBoxCanvas” in “Annotate + submit”, where “Annotator” and “BoundingBoxCanvas” are not inside one container, and neither is inside the other."
  • What matched: each variable of the pattern and its value (?a = Annotator, ?n = 14), as links.
  • What was checked, and not found: the exception in words ("an arrow, in either direction, between “Annotator” (or a box around or inside it) and “BoundingBoxCanvas” (or a box around or inside it): none"), with the boxes it walked: each box's line, the box itself, the boxes around it and the boxes inside it.
  • The facts: the pattern's triples with the values (:step:annotate:14 c4:source :annotator .).
  • The SPARQL: where as an ASK with the values written in (true for this finding) and unless as an ASK (false for it), to run in any SPARQL engine (query_sparql over MCP, rete, pyshacl).
  • A diagram in the page: the boxes with their real names, in the map's colours and clickable; what is missing in the severity's colour, dashed (the arrow no step has, the store no end reaches, the other side of a queue, the initial state); what is there instead in grey (the arrows the sender does have, the boxes the flow has reached).
  • A dismissal: its reason, who (by: reader, agent or a name) and when (on).

The run log

Each run also keeps, per rule, how many candidates the pattern found, how many none of the exceptions cleared, the findings, the dismissed ones and the time, with the cleared candidates by key (at most 40 per rule): which steps did have an arrow, which queue did have two parties. The page's Issues → Log tab shows the build's run (no timings: the same model builds the same bytes) and each Re-check's (with timings, kept for the visit, the last 5), with the rete-graph version, the number of triples and the plugin's version; copy log gives it as text, copy as JSON as data. check-coherence.mjs --log prints the same table:

rule                           candidates  kept findings dismissed     ms
flow.step-without-arrow                46     4        4         0     53
flow.call-without-arrow                47     3        3         0     42
flow.data-out-of-reach                 22     1        1         0    161
…
total (16 rules)                      120    11       11         0    638
cleared  flow.step-without-arrow: annotate#1, annotate#3, annotate#11, …

An agent going through the findings

The page's tools take an agent through the findings one at a time, with the reader watching:

  1. list_issues: the open findings (status, severity, area, rule filter them), errors first.
  2. next_issue (after: the id of the last one handled): the next open finding, shown to the reader on the map.
  3. get_issue: why it matters, how to fix it, its boxes, arrow and step in detail, and how it was found (how: the logic, what matched, what was checked and not found, the facts, the SPARQL), to tell a real gap from a rule that does not fit this model; then get_element, list_relationships and the other reading tools.
  4. Fix it with the edit tools (connect_elements, update_relationship, update_element, …): the reader approves each edit. When the finding is right as it is, dismiss_issue with the reason instead.
  5. recheck_issues: the rules again, on the edited model (it returns which findings are new and which are gone).
  6. Back to 2 with after set to the finding just handled, until next_issue answers done.

Over MCP, check_coherence gives the same findings for a model passed in, with the same ids, so an agent can fix the model it is writing and check again before building the page.

Writing a rule

Rules live in one place, the explorer template's <script id="coherence"> block (window.archCoherence): the page, the scripts, the MCP server and the SHACL file all read them from there. A rule is

{ id: 'area.name', area: 'flows', severity: 'warning', target: 'c4:Step', title: '…',
  vars: ['a', 'b', 'sc'], literals: ['n'], key: ['this'],
  message: 'Step {n} of {sc}: {a} → {b} …',   // {var}: the name of that box, scenario or entity, or the literal
  why: '…', fix: '…',
  where: '?this a c4:Step ; c4:source ?a ; … FILTER NOT EXISTS { … }',   // the candidates: ?this and the vars bound
  unless: '…' }   // optional: a pattern that clears a candidate

where finds the candidates; unless, when there is one, is asked for each candidate with its values written in as constants (the SHACL form adds it as FILTER NOT EXISTS: the same meaning). Two things keep rules fast on rete: an engine may evaluate each branch of a UNION on its own, so a UNION must not hold a join with the rest of the rule (the shared line() helper, "x is y, inside it or around it", is a UNION of two plain property paths, which is cheap), and filters are evaluated for every row, so the expensive part goes in unless, which only the few candidates reach. After adding a rule: check-coherence.mjs --write-shapes, a broken model that triggers it once, and a run on the example to check it is not noisy.


Where the details are. The terms the rules read are in the ontology (and the data terms for the data rules); the shapes file is ontology/c4-coherence-shapes.ttl. What makes a model well formed in the first place is the modelling guide and its hints; the agent tools are listed in the agent tools reference.

Source

This page is skills/architecture-explorer/references/coherence-rules.md, which the skill reads when it checks a model. Edit it there; the documentation includes it as is. The rules themselves are in the explorer template's <script id="coherence"> block.