Skip to content

0012 - Architecture Diagrams in Taskbase

Status

Accepted. Built in Taskbase epics 43 (data model, API and MCP tools), 44 (builder UI with automatic layout) and 45 (agents keep diagrams current), tasks #698–#703. This record is written after the fact, from the merged code. Builds on ADR-0003 and ADR-0005.

Amended 2026-10-10 by the Taskbase diagram simplification (docs/diagram-simplification.md in Skatzi/taskbase, steps 1–4): rule W added to rule 3, and the presentation rules L, F, M, H and B added.

Date

2026-10-09 (amended 2026-10-10)

Context

Each organization in Taskbase has systems worth drawing: the Skatzi platform, Taskbase itself, Botyard. Drawings kept in draw.io files or wiki pages go stale, because the people who change the systems do not open them, and the agents that now do most of the changes cannot edit them.

We want architecture diagrams that agents can maintain and people can edit, kept per organization next to the projects and tasks that change the systems:

  • An agent that adds a service in a task should add it to the diagram in the same task, without working out where to draw it.
  • A person should be able to open the diagram, drag things into place, and have that placement survive later changes by agents.
  • Who changed what, and why, should be visible, and a bad change should be easy to undo.

Options considered

Option For Against
Mermaid or D2 text in a repository Agents write text well; diffs in PRs The renderer decides the layout. There is no stable manual placement: adding one node can reshuffle the whole drawing, and a person cannot pin a box where it belongs
draw.io XML in a repository People already know the editor; full control of layout Agents have to edit coordinates and styles in XML. They cannot reliably place a box without overlapping others, and a semantic change ("add a queue between these two") is a geometry problem
A diagram-as-code file of our own (YAML of components plus a positions section) Git history and PR review We would write the parser, validator, layout and editor anyway, and the editor would have to commit to Git for every drag. Two writers (agent and person) would conflict in the file
A builder in Taskbase over database rows with semantic components (chosen) Agents send small validated ops by meaning; people edit on a canvas; layout is a separate layer that rules fill in No Git history; agents need the MCP server; we build and own a canvas

Decision

Taskbase gets architecture diagrams stored as database rows, made of semantic components — what something is (a service, a database, a queue…), not drawing primitives. A diagram belongs to one organization. Agents and people change it through the same API.

The design has three layers, each with one writer.

flowchart LR
    Agent[Agent via MCP] -->|op batches| Model
    Person[Person in the UI] -->|op batches| Model
    Person -->|drags, tidy up, reset| Positions
    Engine[Layout rules in the UI] -->|placements saved as auto| Positions
    Model[Model: components and connections] --> Canvas
    Positions[Positions: manual or auto] --> Canvas
    Engine --> Canvas

1. The model: components and connections

  • A component has a key (a stable, readable slug such as taskbase-api, which never changes), a type, a name, an optional parent group, and optional tech, description, url and a linked Taskbase project.
  • A connection links two components, with a label, a protocol and a bidirectional flag. Its key is generated as <from>--<to>.
  • The model only changes through an atomic batch of ops (add_component, update_component, remove_component, add_connection, update_connection, remove_connection) sent against a base_revision. Every op is validated. A batch either applies in full or is refused with an error per op, e.g. ops[2].parent: no group with key "taskbse" (did you mean "taskbase"?). A batch on a stale revision is refused with 409.
  • Every applied batch bumps the diagram's revision and records a revision row with the author (person or agent persona), the run, a summary, the ops as applied and a full snapshot of the model.
  • People (in the UI) and agents (through MCP) use the same ops.

2. Layout positions: manual or auto

  • Positions are a separate table, one row per component, with x, y and a source: manual (a person dragged it) or auto (the layout rules placed it).
  • Positions are written by the UI only. The MCP server has no position tool, and get_diagram leaves positions out, so agents never see or compute coordinates.
  • Positions are not part of revisions: last write wins, and they do not bump the revision.
  • A component without a position is placed by the rules the next time someone opens the diagram, and the result is saved as auto, so every viewer sees the same layout.

3. Rule-based automatic placement

