Architecture decision record

ADR-0007: Lay diagrams out in the browser, not with a graph-layout library

Accepted

2026-10-07Deciders: maintainers

Context

Agents draw diagrams of the user's code. Coordinates that a model places by hand overlap once a graph passes about eight nodes. The VS Code preview renders artifacts from their text through srcdoc, so a relative <script src> never loads there. The extension avoids heavy runtime dependencies, and elkjs, the strongest layout library, is EPL-2.0 and about 1.5 MB.

Decision

We will lay diagrams out in the browser. The agent gives each node a data-rank (its step along the flow) and a data-lane (its position across it). CSS grid places the nodes, and a small dependency-free runtime, inlined in the artifact by add_open_design_diagram_runtime, draws right-angle connectors through the gaps between ranks and lanes.

Options considered

OptionForAgainstOutcome
elkjs in Node, returning coordinatesBest compound layout and edge routingEPL-2.0, ~1.5 MB, the agent still transcribes coordinatesRejected
dagre in NodeMIT, smallWeak group layout, curved edges onlyRejected
Agent-placed SVG coordinatesNo machineryDegrades past ~8 nodes; several fix roundsRejected
CSS grid + inline runtimeBrowser measures text; same render in preview, export and check; no dependencyThe agent orders lanes; dense graphs can still crossChosen

Consequences

Positive

Negative

Neutral

Sources