Skip to content
Back to search

svg-diagram

SkillWorks with Claude CodeGitHub

SVG diagramming conventions blending a technical look with CJK-friendly typography. Use when creating flowcharts, architecture diagrams, and similar SVG figures. For one-shot generation, prefer invoking it from a subagent so the main context does not have to carry this skill plus the SVG XML; for multi-round tweaking, use it directly in the main context.

Safety scan

A static text scan, not a guarantee. Select the badge to see what was scanned and every finding.

Checked today
Badge for your README
findsafeskills safety rating

Markdown

[![findsafeskills safety rating](/api/listings/bybit-exchange--svg-diagram/badge.svg)](/listings/bybit-exchange--svg-diagram)

HTML

<a href="/listings/bybit-exchange--svg-diagram"><img src="/api/listings/bybit-exchange--svg-diagram/badge.svg" alt="findsafeskills safety rating" /></a>

Install

i

Install instructions from the README

As written by the repo's author. findsafeskills has not verified these steps.

Paste this to your coding agent:

Install the svg-diagram skill from https://github.com/bybit-exchange/svg-diagram
for me by running: npx skills add bybit-exchange/svg-diagram -g

Or run it yourself:

npx skills add bybit-exchange/svg-diagram -g

The CLI detects which agents you have installed and writes each one's path. Drop `-g` to install into the current project instead.

| Surface | Path | |---|---| | Claude Code | `~/.claude/skills/svg-diagram/` | | Codex, Cursor, Gemini CLI, Copilot, opencode, Antigravity | `~/.agents/skills/svg-diagram/` — they share one directory | | Pi | `~/.pi/skills/svg-diagram/` | | Windsurf, Continue, Roo, Goose, Kiro, Trae and 40+ more | `~/.<agent>/skills/svg-diagram/` | | Claude.ai | Zip the folder and upload it under Settings → Capabilities → Skills (skill text only — `svg-lint` needs local Node) |

Every path is named from the skill's frontmatter `name`, not from where the skill sits here, so moving files in this repository doesn't change them.

`SKILL.md` is at the repository root, so the install copies the root and `svg-lint` comes along with the skill text. The linter has no dependencies, so it runs from wherever it landed:

node ~/.claude/skills/svg-diagram/tools/svg-lint/bin/svg-lint.mjs diagram.svg

If you only want the skill text, take the one file the agent reads:

mkdir -p ~/.claude/skills/svg-diagram
curl -fsSL https://raw.githubusercontent.com/bybit-exchange/svg-diagram/main/SKILL.md \
  -o ~/.claude/skills/svg-diagram/SKILL.md

The skill works on its own that way; `svg-lint` is what you give up.

Then start a new session and ask for a diagram — the agent should announce that it's using `svg-diagram`.

What was scanned

The files the safety scan read, as written by the repository's author and shown as plain text. Lines with a finding are marked.