A pure TypeScript module in the UI (ui/src/diagramLayout/) places components. It is deterministic — the same model and positions always give the same result, with ties broken by component key — and no agent does any layout.

  1. Every position is stored as manual or auto.
  2. Nothing that already has a position moves on its own. Adding a component never reshuffles the others. There are two exceptions, both for auto components only: the group push-aside of rule 5, and an auto component other than a group that overlaps a sibling (for example a position stored before the boxes grew), which is placed again like a new one (rule 3) and saved. Of overlapping auto components the topmost, then leftmost, stays; manual components and groups never move this way.
  3. A new component goes into its parent group, in the column of its tier, level with the placed component it shares the most connections with (else at the top), in the first free slot on an 8 px grid that keeps 40 px from everything.
    • Rule W — wrap tall tier columns. A tier column in one container holds at most 6 components (MAX_COLUMN). A tier with more children gets sub-columns: the 7th starts a sub-column one COLUMN_PITCH (280 px) to the right, and the columns of later tiers start after the last sub-column. A new component joins the first sub-column that has room, still level with its best-connected placed neighbour where there is room. A container with at most 6 components per tier lays out as before. Rule W applies only to placing new components: stored auto and manual positions never move because of it, so existing diagrams change only through Tidy up, which is unchanged.
  4. Tiers, left to right: person → service → queue → datastore. An external that only receives connections goes to the rightmost column; one that sends goes to the leftmost. A group takes the majority tier of its children. A note goes to the top right of its group.
  5. Groups size themselves to fit their children plus padding. A group that grows into an auto sibling pushes it right or down; manual siblings never move. Moving a group moves its children.
  6. Connections are always routed automatically; there are no hand-bent lines. How routes are drawn — merged, bundled or replaced by chips — is part of the presentation rules.
  7. "Tidy up" lays out every auto component again with a full layered layout (ELK), partitioned by tier. manual components stay where they are, and the result never overlaps them.

Presentation rules

The canvas does not draw the model one-to-one: a presentation layer in the UI (ui/src/diagramSimplify.js, ui/src/diagrams.js and routeEdges in ui/src/diagramLayout/edgeRoutes.ts) decides what is drawn, to keep large diagrams readable. Its rules are bound by four guardrails, which are their contract:

  • No information lost. Every component and connection stays in the model and stays reachable in the UI: a hidden label shows on focus or with the Labels toggle, a merged line lists its members, a chip stands for its connection.
  • Deterministic. All rules are pure functions of the model, the stored positions and the zoom. Ties are broken by key, so every viewer sees the same drawing.
  • Manual positions are never moved. The presentation rules write no data and move no position; rule W (above) only places new components.
  • MCP and ops contract unchanged. No API, op or MCP tool changes; agents still see and edit every connection on its own.

The rules:

  • L — Labels on demand. At rest no connection label is drawn, at any zoom. A connection's label shows while the connection or one of its ends is hovered, focused or selected (rule F). A Labels toggle in the canvas toolbar shows the labels of all drawn lines (not in the overview below 60 % zoom, where only a focused connection's label shows, and not of lines replaced by chips, rule H); it is off by default and remembered per browser in localStorage under diagram.labels. At rest edges are 1 px in a muted colour (--diagram-edge, in light and dark); focused edges are 2 px in the accent colour.
  • F — Focus. Hovering a component, or selecting it (click, tap, or Enter on a keyboard-focused node), focuses it: its connections, including those hidden as hub chips (rule H), are drawn at full strength with labels, its neighbours keep full opacity, and everything else drops to 25 % opacity. Hovering a connection focuses it and its two ends. Esc or a click on the empty canvas clears focus, before Esc does anything else. Focus never changes positions.
  • M — Merge parallel connections. All connections between the same unordered pair of components are drawn and routed as one line, keyed by the sorted pair. It has an arrowhead at every end that is the to of one of its members, or of a bidirectional one. Its label lists the member labels joined by " / ", or reads "N connections" for three or more. Clicking it opens the connection panel, which lists every member to select, edit or delete. The model, ops and undo stay per connection.
  • H — Hubs as chips. A component that is not a group or note is a hub when, after rule M, it has at least 6 distinct neighbours whose parent containers (the direct parent group, or the top level) number at least 3. A line between a hub and a neighbour that is not a hub and sits in another container is not drawn; the neighbour shows a chip instead — the hub's type icon and name (cut at 14 characters) as a pill at the bottom of its box, at most 3 per box sorted by hub key, then "+N". A chip is a button (e.g. aria-label "Connected to Keycloak: OIDC login · OIDC"); hovering or focusing it draws its connection, and focusing the hub draws all its lines. Hub-to-hub and same-container lines stay lines.
  • B — Bundle routes that share an end. In routeEdges, routes with the same source, or the same target, share a stretch at no extra cost and one lane, so a fan-out is drawn as one trunk that branches near its targets. Routes that share a corridor but no end still pay for it and are moved apart into lanes (LANE, MAX_NUDGE).

