Diagrams for software documentation
Most code needs one diagram more than it needs another page of prose: the request flow, the order lifecycle, the shape of the domain model. Draw it once, keep it next to the code, and update it in the same pull request.
For: Developers and tech leads writing READMEs, design docs and onboarding guides
The problem
Documentation diagrams rot because they are expensive to change. They were drawn in a tool nobody else has a license for, exported as a PNG, and the source file lives on someone's laptop. Six months later the diagram is wrong and nobody can edit it, so it gets deleted or, worse, left in place.
Which diagrams fit
- Flowchart
- Request handling, retries, feature-flag logic and anything with branches. A flowchart is the diagram a new teammate can read without a legend.
- UML
- State diagrams for entities with a lifecycle, such as orders, subscriptions and documents, and class diagrams for the core domain model.
- Architecture diagram
- How services, queues and databases connect, for the top of a design doc or the README of a service.
A way of working
Sketch the flow as text first: type the steps into text to flowchart, or write Mermaid directly if the diagram will live in Markdown.
Open the result in the editor to fix what text cannot express: spacing, grouping, which branch is the happy path.
Export Mermaid (.mmd) for diagrams that should be diffed and reviewed with the code, or SVG for docs sites where precise layout matters.
Also export the .flowchart.json file and commit it next to the SVG, so the next person can reopen and edit the original instead of redrawing it.
Keep the source with the code
The rule that keeps documentation diagrams alive is that the editable source sits in the repository. Mermaid does this natively. For diagrams that need real layout, commit the SVG you embed alongside the .flowchart.json export it came from. A reviewer can see the diagram changed in the pull request, and the next author has a file to open instead of a picture to trace.
One diagram per question
A diagram that shows every service, every queue and every state answers no question well. Write the question first (how does a password reset work? what states can an order be in?) and draw only what answers it. Two small diagrams that each answer one question get read; one large one gets skimmed and then ignored.
SVG beats PNG in docs
SVG stays sharp on high-density screens and when readers zoom, its text is selectable and searchable, and it is usually smaller than the equivalent PNG. Exports from the editor have a white background so they read correctly on dark-mode documentation sites. Use PNG only where SVG is not accepted, such as some chat tools and slide apps.
Templates to start from
Tools for this job
Read next
- Diagrams as code
Mermaid flowchart syntax: a practical cheat sheet
Mermaid flowchart syntax on one page: directions, node shapes, link types, labels, subgraphs, styling and the gotchas that break a diagram, with copy-ready examples. - Flowcharts
How to draw decisions in a flowchart without the spaghetti
Practical rules for the flowchart decision diamond: how to phrase the question, label branches, route loops and keep the happy path straight, with a before-and-after example. - UML
UML class diagram relationships: association, aggregation, composition and the rest
The six UML class diagram relationships, the line and arrowhead for each, what they mean in code, how to read multiplicity, and when aggregation is worth drawing at all.
Questions
- Should documentation diagrams be Mermaid or images?
- Mermaid when the diagram changes with the code and a reviewer should see the change in a diff. An SVG image when layout matters more than diffability, for example an architecture overview at the top of a design doc. Many teams use both: Mermaid in READMEs, SVG in long-form docs.
- Can I convert a Mermaid diagram into an editable diagram?
- Yes, for flowcharts. Paste it into the Mermaid editor and choose Open in editor: nodes and links become shapes and connectors you can rearrange. Other Mermaid diagram types render and export as SVG or PNG but are not converted into shapes.
- Is it safe to paste internal code or schemas into the tools?
- Yes. Parsing, layout and export all run in your browser, and nothing you type is uploaded. That is why the tools work for internal table names, endpoints and payloads that should not leave your machine.