The Complete Production SOP: How to Deploy and Run Architecture Diagram Craft (Mermaid/SVG) in Autonomous AI Agents
Production SOP to install and execute claude-diagram-craft in Codex, Claude Code, Cursor, and Windsurf. Generate compliant Mermaid, C4, and SVG architectures.
Technical Overview & Architectural Context
Autonomous coding agents frequently fail when tasked with generating architecture diagrams, database ERDs, and state machines. Without explicit structural constraints, models tend to introduce unescaped delimiters, invent non-standard Mermaid syntax, mix incompatible C4-PlantUML semantics into standard graph definitions, or produce poorly styled SVGs lacking proper viewBox definitions and accessible contrast ratios. Furthermore, agents often hallucinate dependencies or output inline diagrams that break downstream markdown renderers. The claude-diagram-craft skill enforces strict architectural boundaries across agent runtimes such as Codex, Claude Code, Cursor, and Windsurf. By enforcing a repository-first inspection pattern, strict workspace directory containment, and deterministic local compilation checks via headless rendering utilities (such as `@mermaid-js/mermaid-cli`), the skill guarantees that every generated diagram compiles cleanly without manual developer remediation.
Prerequisites & Environment Requirements
Verified Search Intents & Long-Tail Queries Solved
This operational tutorial is engineered to provide deterministic solutions for these developer search queries:
Step-by-Step Execution Playbook
Local Environment Setup & SKILL.md Mounting
Mount the claude-diagram-craft skill specification into the agent's target skill directory.
Autonomous agents load procedural instructions from dedicated configuration folders. Depending on whether you run Claude Code (`~/.claude/skills`), Cursor (`.cursor/rules`), or universal Codex paths (`~/.agents/skills`), placing the validated SKILL.md in the correct location allows runtime intent detectors to inject architectural diagram standards automatically into context.
mkdir -p ~/.agents/skills/claude-diagram-craft && curl -fsSL https://askills.dev/api/skills/claude-diagram-craft/raw -o ~/.agents/skills/claude-diagram-craft/SKILL.md---
name: "claude-diagram-craft"
description: "Generate clean Mermaid.js sequence diagrams, C4 architecture charts, and crisp SVGs."
triggers:
- "generate mermaid diagram"
- "create c4 architecture"
- "draw sequence diagram"
- "export svg architecture"
---
# Architecture Diagram Craft (Mermaid/SVG)
Visualizes software architecture, database ERDs, cloud topologies, and state machines with accessible color palettes.
## Instructions and Rules
1. Inspect existing diagrams and repository conventions before generating new assets.
2. Adhere strictly to the workspace directory boundaries (output to docs/diagrams/ or as requested).
3. Validate every Mermaid or SVG chart using headless compilation before completing the task.Store canonical diagram templates (e.g., standard C4 container palettes) in `.github/diagram-style.json` to avoid wasting LLM context tokens re-prompting styling details.
Ensure that your agent runtime has read/write permissions for the target output directory (`./docs/architecture/`), otherwise the agent may fall back to inline conversational output instead of committed repository assets.
Tooling Verification & Validator Installation
Install the Mermaid CLI validation toolchain to allow self-healing syntax checks.
To make diagram generation deterministic, the agent needs a sandbox execution utility to test its generated `.mmd` or `.svg` files before committing them. Installing `@mermaid-js/mermaid-cli` provides the `mmdc` executable required for headless dry runs.
pnpm add -D @mermaid-js/mermaid-cli puppeteer{
"devDependencies": {
"@mermaid-js/mermaid-cli": "^10.9.0",
"puppeteer": "^22.0.0"
},
"scripts": {
"lint:diagrams": "mmdc -i docs/diagrams/system-context.mmd -o docs/diagrams/system-context.svg"
}
}In CI/CD or sandboxed agent containers lacking Chromium dependencies, configure Puppeteer to use `--no-sandbox` via a `.puppeteerrc.cjs` file to prevent process crashes during validation.
Do not commit raw binaries or bulky Chromium artifacts; keep Puppeteer caches inside ignored scratch mounts.
Intent Matching & Trigger Invocation
Trigger the agent using structured architectural prompts that match frontmatter rules.
Provide high-clarity requirements that activate the skill's triggers. Emphasize component boundaries, data flow protocols (gRPC, HTTPS, WebSockets), and required format (Mermaid C4Context, Sequence, or SVG) so the agent strictly applies the procedural SOP.
claude 'Generate a C4 container diagram in Mermaid format for our auth service decoupling and save it to docs/diagrams/auth-c4.mmd'C4Container
title Container Diagram for Auth Service Decoupling
Person(user, "Customer", "End user accessing web and mobile clients")
System_Boundary(c1, "Core Platform") {
Container(spa, "Single-Page App", "React, TypeScript", "Delivers platform UI")
Container(api_gateway, "API Gateway", "Kong", "Routes, rate-limits, and terminates TLS")
Container(auth_svc, "Auth Service", "Go, Gin", "Issues JWTs and manages user identity")
ContainerDb(auth_db, "Auth Database", "PostgreSQL", "Stores hashed credentials and audit logs")
}
Rel(user, spa, "Uses", "HTTPS")
Rel(spa, api_gateway, "Sends API calls to", "JSON/HTTPS")
Rel(api_gateway, auth_svc, "Forwards /auth/*", "gRPC/mTLS")
Rel(auth_svc, auth_db, "Reads/Writes credentials", "TCP/SSL")Specifying protocol and transport types directly in the prompt prevents the model from generating ambiguous undirected graph edges.
Avoid mixing classic flowchart syntax (`-->`) inside C4-specific Mermaid syntax (`Rel(...)`), which triggers parser failures.
Verification, Linting & Output Quality Gate
Execute headless rendering to confirm compile-time diagram integrity.
Rule 3 requires verifying changes before concluding. The agent runs `mmdc` against the newly drafted diagram. If the compiler exits with status 0, the diagram is guaranteed free of syntax anomalies, unbalanced brackets, or unescaped strings.
npx mmdc -i docs/diagrams/auth-c4.mmd -o docs/diagrams/auth-c4.svg#!/usr/bin/env bash
set -euo pipefail
for file in docs/diagrams/*.mmd; do
echo "Validating ${file}..."
npx mmdc -i "$file" -o "${file%.mmd}.svg"
done
echo "All diagrams compiled successfully."Use `git diff --stat docs/diagrams/` to inspect SVG output size shifts; sudden byte ballooning often flags unbounded coordinate rendering.
Ensure the target directory exists before running `mmdc`; the CLI fails silently or throws an uncaught ENOENT if the parent path is missing.
Real-World Scenario: Documenting Distributed Payment Reconciliation Flow with Sequence Diagrams
“Using claude-diagram-craft, read services/payment/orchestrator.ts and generate a strictly valid Mermaid.js sequence diagram documenting the settlement flow between the API Gateway, Payment Worker, Stripe Webhook, and Ledger DB. Save to docs/diagrams/payment-flow.mmd and verify that it compiles cleanly to SVG.”
Runtime Troubleshooting & Failure Modes
Root Cause: The agent included unescaped special characters (such as parentheses, quotes, or JSON blobs) inside node labels or used reserved Mermaid keywords without proper encapsulation.
Enclose node strings inside double quotes: change `nodeA[State (Pending)]` to `nodeA["State (Pending)"]` and re-run `npx mmdc -i docs/diagrams/target.mmd -o docs/diagrams/target.svg`.Root Cause: Headless Puppeteer invocation by @mermaid-js/mermaid-cli failed because system-level Chromium shared libraries are missing in the local execution sandbox.
Create a `puppeteer-config.json` file with `{"args": ["--no-sandbox", "--disable-setuid-sandbox"]}` and run `npx mmdc -p puppeteer-config.json -i docs/diagrams/auth-c4.mmd -o docs/diagrams/auth-c4.svg` or install dependencies via `npx puppeteer browsers install chrome`.Frequently Asked Questions (Architecture Diagram Craft (Mermaid/SVG) SOP)
Q:Can I use Architecture Diagram Craft (Mermaid/SVG) across Codex, Claude Code, and Cursor simultaneously?
Yes. The skill conforms to the universal SKILL.md specification. You can symlink or copy `SKILL.md` into `~/.claude/skills/`, `.cursor/rules/`, or your repository's `.agents/` folder for seamless cross-agent operation.
Q:How does Architecture Diagram Craft (Mermaid/SVG) prevent context window overflow during long agent sessions?
By offloading styling heuristics to static repository configs and enforcing concise procedural rules (inspect -> create -> local compile check), the skill eliminates long conversational self-correction loops.
Q:Does this skill require escalated root or container permissions?
No. The skill operates strictly inside standard non-root workspace permissions (Security Score: 98/100). It only requires workspace file system write access and execution rights for local Node-based linters.
Ready to equip your autonomous agent with Architecture Diagram Craft (Mermaid/SVG)?
Copy the complete audited SKILL.md specification or download the 1-click zip bundle directly from our verified registry.