Glossary

Diagram as code, and what the layout engine decides.

Text in, picture out. Which means the layout engine, not you, decides what it looks like.

Download for macOS
v0.1.33 · .dmg · Apple Silicon & Intel
Signed & notarized by Apple · opens without a Gatekeeper warning
sha256 698955a0187bc039f4c74f5d05a9f10fbb27376a45788a0a241d1326b73873c7
Download for Windows instead
$curl -fsSL https://lucidtrain.com/install.sh | sh

Diagram as code means expressing a diagram in a plain-text language that a renderer turns into an image, rather than positioning shapes in an editor. Mermaid, PlantUML, D2, Graphviz and Structurizr DSL are the common examples. The benefits are all consequences of being text: it lives in the repository, it diffs in a pull request, it is versioned with the code it describes, and it can be generated by a script. The recurring limitation is that you control the structure and the renderer's layout engine controls the picture.

Reviewability is the real argument

The strongest case has nothing to do with authoring speed. A binary diagram file changes opaquely in a pull request: the reviewer sees that a file changed and has no way to see what. A text diagram produces a readable diff, so a change to the architecture is reviewed alongside the change to the code, by the same person, at the same time. That is the property that keeps a diagram accurate.

Where it frustrates people

You describe nodes and edges; the renderer decides positions. When the result is nearly right, nudging it means fighting the layout algorithm through ranking hints and invisible edges, and the workarounds are notoriously unportable between renderers. This is the honest trade: you give up direct control of the picture in exchange for a diffable source.

The languages differ more than they look

Mermaid renders natively on GitHub, which is why it spread fastest, and its layout is the weakest of the group. PlantUML covers far more diagram types and needs Java or a server. D2 was designed later with layout quality as an explicit goal. Structurizr DSL is different in kind: you describe a model once and generate several C4 views from it, rather than writing each diagram separately.

The semantic graph variant

There is a related approach that is not quite the same thing: instead of a human writing text, an agent emits a structured graph of nodes, edges and tiers with no coordinates, and a constraint solver computes the layout. It gives up the human-writable source and gains layout quality, since a solver placing boxes cannot produce an overlap. This is what Lucid Train does, which makes it adjacent to diagram-as-code rather than an instance of it.

The common languages

LanguageRenders on GitHubNotable for
MermaidYes, nativelyReach, weakest layout
PlantUMLNoDiagram type coverage
D2NoLayout quality by design
GraphvizNoThe layout engine others build on
Structurizr DSLNoOne model, many C4 views
FAQ

Questions

Which diagram-as-code language should I choose?

If it must render in a GitHub README with no build step, Mermaid, and accept its layout. If layout quality matters more than portability, D2. If you want one model producing several C4 views, Structurizr DSL.

Why do diagram-as-code layouts look wrong so often?

Because the renderer decides positions from an algorithm that cannot know which relationships you consider important. Correcting it means manipulating the algorithm indirectly, which is the main source of frustration with the approach.

Can Lucid Train export Mermaid?

No. Exports are SVG, PNG at 2x, Markdown and Excalidraw scenes. There is no Mermaid or PlantUML output that the product renders or validates.

Related

Last updated