Sequence diagrams your agent cannot misdraw
Call flows are the diagram agents reach for most — auth handshakes, API chains, incident timelines — and the one they mangle worst when drawing characters by hand. In mdd a sequence diagram is a list of participants and an ordered list of messages: message order in the JSON is the layout, there are no layout decisions to get wrong, and the ASCII renders in READMEs, design docs, diffs, and terminals.
A login flow in a design doc
A login handshake as it appears spliced into a design doc: an actor, solid calls, dashed replies, and a self-message. The JSON lists participants left to right and messages in time order — the engine does the rest.
<!-- mdd:begin id=login-flow src=docs/login-flow.diagram.json --> ``` o ┌─────┐ ┌──────────┐ ┌──────────┐ /|\ │ App │ │ Auth API │ │ Sessions │ / \ └─────┘ └──────────┘ └──────────┘ User │ │ │ │ │ │ │ │ POST /login │ │ │ │────────────────▶│ │ │ │ │ │ │ │ │ verify(creds) │ │ │ │──────────────▶│ │ │ │ │ │ │ │ │ create session │ │ │ │───────────────▶│ │ │ │ │ │ │ │ session id │ │ │ │◀┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄│ │ │ │ │ │ │ │ sign JWT │ │ │ │──┐ │ │ │ │◀─┘ │ │ │ │ │ │ │ token │ │ │ │◀┄┄┄┄┄┄┄┄┄┄┄┄┄┄│ │ │ │ │ │ │ Set-Cookie; 302 │ │ │ │◀┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄│ │ │ │ │ │ │ ``` [diagram source](docs/login-flow.diagram.json) <!-- mdd:end -->
The model your agent edits
{
"version": 1,
"kind": "sequence",
"participants": [
{
"id": "user",
"label": "User",
"actor": true
},
{
"id": "app",
"label": "App"
},
{
"id": "auth",
"label": "Auth API"
},
{
"id": "db",
"label": "Sessions"
}
],
"messages": [
{
"from": "user",
"to": "app",
"label": "POST /login"
},
{
"from": "app",
"to": "auth",
"label": "verify(creds)"
},
{
"from": "auth",
"to": "db",
"label": "create session"
},
{
"from": "db",
"to": "auth",
"label": "session id",
"reply": true
},
{
"from": "auth",
"to": "auth",
"label": "sign JWT"
},
{
"from": "auth",
"to": "app",
"label": "token",
"reply": true
},
{
"from": "app",
"to": "user",
"label": "Set-Cookie; 302",
"reply": true
}
]
}Your agent draws it, you review it
- List the participants left to right and the messages top to bottom — the behavior reads as JSON in the order it happens. Your agent can draft it from a code trace.
- Run mdd render to splice the diagram into the doc; columns widen so labels always fit.
- When the flow changes, the agent inserts or reorders messages and re-renders — reordering a JSON array, never redrawing arrows.
- mdd check in CI fails if the rendered flow ever goes stale relative to the model.
A prompt to hand your agent
Maintain the login-flow sequence diagram in docs/auth.md with mdd. The source of truth is docs/login-flow.diagram.json (kind: "sequence" — participants left-to-right, messages in time order). After changing it, run: npx mdd render --json docs/login-flow.diagram.json --file docs/auth.md --id login-flow — then commit both files.
Why mdd here
Sequence diagrams are where hand-drawn ASCII fails hardest: every inserted message shifts every line below it, and a model eyeballing characters misaligns arrowheads and lifelines. In mdd the message array is the timeline — inserting a step is a one-line JSON edit, the engine recomputes every column and row, and call vs. reply is semantic (reply: true), not a hand-picked glyph.
More use cases
- AGENTS.md architecture maps — An architecture map in your agent context file: ASCII for humans, JSON ground truth for the agent.
- Diagrams in code comments — Header-comment state machines and layouts, computed from JSON and spliced behind // or #.
- Runbook flowcharts — Decision flows and failure maps readable in any terminal, drafted and updated by your incident tooling.
- Design docs, RFCs & ADRs — RFC and ADR system diagrams that stay legible in diffs across every revision round.
- Data pipeline lineage maps — A curated lineage map your agent keeps current as pipeline models change.
- Multi-agent orchestration maps — Agent hand-offs, tool wiring, and memory flow — documentation the agents themselves can update.
- Docs-as-code threat models — Data-flow diagrams with trust boundaries, drafted from the code and reviewed in the diff.
- Tutorials & conceptual docs — Conceptual diagrams that survive every downstream medium: docs site, README, PDF, chat.
- sequence diagram spec & schema