Install
$ agentstack add skill-magnus919-agent-skills-mermaid-diagrams ✓ scanned · ✓ verified — works with Claude Code, Cursor, and more.
Security review
✓ PassedNo issues found. Passed automated security review. · v0.1.0 How review works →
- ✓ Prompt-injection patterns
- ✓ Secret / credential exfiltration
- ✓ Dangerous shell & filesystem operations
- ✓ Untrusted network calls
- ✓ Known-malicious package signatures
What it can access
- ✓ Network access No
- ✓ Filesystem access No
- ✓ Shell / process execution No
- ✓ Environment & secrets No
- ✓ Dynamic code execution No
From automated source analysis of v0.1.0. “Used” means the capability is present in the source — more access means more to trust, not that it’s unsafe.
About
Mermaid Diagrams
Portable Mermaid.js diagramming for architectural documentation. Not tied to any blog platform, theme, or rendering engine. Diagrams can be rendered via CLI, embedded in markdown, or served as HTML snippets.
When to Use
Load this skill when:
- Creating C4 structural views (use Structurizr DSL for production; flowchart workarounds for inline markdown)
- Producing sequence diagrams for interaction flows
- Designing flowcharts for process documentation
- Building state/class/ER diagrams for specification
- Generating any diagram that needs to render in both agent-facing and human-facing contexts
Do NOT load when:
- A plain text outline communicates the relationship more clearly than a diagram.
- The target renderer cannot execute Mermaid and no pre-rendering path is available.
PDF Output — Pre-render Required
Mermaid code blocks (``mermaid``) do NOT render in the Pandoc → HTML → Puppeteer PDF pipeline. The pipeline generates static HTML with no JavaScript execution.
For any diagram destined for PDF output:
- Create the diagram as a standalone .mmd file
- Pre-render to SVG:
npx @mermaid-js/mermaid-cli -i diagram.mmd -o diagram.svg --width 800 - Choose one embedding method: use raw inline SVG by default, or base64 data URIs when the renderer corrupts raw SVG.
- Strip hardcoded
max-widthpixel values from the SVG tags - Use
flowchart TD(portrait) notflowchart LR(landscape) — seereferences/portrait-layout.md - Add page-break divs before/after each full-page diagram
Do NOT leave ```mermaid code blocks in markdown that will go through Pandoc. They render as raw monospace text.
See references/pdf-rendering-pipeline.md for the full pipeline with Puppeteer setup, SVG styling fixes, and QA checklist.
Supported Diagram Types
| Type | Use Case | File | |------|----------|------| | Flowchart | Process flows, C4 workarounds, decision trees | references/flowchart.md | | Sequence | Interaction protocols and API calls | references/sequence.md | | C4 | Architecture context and container views | references/c4-mermaid.md | | Portrait Layout | PDF/print-oriented diagramming — TD over LR, page breaks, full-page diagrams | references/portrait-layout.md | | PDF Rendering Pipeline | Full pipeline from .mmd → SVG → HTML → PDF, with QA checklist | references/pdf-rendering-pipeline.md | | mmdc Spacing Config | Config for controlling diagram density and preventing label overlap | references/mmdc-spacing-config.md |
C4 Model Guidance
Mermaid has experimental native C4 syntax (C4Context, C4Container, C4Component) but it is unsupported on GitHub and most markdown renderers. GitHub's built-in mermaid renderer does not bundle the C4 plugin — C4-syntax blocks render as raw code rather than diagrams. Use one of these approaches instead:
- Flowchart workarounds (GitHub-compatible) — Convert C4 diagrams to standard
flowchartsyntax using subgraphs for boundaries, styled node boxes for Person/System/Container/Db, and labelled edges for Rel. Seereferences/c4-to-flowchart.mdfor the full conversion pattern. - Structurizr DSL — use for real C4 diagrams. Render via Structurizr CLI or export to Mermaid SVG. Best for formal architecture documentation that doesn't live in GitHub markdown.
- Hybrid approach — maintain a full C4 model in Structurizr DSL and include a flowchart-based approximation in Markdown for inline readability.
C4 → Flowchart Conversion Pattern
| C4 Element | Flowchart Equivalent | Example | |-----------|---------------------|---------| | Person() | [label] (standard rect) | U[Human User] | | System() | [label] with style | GP[GroktoPlan] with style GP fill:#... | | System_Ext() | [label] outside subgraph | GIT[Git Providers] | | Container() | [label with tech stack] | KG[Knowledge GraphPython + pgvector] | | Db() | [(label)] (cylinder shape) | LS[(Live State DB)] | | System_Boundary{} | subgraph System["Title"] ... end | Nested subgraphs | | Container_Boundary{} | subgraph Service["Title"] ... end | Single subgraph | | Rel() | -- label --> or -.-> | AR -- gRPC --> GA | | UpdateLayoutConfig() | Omit — use flowchart LR or TB | Direction set in header |
See references/c4-to-flowchart.md for worked examples of all three C4 levels.
GitHub Compatibility Reference
| Diagram Type | GitHub Renders? | Notes | |-------------|----------------|-------| | flowchart (TD/LR/BT/RL) | ✅ | Use for all C4 workarounds | | sequenceDiagram | ✅ | | | classDiagram | ✅ | | | stateDiagram-v2 | ✅ | | | erDiagram | ✅ | | | gantt | ✅ | | | pie | ✅ | | | quadrantChart | ✅ | | | requirementDiagram | ✅ | | | gitgraph | ✅ | | | mindmap | ✅ | | | timeline | ✅ | | | zenuml | ✅ | | | sankey | ✅ | | | xychart | ✅ | | | block | ✅ | | | packet | ✅ | | | C4Context | ❌ | Requires C4 plugin — renders as raw code | | C4Container | ❌ | Requires C4 plugin — renders as raw code | | C4Component | ❌ | Requires C4 plugin — renders as raw code | | C4Deployment | ❌ | Requires C4 plugin — renders as raw code | | C4Dynamic | ❌ | Requires C4 plugin — renders as raw code |
Rendering
CLI (mmdc) — for PDF/SVG/PNG output
npx @mermaid-js/mermaid-cli -i diagram.mmd -o diagram.svg
npx @mermaid-js/mermaid-cli -i diagram.mmd -o diagram.png
npx @mermaid-js/mermaid-cli -i diagram.mmd -o diagram.pdf
Requires Puppeteer + Chromium (~1.7GB). Use the Docker image for isolated rendering:
docker run --rm -v $(pwd):/data ghcr.io/mermaid-js/mermaid-cli mermaid-cli -i /data/diagram.mmd -o /data/diagram.svg
CDN (HTML) — for inline web rendering
mermaid.initialize({startOnLoad:true});
flowchart LR
A-->B
Validation
// Node.js validation
import { parse } from 'mermaid';
try {
parse('flowchart LR\n A-->B');
console.log('Valid');
} catch (e) {
console.error('Invalid:', e.message);
}
Scripts
| Script | Purpose | |--------|---------| | scripts/validate-mermaid.sh | Validate a .mmd file with Mermaid CLI |
Theming
Mermaid uses a base theme with customizable theme variables. Set them with an init directive at the top of the diagram. Consult the Mermaid documentation for the complete version-specific variable set.
Key theme variables:
primaryColor,primaryTextColor,primaryBorderColorsecondaryColor,tertiaryColorlineColor,fontFamily,fontSizebackground(outer background),mainBkg(element background)
Anti-Patterns
| Anti-pattern | Fix | |-------------|-----| | Lowercase end in flowchart | All Mermaid keywords are case-sensitive. End is not end. | | o or x after dashes without space | -->o needs space: --o or use explicit node shapes | | Quotes inside parentheses | ("quoted text") not ('quoted text') | | Very wide diagrams (>100 nodes) | Split into sub-diagrams or use ELK layout | | Mixed tabs and spaces | Use spaces only. 2-space indent for subgraphs. | | Long labels without line breaks | Use ` or pipe | for line breaks in nodes | | Embedding SVGs as data URIs | Use raw tags instead — data URIs can't have their max-width overridden by CSS | | Leaving Mermaid code blocks in markdown for PDF | Pre-render to SVG first. Pandoc renders ``mermaid as raw text. |
Portability
This skill is intentionally host-neutral. Use your agent's normal mechanisms to load the references, templates, and scripts listed here. Do not assume a particular profile system, task orchestrator, memory service, or response-handoff format.
Source & license
This open-source skill is cataloged on AgentStack and links to its original source — we do not rehost the code.
- Author: magnus919
- Source: magnus919/agent-skills
- License: MIT
Install and usage instructions live in the source repository linked above.
Reviews
No reviews yet — be the first.
Write a review
Versions
- v0.1.0 Imported from the upstream source.