What "diagrams as code" means
Instead of dragging boxes, you write a few lines of text and a tool draws the diagram. The text sits in your repository, shows up in code review, and never goes out of date because nobody can find the original file. PlantUML, D2 and Mermaid are the three best known languages for this.
| Language | Good at | Looks like |
|---|---|---|
| PlantUML | UML: sequence, class, activity | @startuml … @enduml |
| D2 | Architecture and flows with containers | api -> db: query |
| Mermaid | Flowcharts, sequence, Gantt, many more | flowchart LR |
PlantUML: an activity diagram
The text behind it:
@startuml
start
:Enter email;
if (Account found?) then (yes)
:Send reset link;
:Set new password;
else (no)
:Show a neutral message;
endif
stop
@enduml
PlantUML sequence and class text work too, so a @startuml block you already have in a wiki opens as it is.
D2: a small architecture
The text behind it:
direction: right
user: User
web: Web app
api: API
db: Database
db.shape: cylinder
user -> web: opens
web -> api: requests
api -> db: query
name: Labelgives a node a readable label.a -> b: textdraws a labelled arrow.<-and<->point the other way or both ways.name.shape: cylinderchanges the shape; circle, diamond and hexagon work too.direction: rightlays the diagram out left to right.
Why open them in a drawing tool?
Text is great for keeping a diagram correct. It is less great for the last mile: nudging a label, adding a note for a slide, colouring one path, or showing it to someone who does not read code. Opening the text in an editor gives you both: generate the layout from text, then polish by hand.
Opening PlantUML and D2 in Chalkline
In Chalkline, open Diagram as text, paste PlantUML or D2 into the flowchart box and press Apply. Chalkline recognises the language on its own. Activity diagrams and D2 flows become normal flowcharts, so they stay linked: rename a shape on the board and the text updates. Everything runs in your browser; your text is never sent to a rendering server, which matters for diagrams of internal systems.
From there you can switch between hand drawn and clean, export to SVG, vector PDF, editable PowerPoint or TikZ for LaTeX, or embed the diagram on a web page. For Mermaid syntax, see the Mermaid flowchart cheat sheet. For sequence diagrams in detail, see the sequence diagram tutorial.