$npx -y skills add comol/ai_rules_1c --skill mermaid-diagramsPractical guide for creating human-readable and agent-parseable diagrams using Mermaid. Includes conservative, renderer-compatible templates and when-to-use guidance.
| 1 | # Mermaid Diagrams Skill |
| 2 | |
| 3 | ## Compatibility Rules (Read First) |
| 4 | - Prefer `graph LR`/`graph TB` for flowcharts; some renderers fail on `flowchart` keyword. |
| 5 | - Quote labels containing spaces/special characters: `A["Text (x|y) |"]`. |
| 6 | - **Do not use literal `\n` inside labels** — Mermaid does not interpret such line breaks. Use `<br/>` for line breaks. |
| 7 | - Advanced types like `quadrantChart`, `sankey-beta`, `requirementDiagram`, `gitGraph` may not be available. Use provided flowchart fallbacks. |
| 8 | - Code fences must start at column 0 with language `mermaid`. |
| 9 | |
| 10 | ## ASCII/Unicode Sidecar (Human-Readable Raw Markdown) |
| 11 | To optimize for quick human scanning in raw Markdown and robust parsing by agents, always ship an ASCII/Unicode sidecar immediately below each Mermaid block. |
| 12 | |
| 13 | Policy: |
| 14 | - MUST include a monospace, text-only diagram right under the Mermaid block using fenced code with language `text`. |
| 15 | - MUST keep Mermaid and sidecar in sync (same nodes/edges, same labels where feasible). If they diverge, treat Mermaid as the source of truth and update the sidecar. |
| 16 | - SHOULD limit width to ~80 columns for readability in diffs and terminals. |
| 17 | - SHOULD use simple line art characters (ASCII first; Unicode box-drawing optional when environment supports it). |
| 18 | - MAY add a one-line caption above the pair: `Diagram: <name> (<type>)`. |
| 19 | |
| 20 | Recommended primitives: |
| 21 | - Boxes: `[Name]`, `(Name)`, `+-----+\n| N |\n+-----+` |
| 22 | - Flows: `-->`, decisions as `{cond?}` lines, lists with `-`. |
| 23 | - Sequence (text-based): `Actor -> Actor: message` with indented lifelines. |
| 24 | |
| 25 | Example (Flowchart): |
| 26 | ```mermaid |
| 27 | graph LR |
| 28 | A["Start"] --> B{Auth?} |
| 29 | B -->|Yes| C["Dashboard"] |
| 30 | B -->|No| D["Login"] |
| 31 | ``` |
| 32 | ```text |
| 33 | Diagram: Auth flow (flowchart) |
| 34 | [Start] --> {Auth?} |
| 35 | {Auth?} -- Yes --> [Dashboard] |
| 36 | {Auth?} -- No --> [Login] |
| 37 | ``` |
| 38 | |
| 39 | Example (Text-based Sequence): |
| 40 | ```mermaid |
| 41 | sequenceDiagram |
| 42 | participant U as User |
| 43 | participant W as WebApp |
| 44 | U->>W: Open |
| 45 | W-->>U: OK |
| 46 | ``` |
| 47 | ```text |
| 48 | Diagram: Happy path (sequence) |
| 49 | User -> WebApp : Open |
| 50 | WebApp -> User : OK |
| 51 | ``` |
| 52 | |
| 53 | ## Working Templates (Renderer-Compatible) |
| 54 | |
| 55 | ### Flowchart |
| 56 | ```mermaid |
| 57 | graph LR |
| 58 | A["Start"] --> B{Auth?} |
| 59 | B -->|Yes| C["Dashboard"] |
| 60 | B -->|No| D["Login"] |
| 61 | C --> E["Settings"] |
| 62 | ``` |
| 63 | |
| 64 | ### Sequence |
| 65 | ```mermaid |
| 66 | sequenceDiagram |
| 67 | autonumber |
| 68 | participant U as User |
| 69 | participant W as WebApp |
| 70 | participant API |
| 71 | U->>W: Open |
| 72 | W->>API: GET /status |
| 73 | API-->>W: 200 |
| 74 | W-->>U: OK |
| 75 | ``` |
| 76 | |
| 77 | ### Class |
| 78 | ```mermaid |
| 79 | classDiagram |
| 80 | class User { |
| 81 | +String id |
| 82 | +String name |
| 83 | +login(): bool |
| 84 | } |
| 85 | class Order { |
| 86 | +String id |
| 87 | +Decimal total |
| 88 | +submit() |
| 89 | } |
| 90 | User "1" o-- "*" Order |
| 91 | ``` |
| 92 | |
| 93 | ### State (v2) |
| 94 | ```mermaid |
| 95 | stateDiagram-v2 |
| 96 | [*] --> Idle |
| 97 | Idle --> Loading : fetch |
| 98 | Loading --> Ready : ok |
| 99 | Loading --> Error : fail |
| 100 | state Ready { |
| 101 | [*] --> Viewing |
| 102 | Viewing --> Editing : edit |
| 103 | Editing --> Viewing : save |
| 104 | } |
| 105 | Error --> Idle : retry |
| 106 | ``` |
| 107 | |
| 108 | ### ER (Entity-Relationship) |
| 109 | ```mermaid |
| 110 | erDiagram |
| 111 | USER ||--o{ ORDER : places |
| 112 | ORDER ||--|{ ORDER_LINE : contains |
| 113 | PRODUCT ||--o{ ORDER_LINE : referenced |
| 114 | USER { |
| 115 | string id |
| 116 | string email |
| 117 | } |
| 118 | PRODUCT { |
| 119 | string id |
| 120 | string name |
| 121 | float price |
| 122 | } |
| 123 | ``` |
| 124 | |
| 125 | ### Journey (User Journey) |
| 126 | ```mermaid |
| 127 | journey |
| 128 | title Checkout UX |
| 129 | section Browse |
| 130 | "See product": 5: User |
| 131 | "Add to cart": 4: User |
| 132 | section Payment |
| 133 | "Enter card": 2: User |
| 134 | "3DS confirm": 2: User |
| 135 | section Result |
| 136 | "Success page": 5: User |
| 137 | ``` |
| 138 | |
| 139 | ### Gantt |
| 140 | ```mermaid |
| 141 | gantt |
| 142 | title Release Plan |
| 143 | dateFormat YYYY-MM-DD |
| 144 | section Dev |
| 145 | Spec :done, des1, 2025-10-01,2025-10-05 |
| 146 | Impl :active, des2, 2025-10-06,2025-10-20 |
| 147 | Tests : des3, 2025-10-21, 7d |
| 148 | section Release |
| 149 | Freeze :milestone, m1, 2025-10-28, 0d |
| 150 | Deploy :crit, des4, 2025-10-29, 1d |
| 151 | ``` |
| 152 | |
| 153 | ### Pie (compatible syntax) |
| 154 | ```mermaid |
| 155 | pie |
| 156 | title Traffic by Source |
| 157 | "Direct" : 35 |
| 158 | "Organic" : 45 |
| 159 | "Ads" : 20 |
| 160 | ``` |
| 161 | |
| 162 | ### Quadrant — flowchart fallback |
| 163 | ```mermaid |
| 164 | graph TB |
| 165 | Q1["Quick Wins<br/>High Impact - Low Effort<br/><br/>- Improve UX"] |
| 166 | Q2["Major Projects<br/>High Impact - High Effort<br/><br/>- Rewrite Core"] |
| 167 | Q3["Fill-ins<br/>Low Impact - Low Effort<br/><br/>- Docs polish"] |
| 168 | Q4["Thankless<br/>Low Impact - High Effort<br/><br/>- Legacy migration"] |
| 169 | |
| 170 | Q1 --> Q2 |
| 171 | Q1 --> Q3 |
| 172 | Q2 --> Q4 |
| 173 | Q3 --> Q4 |
| 174 | ``` |
| 175 | |
| 176 | ### Requirement — flowchart fallback |
| 177 | ```mermaid |
| 178 | graph LR |
| 179 | R1["Requirement: PCI-DSS compliant"] |
| 180 | T1["Test: PCI checklist"] |
| 181 | SVC["Service"] |
| 182 | |
| 183 | SVC -- satisfies --> R1 |
| 184 | T1 -- verifies --> R1 |
| 185 | ``` |
| 186 | |
| 187 | ### Sankey — flowchart fallback (weights on edges) |
| 188 | ```mermaid |
| 189 | graph LR |
| 190 | Checkout["Checkout"] -->|100| PSP["PSP"] |
| 191 | PSP -->|60| Settled["Settled"] |
| 192 | PSP -->|40| Declined["Declined"] |
| 193 | ``` |
| 194 | |
| 195 | ### Git graph — flowchart fallback (simple DAG) |
| 196 | ```mermaid |
| 197 | graph LR |
| 198 | A["init"] --> B["feat-A"] |
| 199 | A --> C["fix-1"] |
| 200 | B --> D["merge"] |
| 201 | C --> D |
| 202 | ``` |
| 203 | |
| 204 | ## When to |