SKILL.md · Manifest · 586 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. ---
  2. name: svg-diagram
  3. description: SVG diagramming conventions blending a technical look with CJK-friendly typography. Use when creating flowcharts, architecture diagrams, and similar SVG figures. For one-shot generation, prefer invoking it from a subagent so the main context does not have to carry this skill plus the SVG XML; for multi-round tweaking, use it directly in the main context.
  4. ---
  5. # SVG Diagramming Conventions
  6. ## Output location and referencing
  7. > Diagrams go in SVG, never ASCII art. That rule decides *whether* to draw; this skill covers *how*, starting with where the file lands.
  8. - Put the file in an `assets/` directory next to the document (e.g. `docs/foo.md` → `docs/assets/foo-arch.svg`)
  9. - Reference it from markdown with a relative path, `![title](assets/xxx.svg)`. Do not inline SVG XML.
  10. - When data in the document changes, the corresponding SVG must be updated too. A figure that contradicts the prose beside it is worse than no figure
  11. ## Core principles
  12. ### Get it right on the first pass
  13. The first SVG you generate must already satisfy every item in the verification checklist at the end of this document. Do not rely on user feedback to fix basic layout problems (spacing, padding, alignment, viewBox clipping). After generating, walk the checklist yourself and fix anything you find before showing the result.
  14. ### No overlapping elements
  15. - Text must not sit on top of boxes or lines
  16. - Lines must not cut through boxes (unless the line is an arrow terminating at that box)
  17. - Keep 10–20px between text and lines
  18. - **For spacing between sibling/adjacent boxes see the "Block spacing" section below** (single standard: ≥25px, 25–30px recommended)
  19. - Put color-key legends outside the diagram body (bottom or side), never overlapping the content area
  20. ```xml
  21. <!-- ✅ Correct: label sits beside the line -->
  22. <path d="M35,200 C 35,120 ..." .../>
  23. <text x="55" y="200">Label text</text> <!-- 20px clearance -->
  24. <!-- ❌ Wrong: label sits on the line -->
  25. <text x="35" y="200">Label text</text>
  26. ```
  27. ### Visual balance
  28. The left and right halves should carry similar visual weight; add or remove annotation boxes to even them out.
  29. ## Layout rules
  30. ### Centering
  31. ```
  32. content width = right edge of rightmost element - left edge of leftmost element
  33. left margin = (viewBox width - content width) / 2
  34. ```
  35. **Center the title on the *content* center, not the viewBox center** (they differ whenever the content is asymmetric):
  36. ```xml
  37. <!-- content center = (content left edge + content right edge) / 2 -->
  38. <text x="[content center x]" y="[top_padding + font_ascent]" text-anchor="middle">Title</text>
  39. ```
  40. Only when the content is left-right symmetric does `content center x = viewBox width / 2`. When it is asymmetric, center the whole group with `<g transform="translate(...)">` and update the title's `x` to the new content center as well.
  41. ### Shifting everything after the fact
  42. If you only notice asymmetric left/right (or top/bottom) padding after the SVG is finished, you do not need to touch every coordinate. Wrap the content in one `<g transform="translate(dx, dy)">`:
  43. ```xml
  44. <svg viewBox="0 0 800 460" ...>
  45. <defs>...</defs>
  46. <g transform="translate(22, 0)">
  47. <!-- all content here, coordinates unchanged -->
  48. </g>
  49. </svg>
  50. ```
  51. **Computing the offset**: `dx = (right padding - left padding) / 2`, where padding is the distance from the viewBox edge to the nearest content element.
  52. - `dx > 0`: shift content right (use when content sits too far left)
  53. - `dx < 0`: shift content left (use when content sits too far right)
  54. When to use it: the content as a whole is off-center and you do not want to edit every `x` coordinate. Downside: the coordinates in the file no longer equal rendered positions, so later edits require mentally subtracting the offset — if a larger layout rework is coming, fold the offset into the individual coordinates and drop the `<g>`.
  55. ### viewBox margins
  56. The title is part of the content, so top and bottom margins are measured from the title:
  57. ```
  58. title y = margin + font ascent (≈ font-size × 0.75)
  59. viewBox height = bottom y of content + margin
  60. ```
  61. **Recommended margin**: 20–25px
  62. ```xml
  63. <!-- Example: 16px title, 20px margin -->
  64. <!-- title y = 20 + 16×0.75 ≈ 32 -->
  65. <!-- content bottom 270px, viewBox height = 270 + 25 = 295 -->
  66. <svg viewBox="0 0 680 295" ...>
  67. <text x="340" y="32" font-size="16">Title</text>
  68. ...
  69. </svg>
  70. ```
  71. ### Box layout
  72. - Boxes in the same row differ in size by ≤60px; text is centered (`text-anchor="middle"`)
  73. - Boxes in the same column share a center line
  74. - An outer box fully encloses the inner boxes: `outer size = content size + padding × 2`
  75. ### Dashed grouping boxes (containers)
  76. Used to group related boxes together (e.g. "Server", "Client", "Employee instances").
  77. **Style consistency**: within one diagram, every dashed grouping box must share these attributes:
  78. - `stroke-dasharray` (recommended `6,4`)
  79. - `rx` (corner radius, recommended 8–12)
  80. - `fill` (recommended `#f8fafc` or `none`)
  81. - Inner padding (recommended 15–20px)
  82. - Title font size (recommended 11px, to distinguish it from the 12px box body text)
  83. **Title placement**: put the group title inside the top-left corner of the box (`x = box x + 10, y = box y + 14`) using the secondary text color `#64748b`.
  84. **Vertical-centering trap**: compute the group box's vertical position from the combined height of **title + inner content**, not from the box alone. With a title, the top of the box is occupied for roughly 20–25px, and inner boxes start below it:
  85. ```xml
  86. <!-- ✅ Group box: title + content laid out as a whole -->
  87. <!-- box top y=100, title takes 20px, inner boxes start at y=125 -->
  88. <rect x="50" y="100" width="200" height="120" rx="10"
  89. stroke="#94a3b8" stroke-dasharray="6,4" fill="#f8fafc"/>
  90. <text x="60" y="114" font-size="11" fill="#64748b">Server</text>
  91. <!-- inner boxes -->
  92. <rect x="65" y="125" width="170" height="36" rx="6" .../>
  93. <rect x="65" y="170" width="170" height="36" rx="6" .../>
  94. ```
  95. **Connectors pointing at a group**: when a connector logically targets a set of elements rather than one of them, terminate it on the group box boundary instead of on a single member. Alternatively, wrap the elements in a grouping box and point the arrow at that box.
  96. ### Box dimensions
  97. Derive box height from the font size so there is enough inner padding:
  98. | Content | Height formula | Example (12px font) |
  99. |---------|----------------|---------------------|
  100. | One line | font-size × 3 | 36px |
  101. | Two lines | font-size × 3 + line height | 36 + 18 = 54px |
  102. | Multiple lines | font-size × 3 + (lines - 1) × line height | +18px per extra line |
  103. **Where the formula comes from**: `font-size × 3 = top padding (≈font-size) + glyph height (≈font-size) + bottom padding (≈font-size)`. Scale the same ratio for non-standard font sizes.
  104. **Recommended line height**: font-size × 1.5 (e.g. 18px for a 12px font)
  105. ### Vertically centering text in a box (baseline positioning)
  106. In SVG, `<text y=...>` is the **baseline**, not the top of the glyph. To center text optically inside a box:
  107. ```
  108. text y = box center y + font-size × 0.35
  109. = box y + box height/2 + font-size × 0.35
  110. ```
  111. The 0.35 factor is an empirical value for "optical glyph center to baseline" (roughly one third of the font size).
  112. **Keep the two factors apart**:
  113. - `font-size × 0.75` (ascent): for elements **positioned from the top**, such as titles (y = top_padding + ascent)
  114. - `font-size × 0.35` (baseline offset): for **vertical centering inside a box**
  115. ```xml
  116. <!-- One line: height = 12 × 3 = 36px -->
  117. <rect x="30" y="50" width="110" height="36" rx="6" .../>
  118. <!-- y = 50 + 36/2 + 12×0.35 = 50 + 18 + 4.2 ≈ 72 -->
  119. <text x="85" y="72" ...>Single line</text>
  120. <!-- Two lines: height = 36 + 18 = 54px -->
  121. <rect x="30" y="50" width="110" height="54" rx="6" .../>
  122. <text x="85" y="70" ...>First line</text>
  123. <text x="85" y="88" ...>Second line</text> <!-- 18px apart -->
  124. ```
  125. ### Display size
  126. ```xml
  127. <svg viewBox="0 0 750 400" width="750" xmlns="http://www.w3.org/2000/svg">
  128. ```
  129. | Diagram type | width |
  130. |--------------|-------|
  131. | Simple list | 400px |
  132. | Flowchart | 600–700px |
  133. | Architecture diagram | 700–800px |
  134. ## Connector rules
  135. ### Choosing a connector
  136. Use a straight `L` line for co-axial connections; use smooth `C`/`Q` curves whenever the path **turns or routes around** something. Never use right-angle elbows.
  137. ```xml
  138. <!-- ✅ Horizontally co-axial: straight line -->
  139. <path d="M190,77 L 320,77" .../>
  140. <!-- ✅ Vertically co-axial: straight line -->
  141. <path d="M130,145 L 130,213" .../>
  142. <!-- ❌ Right-angle elbow for a turn -->
  143. <path d="M100,100 L100,200 L200,200" .../>
  144. <!-- ✅ Smooth curve for a turn -->
  145. <path d="M100,100 C 100,150 150,200 200,200" .../>
  146. ```
  147. | Case | Recommended | Syntax |
  148. |------|-------------|--------|
  149. | Co-axial (horizontal/vertical) | L | `L endx,endy` |
  150. | Simple turn | Q | `Q ctrlx,ctrly endx,endy` |
  151. | S-curve / complex path | C | `C ctrl1x,ctrl1y ctrl2x,ctrl2y endx,endy` |
  152. ### Arrow rules
  153. - **Direction comes from the final path segment**: rightward means x increases, downward means y increases
  154. - **Symmetric clearance**: 5px between the arrow and the source box, and the same visual clearance at the target box
  155. - **Centered labels**: `x = (source right edge + target left edge) / 2`, together with `text-anchor="middle"`
  156. **Fixing arrow direction on curved paths**: `orient="auto"` aligns the arrowhead with the tangent at the end of the path. The end tangent of a C/Q curve can be skewed, which makes the arrowhead look crooked. The fix: place the second control point (cp2) so that the direction cp2 → end point is exactly the direction you want the arrowhead to face.
  157. ```xml
  158. <!-- ❌ cp2 placed arbitrarily, arrow direction uncontrolled -->
  159. <path d="M100,100 C 100,200 250,200 300,250" marker-end="url(#arrow)"/>
  160. <!-- ✅ cp2 shares x with the end point, tangent naturally points down -->
  161. <path d="M100,100 C 100,200 300,220 300,250" marker-end="url(#arrow)"/>
  162. <!-- ✅ cp2 shares y with the end point, tangent naturally points right -->
  163. <path d="M100,100 C 100,200 270,250 300,250" marker-end="url(#arrow)"/>
  164. ```
  165. **Rules for controlling arrow direction**:
  166. | Desired direction | cp2 constraint | Example |
  167. |-------------------|----------------|---------|
  168. | ↓ down | cp2.x = end.x, cp2.y < end.y | `C ...,... ex,ey-20 ex,ey` |
  169. | → right | cp2.y = end.y, cp2.x < end.x | `C ...,... ex-20,ey ex,ey` |
  170. | ← left | cp2.y = end.y, cp2.x > end.x | `C ...,... ex+20,ey ex,ey` |
  171. | ↑ up | cp2.x = end.x, cp2.y > end.y | `C ...,... ex,ey+20 ex,ey` |
  172. **Computing path endpoints** (5px clearance, arrowhead extends 6px past the end of the line):
  173. Core rule: **start 5px away from the source box, end 11px away from the target box** (5px clearance + 6px arrowhead extension).
  174. Because we use `refX="2"` (the notch at the tail of the arrowhead), the tip extends 6px (8-2=6) beyond the end of the line, and the line joins the arrowhead at the center of its notch, so the join reads as continuous.
  175. **Formulas for the four directions**:
  176. | Direction | Start | End |
  177. |-----------|-------|-----|
  178. | → right | source right edge + 5 | target left edge - 11 |
  179. | ← left | source left edge - 5 | target right edge + 11 |
  180. | ↓ down | source bottom edge + 5 | target top edge - 11 |
  181. | ↑ up | source top edge - 5 | target bottom edge + 11 |
  182. ```xml
  183. <!-- Rightward arrow →: source right edge 180, target left edge 220 -->
  184. <!-- start: 180+5=185, end: 220-11=209, tip reaches 209+6=215 -->
  185. <path d="M185,70 L 209,70" marker-end="url(#arrow)"/>
  186. <!-- Leftward arrow ←: source left edge 220, target right edge 180 -->
  187. <!-- start: 220-5=215, end: 180+11=191, tip reaches 191-6=185 -->
  188. <path d="M215,70 L 191,70" marker-end="url(#arrow)"/>
  189. <!-- Downward arrow ↓: source bottom 140, target top 170 -->
  190. <!-- start: 140+5=145, end: 170-11=159, tip reaches 159+6=165 -->
  191. <path d="M130,145 L 130,159" marker-end="url(#arrow)"/>
  192. <!-- Upward arrow ↑: source top 170, target bottom 140 -->
  193. <!-- start: 170-5=165, end: 140+11=151, tip reaches 151-6=145 -->
  194. <path d="M130,165 L 130,151" marker-end="url(#arrow)"/>
  195. ```
  196. **Bidirectional example** (two boxes with arrows going both up and down):
  197. ```xml
  198. <!-- box A bottom=375, box B top=420 -->
  199. <!-- downward arrow: A→B -->
  200. <path d="M320,380 L 320,409" marker-end="url(#arrow)"/> <!-- 375+5, 420-11 -->
  201. <!-- upward arrow: B→A -->
  202. <path d="M480,415 L 480,386" marker-end="url(#arrow)"/> <!-- 420-5, 375+11 -->
  203. ```
  204. ### Routing around obstacles
  205. Keep detour paths at least 20px outside the obstacle's boundary:
  206. ```xml
  207. <!-- Gateway right edge=620, detour path runs at x=650 -->
  208. <path d="M600,313 Q 650,313 650,400 Q 650,640 635,685"
  209. fill="none" stroke="#a855f7" stroke-dasharray="6,4" marker-end="url(#arrow)"/>
  210. ```
  211. ### Block spacing (**single global standard**)
  212. Spacing between adjacent boxes/blocks is **≥25px, 25–30px recommended**.
  213. Breakdown: 5px start clearance + 11px end clearance and arrowhead extension + ≥6px of visible line + safety margin ≈ 25px. **At least 6px of visible line**, otherwise the arrow degenerates into a dot.
  214. **Stay compact**: do not exceed 30px. Spacing that is too wide (>40px) makes the whole diagram feel loose and the connectors overly long. Aim for 5px / 11px at the two ends and 6–12px of visible line in between.
  215. **Overall density**: when you are done, step back and judge the density — if the content area is clearly small relative to the viewBox (large blank regions), tighten spacing or shrink the viewBox. Common causes: box spacing >30px, viewBox margin >25px, excessive padding inside grouping boxes.
  216. > This is the only block-spacing standard in this document; both "No overlapping elements" and the verification checklist refer back to it.
  217. ### SVG paint order (z-order)
  218. SVG has no z-index — **elements painted later sit on top**. Order them like this:
  219. ```xml
  220. <!-- 1. Bottom layer: background boxes (dashed grouping boxes, swimlanes) -->
  221. <rect ... stroke-dasharray="6,4" fill="#f8fafc"/>
  222. <!-- 2. Middle layer: connectors and arrows -->
  223. <path d="..." marker-end="url(#arrow)"/>
  224. <!-- 3. Top layer: boxes and text -->
  225. <rect ... fill="#dbeafe"/>
  226. <text ...>Label</text>
  227. ```
  228. **Common mistake**: painting connectors first and the dashed background box afterwards → the connectors get covered.
  229. **Exception: cross-layer loop-back lines**: connectors that must **span several boxes** — iteration loops, cross-region dashed lines — have to be painted after the boxes (layer 4), otherwise the boxes hide them:
  230. ```xml
  231. <!-- 1. background boxes -->
  232. <!-- 2. ordinary connectors -->
  233. <!-- 3. boxes and text -->
  234. <!-- 4. cross-layer loop-back lines (topmost, painted over the boxes) -->
  235. <path d="..." stroke-dasharray="6,4" marker-end="url(#arrow-purple)"/>
  236. ```
  237. ## Estimating text width (overflow protection)
  238. Before placing text, estimate its right edge and confirm it does not intrude on neighboring elements:
  239. | Font size | Latin char width (approx.) | CJK char width (approx.) |
  240. |-----------|---------------------------|--------------------------|
  241. | 8px | 4.5px | 8px |
  242. | 9px | 5.0px | 9px |
  243. | 10px | 5.5px | 10px |
  244. | 11px | 6.0px | 11px |
  245. | 12px | 7.0px | 12px |
  246. **Estimation formulas**:
  247. - `text-anchor="start"`: right edge ≈ x + char count × char width
  248. - `text-anchor="middle"`: left/right edge ≈ x ± (char count × char width) / 2
  249. - `text-anchor="end"`: left edge ≈ x - char count × char width
  250. Check before placing: text right edge + 10px < left edge of the neighbor to its right.
  251. ```xml
  252. <!-- ❌ Text "4K tokens (= mini-batch)" starts at x=274 -->
  253. <!-- 24 chars × 5px ≈ 120px, right edge ≈ 394, intrudes on the box at x=350 -->
  254. <text x="274" y="115" font-size="9">4K tokens (= mini-batch)</text>
  255. <!-- ✅ Moved below the box and centered, intrudes on nothing -->
  256. <text x="154" y="138" font-size="9" text-anchor="middle">4K tokens (= mini-batch)</text>
  257. ```
  258. ## Placing labels on curves
  259. A label describing an arc or curve must not sit on the path itself (the line would run through the text) — put it on the convex or concave side of the curve:
  260. ```xml
  261. <!-- ❌ Label at y=218 while the curve passes near y=225: the line cuts the text -->
  262. <text x="350" y="218">Skip Connection</text>
  263. <path d="M82,165 C 82,225 620,225 646,225" .../>
  264. <!-- ✅ Label at y=222, lowest point of the curve at y=260, 38px apart -->
  265. <text x="350" y="222">Skip Connection</text>
  266. <path d="M82,149 C 82,260 600,255 640,255" .../>
  267. ```
  268. **Rule**: keep ≥15px between the label and the nearest point on the curve. For a downward-bending curve put the label above it; for an upward-bending curve put it below.
  269. ## Coordinate management
  270. ### Record boundaries in comments
  271. ```xml
  272. <!-- Gateway: x=280, y=55, width=340, height=435, right edge=620, bottom edge=490 -->
  273. <rect x="280" y="55" width="340" height="435" .../>
  274. ```
  275. ### When you move an element, update in lockstep
  276. 1. viewBox dimensions
  277. 2. Every arrow to/from that element (start point, end point, control points)
  278. 3. Positions of related labels
  279. 4. **The dashed background/grouping box that wraps the element** (swimlane, container) — the most commonly missed one
  280. 5. Other boxes aligned with it in the same row/column
  281. 6. Any other affected elements
  282. ## Style rules
  283. ### Fonts (required)
  284. **Every SVG must declare a CJK-capable font stack in `<style>`** — this is non-negotiable:
  285. ```xml
  286. <style>
  287. text { font-family: 'PingFang SC', 'Microsoft YaHei', 'Noto Sans CJK SC', system-ui, sans-serif; }
  288. </style>
  289. ```
  290. Fallback order: macOS (PingFang SC) → Windows (Microsoft YaHei) → Linux (Noto Sans CJK SC) → system default. **`Noto Sans CJK SC` must be kept**, otherwise server-side rendering on Linux falls back to a font with no CJK coverage.
  291. | Element | Size |
  292. |---------|------|
  293. | Title | 16px |
  294. | Box body text | 12px |
  295. | Secondary text / annotations | 10px |
  296. Vertical text: `<text writing-mode="tb">vertical text</text>`
  297. ### Colors
  298. **Base colors**: primary text `#1e293b`, secondary text `#64748b`, muted text / arrows `#94a3b8`
  299. **Semantic colors**:
  300. | Meaning | Fill | Stroke | Text |
  301. |---------|------|--------|------|
  302. | Input / primary | #dbeafe | #3b82f6 | #1e40af |
  303. | Processing / in progress | #fef3c7 | #f59e0b | #b45309 |
  304. | Data / output | #d1fae5 | #22c55e | #166534 |
  305. | AI / analysis | #f3e8ff | #a855f7 | #6b21a8 |
  306. | Sensitive / warning | #fce7f3 | #ec4899 | #9d174d |
  307. ## Arrowhead definitions
  308. Use a notched arrowhead rather than a plain triangle — it reads better:
  309. ```xml
  310. <defs>
  311. <!-- Default gray arrow (markerUnits="userSpaceOnUse" is mandatory) -->
  312. <marker id="arrow" markerWidth="8" markerHeight="8" refX="2" refY="4" orient="auto" markerUnits="userSpaceOnUse">
  313. <path d="M0,0 L8,4 L0,8 L2,4 z" fill="#64748b"/>
  314. </marker>
  315. <!-- Semantic-color arrows (matching the box stroke colors) -->
  316. <marker id="arrow-blue" markerWidth="8" markerHeight="8" refX="2" refY="4" orient="auto" markerUnits="userSpaceOnUse">
  317. <path d="M0,0 L8,4 L0,8 L2,4 z" fill="#3b82f6"/>
  318. </marker>
  319. <marker id="arrow-orange" markerWidth="8" markerHeight="8" refX="2" refY="4" orient="auto" markerUnits="userSpaceOnUse">
  320. <path d="M0,0 L8,4 L0,8 L2,4 z" fill="#f59e0b"/>
  321. </marker>
  322. <marker id="arrow-green" markerWidth="8" markerHeight="8" refX="2" refY="4" orient="auto" markerUnits="userSpaceOnUse">
  323. <path d="M0,0 L8,4 L0,8 L2,4 z" fill="#22c55e"/>
  324. </marker>
  325. <marker id="arrow-purple" markerWidth="8" markerHeight="8" refX="2" refY="4" orient="auto" markerUnits="userSpaceOnUse">
  326. <path d="M0,0 L8,4 L0,8 L2,4 z" fill="#a855f7"/>
  327. </marker>
  328. <marker id="arrow-red" markerWidth="8" markerHeight="8" refX="2" refY="4" orient="auto" markerUnits="userSpaceOnUse">
  329. <path d="M0,0 L8,4 L0,8 L2,4 z" fill="#ef4444"/>
  330. </marker>
  331. </defs>
  332. ```
  333. **Arrow color reference**:
  334. | ID | Color | Use |
  335. |----|-------|-----|
  336. | `arrow` | #64748b | Default / neutral connection |
  337. | `arrow-blue` | #3b82f6 | Input / primary flow |
  338. | `arrow-orange` | #f59e0b | Processing / in progress |
  339. | `arrow-green` | #22c55e | Data / output / success |
  340. | `arrow-purple` | #a855f7 | AI / analysis / special |
  341. | `arrow-red` | #ef4444 | Warning / dangerous operation |
  342. **Key parameters**:
  343. - `orient="auto"` rotates the arrowhead to follow the path direction
  344. - `markerUnits="userSpaceOnUse"` **must be declared explicitly**, otherwise the default `strokeWidth` scales the arrowhead with line thickness (at stroke-width=2 the arrow doubles in size and blows past the intended clearance)
  345. - `refX="2"` aligns the end of the line with the center of the arrowhead's tail notch, so the join looks natural
  346. - `refY="4"` centers it vertically (arrow height 8, midpoint 4)
  347. - The arrow path `M0,0 L8,4 L0,8 L2,4 z` forms the notched shape, with the tip at x=8
  348. - The tip extends 6px (8-2=6) beyond the end of the line, so the end point is computed as `target edge - 11`
  349. **Arrows on thick lines**: when stroke-width > 1.5 (e.g. heavy dashed lines), an 8×8 arrowhead looks too small. Define a proportionally larger marker:
  350. ```xml
  351. <!-- Large arrow for thick lines (1.5×): tip extends 12-3=9px -->
  352. <marker id="arrow-red-lg" markerWidth="12" markerHeight="12" refX="3" refY="6"
  353. orient="auto" markerUnits="userSpaceOnUse">
  354. <path d="M0,0 L12,6 L0,12 L3,6 z" fill="#ef4444"/>
  355. </marker>
  356. ```
  357. | Line stroke-width | Marker size | refX | Tip extension | End point formula |
  358. |-------------------|-------------|------|---------------|-------------------|
  359. | ≤ 1.5 | 8×8 | 2 | 6px | target edge - 11 |
  360. | 1.5 ~ 2.5 | 12×12 | 3 | 9px | target edge - 14 |
  361. | > 2.5 | 16×16 | 4 | 12px | target edge - 17 |
  362. ## XML special characters (high risk, always check)
  363. SVG is XML, so special characters in text **must** be escaped or the entire SVG fails to render:
  364. | Character | Escape | Example |
  365. |-----------|--------|---------|
  366. | `&` | `&amp;` | `Validate &amp; Sanitize` |
  367. | `<` | `&lt;` | `x &lt; 10` |
  368. | `>` | `&gt;` | `x &gt; 0` |
  369. | `"` | `&quot;` | inside attributes |
  370. | `'` | `&apos;` | inside attributes |
  371. ```xml
  372. <!-- ❌ Wrong: unescaped & -->
  373. <text>Load & Save</text>
  374. <!-- ✅ Correct: escaped -->
  375. <text>Load &amp; Save</text>
  376. ```
  377. ### Escaping when generating SVG programmatically
  378. When generating SVG from Python/JS, text coming from external sources (CSV, database, API) must be escaped before it is concatenated into the SVG:
  379. ```python
  380. def svg_escape(text):
  381. return str(text).replace('&','&amp;').replace('<','&lt;').replace('>','&gt;').replace('"','&quot;')
  382. # ❌ Splicing external data directly ("Research&Development" → XML parse failure, image won't render)
  383. svg += f'<text>{team_name}</text>'
  384. # ✅ Escape first
  385. svg += f'<text>{svg_escape(team_name)}</text>'
  386. ```
  387. **High-risk data sources**: team names (contain `&`), requirement descriptions (contain `<>`), user input, file names
  388. ## Troubleshooting
  389. | Problem | What to check |
  390. |---------|---------------|
  391. | Elements overlap | Text-to-line clearance ≥10px; does a detour path cross a boundary? |
  392. | Arrowhead invisible | Block spacing below 25px — increase it |
  393. | Label off-center | Confirm `text-anchor="middle"` and x = center of the gap |
  394. | Arrow points the wrong way | Check the direction of the final path segment (x/y increasing or decreasing) |
  395. | XML parse error | Check whether `&` `<` `>` in text are escaped |
  396. | Content clipped at the bottom | viewBox height too small; it must equal the bottom edge of the lowest element + 25px |
  397. | Dashed group box off-center after adding a title | Vertical centering must use the combined "title + content" height — see "Dashed grouping boxes" |
  398. | Too much blank space overall | Check whether box spacing >30px or viewBox margin >25px |
  399. ## Verification checklist
  400. - [ ] No overlapping elements (text, boxes, lines)
  401. - [ ] No text right edge intrudes on a neighbor (estimated from character widths)
  402. - [ ] ≥15px between a curve label and the nearest point on the curve
  403. - [ ] Symmetric arrow clearance at both ends (5px), visible line segment ≥6px
  404. - [ ] Markers declare `markerUnits="userSpaceOnUse"`
  405. - [ ] Thick lines (stroke-width > 1.5) use the enlarged marker
  406. - [ ] Connectors use C/Q curves, no right angles
  407. - [ ] Labels centered (`text-anchor="middle"`)
  408. - [ ] Detour paths stay outside obstacles
  409. - [ ] Block spacing ≥25px (25–30px recommended, see "Block spacing")
  410. - [ ] Title centered, boxes in a row similar in size
  411. - [ ] `width` attribute present, viewBox matches the content
  412. - [ ] Box heights sufficient (one line ≥ font-size × 3)
  413. - [ ] Top and bottom viewBox margins comparable (20–25px, measured from the top of the title)
  414. - [ ] Left and right viewBox padding symmetric (use `<g transform="translate(dx,0)">` to shift if not)
  415. - [ ] Special characters escaped (`&` → `&amp;`, `<` → `&lt;`)
  416. - [ ] Every element inside the visible viewBox (bottom = bottom edge of the lowest element + 25px)
  417. - [ ] Every connector has a clear meaning (labeled, or its source and target are inferable from context)
  418. - [ ] Dashed grouping boxes styled consistently (dasharray, corner radius, fill, padding, title font size)
  419. - [ ] No large blank regions (spacing within 30px, viewBox hugs the content)
  420. ## Editing workflow
  421. ### 1. Collect: gather the full set before touching anything
  422. When you receive a request to modify an SVG, **do not start editing immediately**. First judge:
  423. - The user gave **one** change → reply "anything else you want adjusted?" to get the full list in one go
  424. - The user gave **several** changes → move to execution and apply them all at once
  425. Goal: fewer round trips, so you are not re-emitting the whole SVG for every single tweak.
  426. ### 2. Execute: apply everything at once, with a change list
  427. Once all edits are done, print the change list first, then show the final SVG:
  428. ```
  429. Change list:
  430. 1. Title spacing 20px → 30px
  431. 2. Box A fill #dbeafe → #f3e8ff
  432. 3. Connector L1 path adjusted (routes around the new box)
  433. ```
  434. **Do not show the diagram after each individual edit** — the user only needs the final result.
  435. ### 3. Layout tweaks: understand the intent and adjust dependents
  436. When the user says "move box A 20px to the right", do not mechanically change box A's `x` alone. Handle the dependents too:
  437. - Every arrow path to/from box A
  438. - Alignment with the other boxes in box A's row
  439. - The position of box A's text labels
  440. - The size of the outer/background box wrapping box A
  441. **Spacing/alignment requests** ("make it tighter", "left-align it", "center it") → read the overall intent and adjust all related elements in one pass, so the user does not have to iterate pixel by pixel.