Considered and not chosen (for now):

  • Collapsing groups by default (or lifting cross-group connections to group pairs): in our diagrams one group holds most of the system, so collapsing it hides nearly everything, and lifting reduced 58 lines only to 50. Collapsible groups may come later as an action a person takes, not as a default.
  • Hiding whole connections depending on the zoom: the same diagram would look different from one zoom to the next. Hub chips and focus do the same job with information that does not depend on the zoom.
  • Rejecting duplicate connections in the API: that changes the agent contract. Rule M already takes care of how duplicates look.

Consequences

  • No Git history. Diagrams are not in a repository, so there is no PR review or git log for them. Revisions replace it: each records who changed what, with a summary that names the task, and any revision can be restored, which records a new revision equal to the old one ([{"restore": n}]). Deleting a diagram deletes its history.
  • Agents need MCP. An agent changes diagrams only through the Taskbase MCP tools (list_diagrams, get_diagram, create_diagram, apply_diagram_ops, list_diagram_revisions), with the organization grant it already has for tasks. Agents cannot delete diagrams, restore revisions or write positions.
  • Seven v1 types: group (a system, cluster or network; can nest), service, datastore, queue, external, person, note. Notes take no connections, and a component's type cannot change (remove it and add it again).
  • Adding a type touches every layer, in one Taskbase change:
    • API: a migration widening the type check on diagram_components, and Types in api/internal/diagram/model.go;
    • MCP: the type list in the apply_diagram_ops description (mcp/internal/tools/diagrams.go);
    • layout: ComponentType in diagramLayout/types.ts, its size in NODE_SIZES and its column in TIERS/tierOf;
    • UI: a node in NODE_TYPES (DiagramCanvas.jsx), its icon in ICON_PATHS (diagramIcons.jsx, shared by the node and the palette), and its label in COMPONENT_TYPE_LABELS (diagrams.js), which also puts it in the palette;
    • docs: the type table in Architecture Diagrams.
  • People and agents can edit the same diagram at once. The UI polls every 10 seconds and re-sends a stale batch on the latest revision; if the API then refuses it, the change is dropped and the person is told.
  • We own a canvas (React Flow) and a layout module, and their tests.

What we deferred (and what would trigger adding it)

From epic 43 (data model, API and MCP tools):

Deferred Trigger
Mermaid/PNG/SVG export Someone needs a diagram outside Taskbase
Other diagram kinds (sequence, flow) Architecture diagrams are in regular use
Custom component types per organization The seven types prove too few
Git export/sync Diagrams need PR review
Comments on components People discuss diagrams in Taskbase
Links from tasks to components Agents keep diagrams current routinely

From epic 44 (builder UI with automatic layout):

Deferred Trigger
Real-time collaborative editing (live cursors); v1 polls and handles conflicts Two people regularly edit the same diagram at once
Manually bent connections and resizable groups Auto-routing is clearly not good enough
Themes and colours per component The type styling isn't enough
Minimap and search Diagrams exceed about 60 components

From epic 45 (agents keep diagrams current):

Deferred Trigger
Automatic drift detection (comparing diagrams to the repositories and cluster on a schedule) Stale diagrams are noticed despite the persona rule
The reviewer checking that diagram updates were made Developers forget often
Diagram updates as a separate follow-up task type Doing them inside the task proves too noisy