thiagowfx's avatar

¬ just serendipity 🍀 (not just serendipity)

Mermaid: rich diagrams in markdown

• 175 words • 1 min • updated

⚠️ This post is over one year old. It may no longer be up to date or relevant. Opinions may have changed.

When writing documentation in markdown e.g. for projects stored in git, adding a system architecture or design diagram is a great way to boost its readability, especially to unfamiliar readers.

My favorite way to generate diagrams is with GraphViz. It is widely available and easy to use.

That said, MermaidJS has native integration with GitHub and GitLab circa 2 years ago, and that’s hard to beat. Graphviz, sadly, does not.

There is a live editor for quick prototyping and iteration: https://mermaid.live/

Once you are happy with the result, you can easily embed it in markdown1:

```mermaid
flowchart TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[fa:fa-car Car]
```

…and it will get automatically rendered in the aforementioned git forges.

MermaidJS is quite intuitive to use. There is plenty of documentation for it2, e.g. for graphs / flowcharts: https://mermaid.js.org/syntax/flowchart.html.


  1. This is one of the examples in the official documentation. ↩︎

  2. And, as increasingly common these days, you can always resort to GenAI for an extra push. ↩︎