README.md · README · 195 lines

View this file on GitHub (read at the repository's current version: the scan did not record which commit it read)

  1. # svg-diagram
  2. A house style for hand-written SVG diagrams your agent can follow — the layout arithmetic, the colour system, and a zero-dependency linter that proves it did.
  3. [![License: MIT](https://img.shields.io/badge/License-MIT-blue.svg)](LICENSE)
  4. [![Agent Skills](https://img.shields.io/badge/Agent-Skills-7C3AED.svg)](https://github.com/vercel-labs/skills)
  5. [![svg-lint: 12 checks](https://img.shields.io/badge/svg--lint-12%20checks-22c55e.svg)](#the-lint-gate)
  6. ![A Markdown doc goes through the svg-diagram skill and comes out as assets/arch.svg](assets/house-style.svg)
  7. ## Install
  8. Paste this to your coding agent:
  9. ```
  10. Install the svg-diagram skill from https://github.com/bybit-exchange/svg-diagram
  11. for me by running: npx skills add bybit-exchange/svg-diagram -g
  12. ```
  13. Or run it yourself:
  14. ```bash
  15. npx skills add bybit-exchange/svg-diagram -g
  16. ```
  17. The CLI detects which agents you have installed and writes each one's path. Drop `-g` to install into the current project instead.
  18. | Surface | Path |
  19. |---|---|
  20. | Claude Code | `~/.claude/skills/svg-diagram/` |
  21. | Codex, Cursor, Gemini CLI, Copilot, opencode, Antigravity | `~/.agents/skills/svg-diagram/` — they share one directory |
  22. | Pi | `~/.pi/skills/svg-diagram/` |
  23. | Windsurf, Continue, Roo, Goose, Kiro, Trae and 40+ more | `~/.<agent>/skills/svg-diagram/` |
  24. | Claude.ai | Zip the folder and upload it under Settings → Capabilities → Skills (skill text only — `svg-lint` needs local Node) |
  25. Every path is named from the skill's frontmatter `name`, not from where the skill sits here, so moving files in this repository doesn't change them.
  26. `SKILL.md` is at the repository root, so the install copies the root and `svg-lint` comes along with the skill text. The linter has no dependencies, so it runs from wherever it landed:
  27. ```bash
  28. node ~/.claude/skills/svg-diagram/tools/svg-lint/bin/svg-lint.mjs diagram.svg
  29. ```
  30. If you only want the skill text, take the one file the agent reads:
  31. ```bash
  32. mkdir -p ~/.claude/skills/svg-diagram
  33. curl -fsSL https://raw.githubusercontent.com/bybit-exchange/svg-diagram/main/SKILL.md \
  34. -o ~/.claude/skills/svg-diagram/SKILL.md
  35. ```
  36. The skill works on its own that way; `svg-lint` is what you give up.
  37. Then start a new session and ask for a diagram — the agent should announce that it's using `svg-diagram`.
  38. ## Gallery
  39. Ten diagrams, all drawn under this skill and all lint clean. Each one is here for the rule it demonstrates.
  40. ### How an agent loads a skill
  41. Two dashed containers side by side. Connectors cross the channel between them, and a colour change marks the point where a request matches.
  42. ![Two dashed groups, disk and session, with connectors crossing between them](gallery/01-architecture-skill-loading.svg)
  43. ### The authoring loop
  44. A cross-layer loop-back line, painted after the boxes so they don't cover it.
  45. ![A six-step authoring loop with a failure branch returning to an earlier step](gallery/02-workflow-svg-authoring.svg)
  46. ### Where the lint gate sits
  47. A self-call that leaves its lifeline and curves back to it, its second control point sharing the end point's y so the arrowhead closes level and points at the participant rather than down the lifeline.
  48. ![A sequence diagram of agent, svg-lint and filesystem, with an alt frame for the repair path](gallery/03-sequence-lint-gate.svg)
  49. ### From a data API to a document figure
  50. CJK labels sized from the CJK column of the width table — one full font size per character, 12px rather than 7.
  51. ![A data flow from a metrics API through escaping to an SVG figure in a document](gallery/04-dataflow-metrics-to-doc.svg)
  52. ### The life of a skill in this repo
  53. One semantic colour triple per state. Each forward arrow carries the colour of the state it leaves.
  54. ![Five skill states from draft to deprecated, with a dashed revision loop](gallery/05-lifecycle-skill-states.svg)
  55. ### What's in this repository
  56. A dashed border only where the contents are actually drawn — `gallery/` and `assets/` are directories too, but their members aren't in the figure, so they stay plain boxes.
  57. ![The repository tree, with the skill's files at the root and one dashed directory group](gallery/06-architecture-repo-layout.svg)
  58. ### One command, every agent
  59. A one-to-many fan-out whose branch curves keep each second control point level with the end point, so every arrowhead lands pointing right.
  60. ![One install command fanning out to five agent skill directories](gallery/07-workflow-install-surfaces.svg)
  61. ### Why the font stack cannot be dropped
  62. A contrast pair built from two semantic triples: the working paths in green, the branch that fails in pink.
  63. ![Three platforms rendering CJK text correctly, and a fourth showing missing glyphs](gallery/08-reference-cjk-fonts.svg)
  64. ### Tiered model routing behind one gateway
  65. A symmetric fan-out and convergence, one triple per tier. Only the middle leg leaves the rule box's bottom edge; the two outer ones leave its sides.
  66. ![A request classified into one of three capability tiers, all converging on a single gateway](gallery/09-dataflow-tiered-routing.svg)
  67. ### A/B benchmark with a model as judge
  68. A dashed group box around exactly the steps that repeat. The return edge is painted last, so it stays legible where it crosses the wall.
  69. ![A repeating benchmark loop comparing a baseline against a router, with a model judging both answers](gallery/10-workflow-ab-benchmark.svg)
  70. ## What the skill pins down
  71. | Area | What's pinned down |
  72. |---|---|
  73. | Layout | viewBox margins of 20–25px, the title centred on the content centre rather than the viewBox, and off-centre content shifted with a single `<g transform="translate(dx,0)">` |
  74. | Boxes | Height derived from the font — one line is `font-size × 3`, each extra line adds `font-size × 1.5` — and boxes sharing a row whose sizes differ by no more than 60px |
  75. | Connectors | A straight `L` only when the two ends are co-axial, a `C` or `Q` curve for anything that turns, and no right-angle elbows |
  76. | Arrowheads | A notched marker with `markerUnits="userSpaceOnUse"`, sized to the line's stroke width, starting 5px clear of the source and ending 11px short of the target |
  77. | Text | Baseline at `box y + height/2 + font-size × 0.35` to centre inside a box, and at least 10px of clearance from a straight connector — 15px from a curve, with the label above a downward bend and below an upward one |
  78. | Fonts | 16px titles, 12px box text, 10px annotations, over a stack that keeps `Noto Sans CJK SC` so Linux rendering doesn't fall back to tofu |
  79. | Colours | Five semantic fill/stroke/text triples applied through presentation attributes — no CSS classes, no media queries |
  80. | Escaping | `&`, `<`, `>`, `"` and `'` escaped in text and attributes, and anything from a database or an API escaped before it's concatenated into the file |
  81. Every diagram also paints its own white canvas rect as the first element, so it reads as a light card on GitHub's dark theme instead of dark text on a dark background. That isn't theme switching. The diagram carries one colour set, and the rect exists only so that set stays readable wherever the file is embedded.
  82. The full rules — the character width tables, the six arrowhead colour variants, the coordinate bookkeeping, and a twenty-item verification checklist — are in [SKILL.md](SKILL.md), which is the single source of truth.
  83. ## Why
  84. - **Checked on the real artifact.** The linter reads the finished SVG, not an intermediate format. Nothing sits between the receipt and the file you ship.
  85. - **Zero dependencies.** `svg-lint` is plain Node with no packages. It runs in a fresh clone, with no install step and no lockfile.
  86. - **Placed, not auto-laid-out.** The skill hands the agent the arithmetic — box height, baseline offset, arrow clearance, block spacing — so every element lands somewhere chosen rather than somewhere a layout engine picked.
  87. - **Findings name the fix.** A failure reports the value it found and the value it should hold: `viewBox: 11 → 20–25`, not "the margin looks wrong".
  88. - **CJK-safe by default.** A mandatory font stack, plus separate character-width tables for Latin and CJK, so labels are checked for overflow before they're placed.
  89. - **Reviewable as text.** Every coordinate is a literal, annotated with a comment explaining why it holds that value, so a change to a diagram reads as a diff instead of a re-render.
  90. - **Plain SVG out.** No runtime, no viewer, no JavaScript. It renders in a README, a docs site, a PDF and a terminal preview.
  91. ## The lint gate
  92. `svg-lint` reads the finished SVG and reports what the house style forbids. It's a maintainer tool, run by hand. Nothing invokes it for you, so run it before you hand a diagram over.
  93. ```bash
  94. node tools/svg-lint/bin/svg-lint.mjs diagram.svg
  95. node tools/svg-lint/bin/svg-lint.mjs diagram.svg --json
  96. ```
  97. Try it on a deliberately broken file:
  98. ```bash
  99. printf '%s' '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 200 60" width="200"><text x="50" y="20" font-size="12">Load & Save</text></svg>' > /tmp/broken.svg
  100. node tools/svg-lint/bin/svg-lint.mjs /tmp/broken.svg
  101. ```
  102. That reports 3 errors and 7 warnings and exits 1: the unescaped `&`, the missing font stack, the missing white canvas rect, an off-palette fill, four viewBox margins outside the 20–25px range, and asymmetric margins on both axes. Each finding carries the id of the check that raised it and a repair line:
  103. ```
  104. 1:1 error No <style> rule declares font-family for text [font-stack/missing-font-stack]
  105. repair: font-family: absent → 'PingFang SC', 'Microsoft YaHei', 'Noto Sans CJK SC', system-ui, sans-serif · SKILL.md marks this non-negotiable
  106. ```
  107. The 12 checks cover XML escaping, viewBox clipping, the font stack, box height, baseline offset, block spacing, arrow markers, text overflow, overlap, light-background fallback, palette conformance and connector geometry. A thirteenth id, `document-model`, raises no findings of its own. It's how the model layer reports what it couldn't read, so the geometry checks never draw conclusions from coordinates they got wrong.
  108. > `0 errors, 0 warnings` is the only pass; a warning is a failure.
  109. Exit codes, the `--json` shape, and what each check does and doesn't catch are in [tools/svg-lint/README.md](tools/svg-lint/README.md). SKILL.md carries a troubleshooting table for the symptoms that reach you before the linter does.
  110. ## Contributing
  111. This repository holds one skill, and the `SKILL.md` at the root is it.
  112. Frontmatter takes `name` and `description`; `license` and a `metadata` map (version, author, requirements) are welcome too. `name` is what every install path keys off. The `description` is what the agent matches on, so write it as "what it covers + when to use it" — that line is the trigger, and the body costs nothing until the work matches it.
  113. Before you open a PR, use the skill for a real task in a fresh session. If the agent didn't load it on its own, the description needs work; if the output still needed manual correction, the body is missing a rule — or the linter is missing a check.
  114. Diagrams committed here must pass clean, and the test suite has to stay green:
  115. ```bash
  116. npm run lint:svg:all # the 11 SVGs this repo ships
  117. npm test # 984 tests
  118. ```
  119. Everything under `tools/svg-lint/test/fixtures/` is excluded from the lint run — for the 14 under `fail/`, failing is their job, and the 2 under `pass/` are asserted by the test suite instead.
  120. ## License
  121. [MIT](LICENSE)

Ratings and comments

Sign in to rate this skill.

Sign in

Free to use. If it’s helped, pass it on.