make-a-diagram
Software diagram generator using Mermaid (v11+) with ELK layout, multi-format
rendering (SVG + PNG + ASCII), and automatic output to docs/diagrams/.
Principles
- Mermaid-First: All diagrams use Mermaid.js (v11) — clean, text-based,
version-control-friendly code.
- ELK Layout Default: Every diagram uses the ELK layout engine for
superior node placement on complex graphs.
- Multi-Format Output: Every diagram produces SVG (vector), PNG (raster),
and TXT (ASCII art) via beautiful-mermaid.
- Workspace Convention: Output always lands in
<workspace_root>/docs/diagrams/.
- Software Scope: Architecture, data flow, processes, schemas, state
machines, timelines. Not for UI mockups or organic visuals.
Preflight
Before rendering, run the dependency check:
bash scripts/check-deps.sh
Required dependencies:
| Dependency |
Purpose |
Install |
| Node.js >= 18 |
Runtime |
https://nodejs.org |
| @mermaid-js/mermaid-cli |
PNG rasterization |
npx @mermaid-js/mermaid-cli (auto-download) |
| beautiful-mermaid |
SVG + ASCII rendering |
npm install beautiful-mermaid |
If the check fails, it prints installation hints. The render script also
runs this check automatically.
Workflow
Generation
- Select Mermaid Type from the Capability Map below.
- Write Mermaid code — include the ELK layout config in frontmatter.
- Save to
docs/diagrams/[name].mmd.
- Render via
python scripts/render.py docs/diagrams/[name].mmd
(produces .svg, .png, .txt, _log.json).
- Validate: check syntax, label clarity, logical geometry.
Refinement Loop
- Show user the rendered diagram (SVG for web/docs, PNG for slides, ASCII for CLI).
- Accept feedback (labels, colors, layout, detail level).
- Iterate until approved.
Default Configuration (ELK Layout)
Every Mermaid diagram MUST include this frontmatter block:
---
config:
layout: elk
---
For flowchart-specific ELK renderer (alternative syntax):
---
config:
flowchart:
defaultRenderer: elk
---
Exceptions: Sequence diagrams and GitGraphs do not use layout engines;
omit the layout: elk config for those types.
Mermaid Capability Map (v11+)
| Diagram Type |
Directive |
Best for |
| Flowchart |
flowchart TD/LR |
Decision trees, data flow, pipelines, protocols |
| Sequence |
sequenceDiagram |
API calls, service interactions, message passing |
| Class |
classDiagram |
OOP structure, domain models, API schemas |
| ER Diagram |
erDiagram |
Database schemas, entity relationships |
| State |
stateDiagram-v2 |
State machines, lifecycle transitions |
| Block |
block-beta |
System architecture, component layout |
| C4 Context |
C4Context |
High-level system context with actors |
| C4 Container |
C4Container |
Container-level architecture view |
| Sankey |
sankey |
Flow quantities between nodes |
| Quadrant Chart |
quadrantChart |
Prioritization matrices, 2D positioning |
| Packet |
packet |
Network packet structure, bit ranges |
| Gantt |
gantt |
Release phases, sprint milestones |
| Timeline |
timeline |
Sequential events, version history |
| GitGraph |
gitGraph |
Repository history, branch strategy |
| Mindmap |
mindmap |
Feature brainstorming, concept mapping |
| XY Chart |
xychart-beta |
Bar/line charts from data |
| Pie |
pie |
Proportions, distribution |
| Journey |
journey |
User journey, experience mapping |
| Requirement |
requirementDiagram |
Requirements traceability |
See references/prompt-guide.md for worked patterns for each type.
Flowchart Node Shapes (v11.3+)
Mermaid v11.3 introduced 30+ expanded shapes via @{ shape: name } syntax.
See references/shape-reference.md for the complete catalog.
Quick reference — semantic mapping:
| Shape |
Use case |
rect (default) |
Process, service |
diam |
Decision |
hex |
Preparation, condition |
stadium |
Start/end terminal |
cyl |
Database |
doc |
File, report |
circle |
Simple endpoint |
cloud |
External service |
folder |
Module, namespace |
queue |
Message queue |
parallelogram |
I/O, data entry |
trap-t |
Manual operation |
subroutine |
Predefined process |
hourglass |
Timed/wait state |
delay |
Timeout |
flag |
Milestone |
fork |
Concurrency start |
Sequence Diagram Features (v11+)
- Participants:
participant, actor, entity, control, database,
queue, collections
- Aliases:
participant A as AliasName
- Boxes:
box Color GroupName ... end box
- Autonumbering:
autonumber <start> <increment>
- Create/Destroy:
create participant B, destroy participant B
- Central connections:
A --()--> B for central lifeline
- Actor menus/links:
link Actor: Label @ URL
- Half-arrows (v11.12.3+):
-|\, -|/, \-, /-, \\-, -//, //-
Arrow types: -> solid, --> dotted, ->> solid with arrow, -->> dotted
with arrow, -x solid with cross, --x dotted with cross, -) solid open,
--) dotted open, <<->> solid bidirectional, <<-->> dotted bidirectional.
Class Diagram Features (v11+)
- Visibility:
+public -private #protected ~package
- Relationships:
<|-- inheritance, *-- composition, o-- aggregation,
--> association, ..> dependency, ..|> realization
- Generics:
List~int~, Map~String, User~
- Annotations:
<<Interface>>, <<Abstract>>, <<Service>>, <<Enumeration>>
- Cardinality:
"1", "0..1", "1..", "*", "n..m"
- Namespaces (v11.15.0+):
namespace ns { ... }
- Lollipop interfaces:
foo --() bar
Block Diagram Features (v11+)
- Column layout with
columns N
- Composite blocks:
block D ... end block
- Width spanning:
a --2--- b
- Shapes:
round, stadium, subroutine, cylinder, circle, rhombus,
hexagon, trapezoid
- Edges with labels:
A --> B : label text
- Class styling:
classDef className fill:#f9f,stroke:#333
State Diagram Features (v11+)
- Composite states:
state Parent { child1 child2 }
- Choice nodes:
<<choice>>
- Fork/Join:
<<fork>>, <<join>>
- Concurrency:
-- separator for parallel states
- Notes:
note right of State : comment
Theming
Default theme: neutral (print-friendly, monochrome-safe).
Available themes: default, neutral, dark, forest, base (customizable).
Override via frontmatter:
---
config:
theme: dark
layout: elk
---
Customize via themeVariables with base theme for full color control.
Rendering Pipeline
Scripts
| Script |
Purpose |
check-deps.sh |
Preflight dependency checker |
render.py |
Orchestration: SVG + PNG + ASCII + log |
render_beautiful.mjs |
beautiful-mermaid wrapper (called by render.py) |
Commands
# Run preflight check
bash scripts/check-deps.sh
# Render all formats (SVG + PNG + ASCII + log)
python scripts/render.py docs/diagrams/[name].mmd
# Render to custom output directory
python scripts/render.py docs/diagrams/[name].mmd -o ./out
# ASCII-only with custom spacing
node scripts/render_beautiful.mjs ascii input.mmd output.txt --padding-x 7 --padding-y 3
# ASCII in pure-ASCII mode (no Unicode box-drawing)
node scripts/render_beautiful.mjs ascii input.mmd output.txt --ascii-only
Manual (if scripts unavailable)
# SVG + PNG via mermaid-cli
npx @mermaid-js/mermaid-cli mmd -i docs/diagrams/[name].mmd -o docs/diagrams/[name].svg
npx @mermaid-js/mermaid-cli mmd -i docs/diagrams/[name].mmd -o docs/diagrams/[name].png -b png
Fallback
If no renderers are available, provide .mmd code and direct user to
mermaid.live for preview.
Output Structure
<workspace_root>/
└── docs/
└── diagrams/
├── [name].mmd # Source (editable)
├── [name].svg # Vector (web/docs — beautiful-mermaid)
├── [name].png # Raster (slides — mermaid-cli)
├── [name].txt # ASCII art (CLI/terminal — beautiful-mermaid)
└── [name]_log.json # Metadata + audit log
Quality Standards
| Target |
Criteria |
| Architecture Doc |
High contrast, clear component boundaries, minimal noise |
| Technical Spec |
Accurate labels, logical layout, academic palette |
| README / Docs |
Readable at small sizes, monochrome-safe |
| Presentation |
High contrast, simplified labels, 6-8 elements max |
| CLI / Terminal |
Pure ASCII option available, max 80 chars wide |
1---2name: make-a-diagram3description: Generate software architecture diagrams, flowcharts, sequence diagrams, block diagrams, C4 models, ER schemas, Sankey flows, state machines, GitGraphs, timelines, and more using Mermaid (v11+) with ELK layout engine. Renders SVG, PNG, and ASCII art via beautiful-mermaid. Use when users ask to diagram, visualize, or map software concepts, system architecture, data flows, processes, or database schemas.4license: Apache-2.05---67# make-a-diagram89**Software diagram generator using Mermaid (v11+) with ELK layout, multi-format10rendering (SVG + PNG + ASCII), and automatic output to `docs/diagrams/`.**1112## Principles13141. **Mermaid-First**: All diagrams use Mermaid.js (v11) — clean, text-based,15 version-control-friendly code.162. **ELK Layout Default**: Every diagram uses the ELK layout engine for17 superior node placement on complex graphs.183. **Multi-Format Output**: Every diagram produces SVG (vector), PNG (raster),19 and TXT (ASCII art) via beautiful-mermaid.204. **Workspace Convention**: Output always lands in `<workspace_root>/docs/diagrams/`.215. **Software Scope**: Architecture, data flow, processes, schemas, state22 machines, timelines. Not for UI mockups or organic visuals.2324## Preflight2526Before rendering, run the dependency check:2728```bash29bash scripts/check-deps.sh30```3132Required dependencies:33| Dependency | Purpose | Install |34| :--- | :--- | :--- |35| Node.js >= 18 | Runtime | https://nodejs.org |36| @mermaid-js/mermaid-cli | PNG rasterization | `npx @mermaid-js/mermaid-cli` (auto-download) |37| beautiful-mermaid | SVG + ASCII rendering | `npm install beautiful-mermaid` |3839If the check fails, it prints installation hints. The render script also40runs this check automatically.4142## Workflow4344### Generation45461. **Select Mermaid Type** from the Capability Map below.472. **Write Mermaid code** — include the ELK layout config in frontmatter.483. **Save** to `docs/diagrams/[name].mmd`.494. **Render** via `python scripts/render.py docs/diagrams/[name].mmd`50 (produces `.svg`, `.png`, `.txt`, `_log.json`).515. **Validate**: check syntax, label clarity, logical geometry.5253### Refinement Loop54551. Show user the rendered diagram (SVG for web/docs, PNG for slides, ASCII for CLI).562. Accept feedback (labels, colors, layout, detail level).573. Iterate until approved.5859## Default Configuration (ELK Layout)6061Every Mermaid diagram MUST include this frontmatter block:6263```yaml64---65config:66 layout: elk67---68```6970For flowchart-specific ELK renderer (alternative syntax):7172```yaml73---74config:75 flowchart:76 defaultRenderer: elk77---78```7980Exceptions: Sequence diagrams and GitGraphs do not use layout engines;81omit the `layout: elk` config for those types.8283## Mermaid Capability Map (v11+)8485| Diagram Type | Directive | Best for |86| :--- | :--- | :--- |87| **Flowchart** | `flowchart TD/LR` | Decision trees, data flow, pipelines, protocols |88| **Sequence** | `sequenceDiagram` | API calls, service interactions, message passing |89| **Class** | `classDiagram` | OOP structure, domain models, API schemas |90| **ER Diagram** | `erDiagram` | Database schemas, entity relationships |91| **State** | `stateDiagram-v2` | State machines, lifecycle transitions |92| **Block** | `block-beta` | System architecture, component layout |93| **C4 Context** | `C4Context` | High-level system context with actors |94| **C4 Container** | `C4Container` | Container-level architecture view |95| **Sankey** | `sankey` | Flow quantities between nodes |96| **Quadrant Chart** | `quadrantChart` | Prioritization matrices, 2D positioning |97| **Packet** | `packet` | Network packet structure, bit ranges |98| **Gantt** | `gantt` | Release phases, sprint milestones |99| **Timeline** | `timeline` | Sequential events, version history |100| **GitGraph** | `gitGraph` | Repository history, branch strategy |101| **Mindmap** | `mindmap` | Feature brainstorming, concept mapping |102| **XY Chart** | `xychart-beta` | Bar/line charts from data |103| **Pie** | `pie` | Proportions, distribution |104| **Journey** | `journey` | User journey, experience mapping |105| **Requirement** | `requirementDiagram` | Requirements traceability |106107See `references/prompt-guide.md` for worked patterns for each type.108109## Flowchart Node Shapes (v11.3+)110111Mermaid v11.3 introduced 30+ expanded shapes via `@{ shape: name }` syntax.112See `references/shape-reference.md` for the complete catalog.113114Quick reference — semantic mapping:115116| Shape | Use case |117| :--- | :--- |118| `rect` (default) | Process, service |119| `diam` | Decision |120| `hex` | Preparation, condition |121| `stadium` | Start/end terminal |122| `cyl` | Database |123| `doc` | File, report |124| `circle` | Simple endpoint |125| `cloud` | External service |126| `folder` | Module, namespace |127| `queue` | Message queue |128| `parallelogram` | I/O, data entry |129| `trap-t` | Manual operation |130| `subroutine` | Predefined process |131| `hourglass` | Timed/wait state |132| `delay` | Timeout |133| `flag` | Milestone |134| `fork` | Concurrency start |135136## Sequence Diagram Features (v11+)137138- **Participants**: `participant`, `actor`, `entity`, `control`, `database`,139 `queue`, `collections`140- **Aliases**: `participant A as AliasName`141- **Boxes**: `box Color GroupName ... end box`142- **Autonumbering**: `autonumber <start> <increment>`143- **Create/Destroy**: `create participant B`, `destroy participant B`144- **Central connections**: `A --()--> B` for central lifeline145- **Actor menus/links**: `link Actor: Label @ URL`146- **Half-arrows** (v11.12.3+): `-|\`, `-|/`, `\-`, `/-`, `\\-`, `-//`, `//-`147148Arrow types: `->` solid, `-->` dotted, `->>` solid with arrow, `-->>` dotted149with arrow, `-x` solid with cross, `--x` dotted with cross, `-)` solid open,150`--)` dotted open, `<<->>` solid bidirectional, `<<-->>` dotted bidirectional.151152## Class Diagram Features (v11+)153154- **Visibility**: `+public -private #protected ~package`155- **Relationships**: `<|--` inheritance, `*--` composition, `o--` aggregation,156 `-->` association, `..>` dependency, `..|>` realization157- **Generics**: `List~int~`, `Map~String, User~`158- **Annotations**: `<<Interface>>`, `<<Abstract>>`, `<<Service>>`, `<<Enumeration>>`159- **Cardinality**: `"1"`, `"0..1"`, `"1.."`, `"*"`, `"n..m"`160- **Namespaces** (v11.15.0+): `namespace ns { ... }`161- **Lollipop interfaces**: `foo --() bar`162163## Block Diagram Features (v11+)164165- **Column layout** with `columns N`166- **Composite blocks**: `block D ... end block`167- **Width spanning**: `a --2--- b`168- **Shapes**: `round`, `stadium`, `subroutine`, `cylinder`, `circle`, `rhombus`,169 `hexagon`, `trapezoid`170- **Edges with labels**: `A --> B : label text`171- **Class styling**: `classDef className fill:#f9f,stroke:#333`172173## State Diagram Features (v11+)174175- **Composite states**: `state Parent { child1 child2 }`176- **Choice nodes**: `<<choice>>`177- **Fork/Join**: `<<fork>>`, `<<join>>`178- **Concurrency**: `--` separator for parallel states179- **Notes**: `note right of State : comment`180181## Theming182183Default theme: `neutral` (print-friendly, monochrome-safe).184185Available themes: `default`, `neutral`, `dark`, `forest`, `base` (customizable).186187Override via frontmatter:188189```yaml190---191config:192 theme: dark193 layout: elk194---195```196197Customize via `themeVariables` with `base` theme for full color control.198199## Rendering Pipeline200201### Scripts202203| Script | Purpose |204| :--- | :--- |205| `check-deps.sh` | Preflight dependency checker |206| `render.py` | Orchestration: SVG + PNG + ASCII + log |207| `render_beautiful.mjs` | beautiful-mermaid wrapper (called by render.py) |208209### Commands210211```bash212# Run preflight check213bash scripts/check-deps.sh214215# Render all formats (SVG + PNG + ASCII + log)216python scripts/render.py docs/diagrams/[name].mmd217218# Render to custom output directory219python scripts/render.py docs/diagrams/[name].mmd -o ./out220221# ASCII-only with custom spacing222node scripts/render_beautiful.mjs ascii input.mmd output.txt --padding-x 7 --padding-y 3223224# ASCII in pure-ASCII mode (no Unicode box-drawing)225node scripts/render_beautiful.mjs ascii input.mmd output.txt --ascii-only226```227228### Manual (if scripts unavailable)229230```bash231# SVG + PNG via mermaid-cli232npx @mermaid-js/mermaid-cli mmd -i docs/diagrams/[name].mmd -o docs/diagrams/[name].svg233npx @mermaid-js/mermaid-cli mmd -i docs/diagrams/[name].mmd -o docs/diagrams/[name].png -b png234```235236### Fallback237238If no renderers are available, provide `.mmd` code and direct user to239[mermaid.live](https://mermaid.live/edit) for preview.240241## Output Structure242243```244<workspace_root>/245└── docs/246 └── diagrams/247 ├── [name].mmd # Source (editable)248 ├── [name].svg # Vector (web/docs — beautiful-mermaid)249 ├── [name].png # Raster (slides — mermaid-cli)250 ├── [name].txt # ASCII art (CLI/terminal — beautiful-mermaid)251 └── [name]_log.json # Metadata + audit log252```253254## Quality Standards255256| Target | Criteria |257| :--- | :--- |258| Architecture Doc | High contrast, clear component boundaries, minimal noise |259| Technical Spec | Accurate labels, logical layout, academic palette |260| README / Docs | Readable at small sizes, monochrome-safe |261| Presentation | High contrast, simplified labels, 6-8 elements max |262| CLI / Terminal | Pure ASCII option available, max 80 chars wide |