baoyu-diagram
Create professional, dark-themed SVG diagrams of any type — architecture diagrams, flowcharts, sequence diagrams, structural diagrams, mind maps, timelines, illustrative/conceptual diagrams, and more. Use this skill whenever the user asks for any kind of technical or conceptual diagram, visualization of a system, process flow, data flow, component relationship, network topology, decision tree, org chart, state machine, or any visual representation of structure/logic/process. Also trigger when the user says "画个图" "画一个架构图" "diagram" "flowchart" "sequence diagram" "draw me a ..." or uploads content and asks to visualize it. Output is always a standalone .svg file.
1How It Works & Mechanism
Nine diagram types share a single unified "design system": semantic color palette (assigned by component category rather than tech stack), typography hierarchy, dark base + grid background, and three arrow markers—define the system before laying out content.
| Primary | `rgba(8, 51, 68, 0.4)` | `#22d3ee` (cyan) | Frontend, user-facing, inputs |
Layout utilizes a "fixed rendering order + opaque mask rectangles" to eliminate SVG semi-transparent overlap issues: draw arrows first, cover them with opaque fill rectangles in the same position, and finally overlay semi-transparent component boxes.
The opaque masking rect trick is essential — semi-transparent component fills will show arrows underneath without it:
Directly applicable, hard numeric rules for spacing/boundaries replace subjective aesthetic judgment: component height 50–70px, vertical spacing ≥40px, horizontal spacing ≥30px, arrow labels 10px from edges, and 30px padding around viewBox.
- **Minimum gap between components:** 40px vertical, 30px horizontal
Each diagram type has an algorithm reference for layout to consult beforehand: layering, column/row allocation, column spacing, L-shaped obstacle-avoidance routing, bus lanes, etc., all have defined approaches.
1. **Identify layers:** Group components by role (clients, gateways, services, data, infrastructure)
Output is a single-file, self-contained SVG: no fixed width/height, defined solely via viewBox, with all styles and defs inlined for seamless scaling and embedding.
2. Set `viewBox` to fit all content with 30px padding; do NOT set fixed `width`/`height` attributes (let the SVG scale responsively)
Includes a built-in script to rasterize SVG into @2x PNG: calculates dimensions by parsing viewBox, then uses sharp to render with density=72*scale and resize into a PNG.
await sharp(svg, { density: 72 * opts.scale })
Dedicated handling for Chinese typography: accounting for wider Chinese characters by switching font families and widening boxes to avoid text overflow.
**Chinese text support:** When labels contain Chinese characters, use `font-family: 'JetBrains Mono', 'Noto Sans SC', 'PingFang SC', sans-serif'` and increase box widths — CJK characters are wider
Explicit file saving conventions: saves to {inputFileDir}/diagram/ if input is a file, otherwise to {projectDir}/diagram/{topic-slug}/, creating directories when non-existent.
**Save location:** If the input is a file, save to `{inputFileDir}/diagram/`.
2Core Capabilities
3External Dependencies
| Kind | Dependency / Endpoint |
|---|---|
| package | sharp(scripts/main.ts 动态 import,用于 SVG→PNG 光栅化) |
| cli | bun / npx(${BUN_X} 运行时) |
| network | Google Fonts(写入产物 SVG 的 @import,由查看端加载;非脚本外发) |
4Recommended Governance & Evidence
- scripts/: Executes local script or command: scripts/main.ts (run via bun; sharp rasterizes local SVG files to PNG)
- 本地工作目录: File I/O and artifact output: writes <input>@2x.png (or -o designated path), creates diagram/ directory when needed
5Second-Pass Verification
- [ok] 脚本仅本地行为 — main.ts 全文无 fetch/http/spawn/process.env;readFileSync(SVG) → sharp(density) → resize → png → toFile,另 mkdirSync 建目录。
- [ok] Google Fonts 外链的性质 — 两处命中均为写入产物 SVG 的 @import 文本与 Output Rules 自述 'no external dependencies except the Google Fonts import';脚本自身不请求该域名,按批4 口径不判级,已写入 risks。
- [ok] 绘制顺序与遮罩矩形确为强制 — SKILL.md 明写 'The opaque masking rect trick is essential',并给出 8 层绘制顺序与组件片段(遮罩 rect + 样式 rect 成对)。
- [ok] 间距规则为可检查数字 — 组件高 50-70px、垂直 ≥40px/水平 ≥30px、箭头标签 10px、区域边界内缩 20px、图例距最低元素 ≥20px、viewBox 30px padding,最后一并在流程第 5 步自检。
- [ok] 参考文件覆盖范围(是否夸大) — 4 份布局参考对应 architecture/flowchart/sequence/structural;思维导图/时间线/状态机/数据流/示意在图型表中给出要点但无专门文件,SKILL.md 用 'Read the reference file if one exists for that type' 表述,不构成夸大。
- [ok] meta 元数据 — GitHub API:MIT、25926 stars、pushed_at 2026-09-10T15:13:43Z;本地 HEAD 与 pin 1567581c26ec… 一致。
6Verdict & Scenarios
e4806bf926545ede…