Documentation
/ Reference
Diagram style
Every Mermaid diagram in this repository follows one house style, "Knowledge Cartography": a parchment-and-ink palette, six node roles carried by shape and colour, one question per diagram, and a width rule. The point is not decoration. Hive's central claims are about where things run: recall is code, a model is optional and key-gated, a person approves before anything is served, and only a projected subset of a card can leave. A diagram in this style makes those claims visible at a glance, and a diagram that broke the style would quietly say something the code does not.
The style is enforced. tools/check-docs.py refuses a block that does not follow it,
tools/restyle-diagrams.py writes the boilerplate so nobody edits it by hand, and
tools/render-diagrams.py renders every diagram and fails one that breaks or comes out too wide.
The checker and renderer run in the docs-check job of CI on every pull request. Run the
restyle tool locally when authoring a diagram; CI checks the result without rewriting it.
Six roles, by shape and colour
| Role | Shape | Fill / border | Mermaid | Ink on fill | Border on fill |
|---|---|---|---|---|---|
| Deterministic code | rectangle ["…"] |
cream #f3ead6 / #2f5d50 |
default, no class | 12.5 : 1 | 6.3 : 1 |
| Human gate | hexagon {{"…"}} |
amber #fbeecf / #b7791f |
class x gate |
12.9 : 1 | 3.2 : 1 |
| Model | rectangle, dashed | lilac #ece6f8 / #6b4fbb |
class x model |
12.2 : 1 | 5.0 : 1 |
| Store | cylinder [("…")] |
slate #e3ebf3 / #3b5b7e |
class x store |
12.4 : 1 | 5.9 : 1 |
| Trust boundary or refusal | rectangle, 3px border | terracotta #f7e1dc / #a63d2f |
class x boundary |
11.9 : 1 | 5.0 : 1 |
| Person or agent | stadium (["…"]) |
grey #eeeeee / #6b7280 |
class x actor |
12.8 : 1 | 4.2 : 1 |
Ink is #1f2a1f, edges are #4f7f70, edge labels sit on #fdfaf3, and a territory (a
subgraph) is #faf6ee with a #8a9a95 border. Every text-on-fill pair is above 11 : 1 and the
edge colour is above 4 : 1 on both GitHub backgrounds (WCAG relative luminance).
Unclassed means deterministic code. That is the honest default: "this runs in code" is what
most of Hive is, and a model or a gate has to be marked to appear as one. A check that code
performs with a pass and a fail branch is a decision diamond {"…"}, unclassed; the amber hexagon
is reserved for a decision a person makes.
Typography and lines
- Font. GitHub's own body stack, set at the top level of the header (
fontFamily), at 16px. Web fonts are not available inside GitHub's render iframe, and afontFamilyunderthemeVariablesproduces an emptyfont-familyin the SVG and a serif fallback. - Labels. At most three short lines. Module names and file names are allowed; no run of uppercase words longer than one per line.
- Edges. Solid
-->is always, in code. Dotted-.->is optional or indirect: only with a key configured, a signal that may be empty, or a hand-off the next actor completes. Thick==>is a write that passes human review before it lands. Edge labels are two to four words. - Direction.
LRorTB, neverTD(a synonym; one spelling so a grep finds every top-to-bottom diagram).
Two looks
- Hand-drawn (
look: handDrawn) for concept and onboarding sketches: the README's recall and ranking pair, the overview lifecycle, a one-idea sketch inconcepts/. - Classic for anything with territories or boundaries: package maps, deployments, trust
boundaries, privacy projection, the release pipeline, and every diagram under
reference/.
A hand-drawn block never contains a subgraph: on a dark page the cluster's hachure fill stripes
every node inside it. Hand-drawn blocks always carry handDrawnSeed: 7; without a seed every
render moves every path, so two renders of the same source never compare equal.
Grammar
- One question per diagram, and
accTitleis that question. - Twelve nodes or fewer, where the subject allows it.
- Width rule: natural width at 16px under 1100px, measured from the rendered SVG's
max-width. Four columns left-to-right at most; otherwise top-to-bottom. GitHub scales a wider diagram into its column, and the README hero used to render its labels at roughly 8px. - Unclassed means deterministic code.
- Territories are subgraphs, classic look only, named in plain words. A subgraph title may carry one clause of a claim the docs already make ("reads cards · writes no card").
- A gate is named by what a person approves. A number may accompany it only where the page's
prose numbers its gates the same way, and it is written
Gate 1, neverGATE 1. - No glyphs: no circled digits, emoji or arrow characters in labels. The middle dot
·is the only separator. - A model call is drawn as the model: a dashed lilac node pointing at the code that consults it, never as a colour on the code node. A keyless serving path has no lilac on it.
- Exact words for exact claims, reused verbatim from the docs: "no model by default", "optional · key-gated", "fails open", "writes no card", "only title + description", "never given to the layer". A diagram never strengthens a claim the prose makes.
- A restyle of an existing diagram keeps its nodes, its edges and its words. If the drawing has to change to fit the width rule, it changes layout, not content.
README hierarchy
- Hero, under "How it flows": the active engine map, classic, top-to-bottom.
- Under "Deterministic first, semantic optional": the recall sketch and the ranking sketch, hand-drawn, one per paragraph.
- Under "Privacy posture": what may reach a configured provider, classic.
- Badges and tables unchanged; no logo, banner or image. The README's identity is the map.
docs/README.mdholds the legend once, under "How to read the diagrams".
Accessibility
- Every diagram has
accTitleandaccDescr. Mermaid emits them as the SVG<title>and<desc>, which is what a screen reader announces. - Role is never colour alone: the shape and the words carry it.
- Text on fills is at least 7 : 1 (every role exceeds 11 : 1); edges at least 4 : 1 on both GitHub backgrounds.
- Effective type size on GitHub is at least 12px, which is what the width rule guarantees.
- No information in glyphs, no animation.
- The paragraph before a diagram states its claim, so a reader who skips figures loses nothing.
The canonical header
Every block starts with this front-matter, byte for byte. tools/mermaid-header.yaml is the one
copy; the check compares against it and the restyle script writes it.
---
config:
theme: base
fontFamily: "-apple-system, BlinkMacSystemFont, Segoe UI, Noto Sans, Helvetica, Arial, sans-serif"
themeVariables:
fontSize: "16px"
primaryColor: "#f3ead6"
primaryTextColor: "#1f2a1f"
primaryBorderColor: "#2f5d50"
lineColor: "#4f7f70"
textColor: "#1f2a1f"
edgeLabelBackground: "#fdfaf3"
clusterBkg: "#faf6ee"
clusterBorder: "#8a9a95"
titleColor: "#1f2a1f"
sequence:
actorMargin: 24
messageMargin: 24
width: 120
---
The hand-drawn variant is the same header with two lines directly under config::
look: handDrawn
handDrawnSeed: 7
theme: base is load-bearing: without it Mermaid ignores every themeVariables entry except
lineColor and renders its default lavender. It also pins the parchment on GitHub's dark colour
mode, which is the intended identity; the palette was checked against #0d1117 as well as white.
The sequence block tightens participant spacing so a five- or six-participant sequence diagram
fits the width rule; it has no effect on any other diagram type. GitHub controls its own Mermaid
renderer and can update it independently of the local tool. A local render checks the selected
CLI's behavior, not GitHub's current version or supported configuration. Inspect the rendered
Markdown on GitHub before relying on a new configuration key.
Every flowchart ends with the five role definitions, verbatim:
classDef gate fill:#fbeecf,stroke:#b7791f,color:#1f2a1f
classDef model fill:#ece6f8,stroke:#6b4fbb,stroke-dasharray:6 4,color:#1f2a1f
classDef store fill:#e3ebf3,stroke:#3b5b7e,color:#1f2a1f
classDef boundary fill:#f7e1dc,stroke:#a63d2f,stroke-width:3px,color:#1f2a1f
classDef actor fill:#eeeeee,stroke:#6b7280,color:#1f2a1f
Sequence, state and entity-relationship diagrams carry the header and the accessibility lines only; the roles are a flowchart vocabulary.
The checks
tools/check-docs.py (stdlib, no install) refuses a Mermaid block that:
- does not start with the canonical header, classic or hand-drawn;
- has no
accTitleor noaccDescr; - spells its direction
TD; - contains an arrow, circled-digit or emoji glyph anywhere;
- is hand-drawn and contains a
subgraph; - is a flowchart whose
classDeflines are not exactly the canonical five, or which references a class that is not one of the five roles.
tools/restyle-diagrams.py writes the header and the class definitions into every block,
idempotently, keeping the hand-drawn variant where a block already asks for it. It never touches
nodes, edges, labels or accessibility lines. A palette change is one edit to the header file or to
the class definitions in check-docs.py, then one run of this script.
tools/render-diagrams.py renders every scanned Markdown file with
@mermaid-js/mermaid-cli, fails on any render error, and
fails any diagram whose max-width exceeds 1100px. It needs Node 20 or newer and a Chromium;
point PUPPETEER_EXECUTABLE_PATH at a browser you already have. --out DIR keeps the SVGs, which
is how to measure a diagram or compare a restyle against the previous render.
The command uses MMDC when set, then mmdc on PATH, otherwise npx with the version pinned
in MERMAID_CLI_VERSION in the script. An override or an installed mmdc can therefore differ
from that pin. The script prints its selected command before rendering. Its Markdown input mode
renders all blocks in one file in one browser launch, rather than starting a browser for each block:
PUPPETEER_EXECUTABLE_PATH=/usr/bin/chromium-browser python3 tools/render-diagrams.py --out build/diagrams
grep -o 'max-width:[^;"]*' build/diagrams/*/rendered-*.svg
The whole tree renders in well under a minute, one browser launch per file.
Adding or changing a diagram
- Write the paragraph that states the claim, then the block: the diagram type line,
accTitle,accDescr, nodes with the shape their role wants, edges with the line kind their meaning wants, andclassstatements for every node that is not code. Leave the header out. - For a hand-drawn sketch, start the block with three lines:
---,config:andlook: handDrawn, then---. - Run
python3 tools/restyle-diagrams.py; it writes the header and the class definitions. - Run
python3 tools/check-docs.pyandpython3 tools/render-diagrams.py. If the diagram is over 1100px, lay it out top-to-bottom or wrap labels; do not shrink the font. - Reviewer checklist for a restyle: same nodes, same edges, same words.
Review the layout, not only the width
A successful render and a passing width check do not establish that the drawing is clear. Inspect the rendered diagram in context, on both light and dark backgrounds:
- Trace every edge from its real source to its target. An edge passing behind an unrelated node can look like an arrow from that node; simplify the route rather than accepting that ambiguity.
- Check subgraph titles against entering edges. Shorten or deliberately break a title with
<br/>if the edge crosses it. - Check the actual placement of nodes after adding links across subgraph boundaries. Do not
assume a subgraph's
directionor the declaration order guarantees the final layout. - Treat invisible
~~~links as layout constraints, not harmless spacers. Inspect the ranks and edge routes again after adding one. - Use deliberate
<br/>breaks for labels that wrap awkwardly. Keep the font size and width rule rather than shrinking text to conceal a crowded layout.
Deliberately left out
A logo, banner or social-preview image (a product decision, not a documentation one); a docs site; pre-rendered SVG assets in git (nothing Hive publishes needs them: the package READMEs shipped to PyPI contain no diagrams, and GitHub renders Mermaid natively with its zoom and copy-source controls); hand-authored SVG or Excalidraw sources (editable Markdown is worth more here than pixel control, and Mermaid's hand-drawn look covers the sketch register).