Mermaid Diagrams
by @wpank
Create software diagrams using Mermaid syntax. Use when users need to create, visualize, or document software through diagrams including class diagrams, sequence diagrams, flowcharts, ERDs, C4 architecture diagrams, state diagrams, git graphs, and other diagram types. Triggers include requests to diagram, visualize, model, map out, or show the flow of a system.
clawhub install mermaid-diagramsπ About This Skill
name: mermaid-diagrams model: fast version: 1.0.0 description: > Create software diagrams using Mermaid syntax. Use when users need to create, visualize, or document software through diagrams including class diagrams, sequence diagrams, flowcharts, ERDs, C4 architecture diagrams, state diagrams, git graphs, and other diagram types. Triggers include requests to diagram, visualize, model, map out, or show the flow of a system. tags: [diagrams, mermaid, visualization, architecture, documentation, modeling]
Mermaid Diagrams
Create professional software diagrams using Mermaid's text-based syntax. Mermaid renders diagrams from simple text definitions, making diagrams version-controllable, easy to update, and maintainable alongside code.
Installation
OpenClaw / Moltbot / Clawbot
npx clawhub@latest install mermaid-diagrams
Core Syntax
All Mermaid diagrams follow this pattern:
diagramType
definition content
Key principles:
classDiagram, sequenceDiagram, flowchart)%% for commentsDiagram Type Selection
| Type | Use For | Reference |
|------|---------|-----------|
| Class Diagrams | Domain modeling, OOP design, entity relationships | references/class-diagrams.md |
| Sequence Diagrams | API flows, auth flows, component interactions | references/sequence-diagrams.md |
| Flowcharts | Processes, algorithms, decision trees, user journeys | references/flowcharts.md |
| ERD | Database schemas, table relationships, data modeling | references/erd-diagrams.md |
| C4 Diagrams | System context, containers, components, architecture | references/c4-diagrams.md |
| State Diagrams | State machines, lifecycle states | β |
| Git Graphs | Branching strategies | β |
| Gantt Charts | Project timelines, scheduling | β |
For styling, themes, and layout options: See references/advanced-features.md
Quick Start Examples
Class Diagram (Domain Model)
classDiagram
Title -- Genre
Title *-- Season
Title *-- Review
User --> Review : creates class Title {
+string name
+int releaseYear
+play()
}
class Genre {
+string name
+getTopTitles()
}
Sequence Diagram (API Flow)
sequenceDiagram
participant User
participant API
participant Database User->>API: POST /login
API->>Database: Query credentials
Database-->>API: Return user data
alt Valid credentials
API-->>User: 200 OK + JWT token
else Invalid credentials
API-->>User: 401 Unauthorized
end
Flowchart (User Journey)
flowchart TD
Start([User visits site]) --> Auth{Authenticated?}
Auth -->|No| Login[Show login page]
Auth -->|Yes| Dashboard[Show dashboard]
Login --> Creds[Enter credentials]
Creds --> Validate{Valid?}
Validate -->|Yes| Dashboard
Validate -->|No| Error[Show error]
Error --> Login
ERD (Database Schema)
erDiagram
USER ||--o{ ORDER : places
ORDER ||--|{ LINE_ITEM : contains
PRODUCT ||--o{ LINE_ITEM : includes USER {
int id PK
string email UK
string name
datetime created_at
}
ORDER {
int id PK
int user_id FK
decimal total
datetime created_at
}
Best Practices
1. Start simple β begin with core entities/components, add details incrementally
2. Use meaningful names β clear labels make diagrams self-documenting
3. Comment extensively β use %% comments to explain complex relationships
4. Keep focused β one diagram per concept; split large diagrams into multiple views
5. Version control β store .mmd files alongside code for easy updates
6. Add context β include titles and notes to explain diagram purpose
7. Iterate β refine diagrams as understanding evolves
Configuration and Theming
Configure diagrams using frontmatter:
---
config:
theme: base
themeVariables:
primaryColor: "#ff6b6b"
flowchart LR
A --> B
Available themes: default, forest, dark, neutral, base
Layout options:
layout: dagre (default) β classic balanced layoutlayout: elk β advanced layout for complex diagramsLook options:
look: classic β traditional Mermaid stylelook: handDrawn β sketch-like appearanceRendering and Export
Native support in:
Export options:
npm install -g @mermaid-js/mermaid-cli then mmdc -i input.mmd -o output.pngWhen to Create Diagrams
Always diagram when:
Use diagrams to:
Common Pitfalls
{} in comments; escape special charactersNEVER Do
1. NEVER create diagrams with more than 15 nodes β they become unreadable; split into multiple focused diagrams 2. NEVER leave arrows unlabeled β every connection should explain the relationship or data flow 3. NEVER create diagrams without a title or caption β context-free diagrams are useless outside the author's head 4. NEVER use diagrams as the sole documentation β pair diagrams with prose that explains the "why" 5. NEVER let diagrams go stale β update diagrams when architecture changes; stale diagrams mislead 6. NEVER use Mermaid for data visualization β Mermaid is for architecture and flow diagrams, not charts of business data
π Tips & Best Practices
1. Start simple β begin with core entities/components, add details incrementally
2. Use meaningful names β clear labels make diagrams self-documenting
3. Comment extensively β use %% comments to explain complex relationships
4. Keep focused β one diagram per concept; split large diagrams into multiple views
5. Version control β store .mmd files alongside code for easy updates
6. Add context β include titles and notes to explain diagram purpose
7. Iterate β refine diagrams as understanding evolves