Community图像github.com

diagram-studio

Rebuild, beautify and create diagrams (architecture diagrams, flowcharts, pipelines, system overviews, agent loops) as crisp, editable PNG + SVG. Core use is a high-fidelity redraw of an existing diagram image (blurry, low-res, AI-generated, cluttered or watermarked) that keeps its exact text, layout, colours and look (hand-drawn or clean/flat) while making it sharp. For any image made of boxes, arrows and text, prefer this over AI image generation or upscaling: it redraws the image as vector, so every word stays exact. It also restyles diagrams (hand-drawn, Excalidraw-like, whiteboard, blueprint, clean corporate, academic, dark) and draws new ones from text, code or notes, with full Chinese support. Triggers include 重绘, 复刻, 高清重建, 变清晰, 美化这张图, 风格复现, 手绘风, 架构图, 流程图, 示意图, and requests to redraw, recreate or sharpen a diagram.

diagram-studio 是什么?

diagram-studio is a Claude Code agent skill that rebuild, beautify and create diagrams (architecture diagrams, flowcharts, pipelines, system overviews, agent loops) as crisp, editable PNG + SVG. Core use is a high-fidelity redraw of an existing diagram image (blurry, low-res, AI-generated, cluttered or watermarked) that keeps its exact text, layout, colours and look (hand-drawn or clean/flat) while making it sharp. For any image made of boxes, arrows and text, prefer this over AI image generation or upscaling: it redraws the image as vector, so every word stays exact. It also restyles diagrams (hand-drawn, Excalidraw-like, whiteboard, blueprint, clean corporate, academic, dark) and draws new ones from text, code or notes, with full Chinese support. Triggers include 重绘, 复刻, 高清重建, 变清晰, 美化这张图, 风格复现, 手绘风, 架构图, 流程图, 示意图, and requests to redraw, recreate or sharpen a diagram.

兼容平台✓Claude Code✓Codex CLI~Cursor
npx skills add https://github.com/stlmx/diagram-studio/tree/HEAD

Installed? Explore more 图像 skills: steipete/songsee, affaan-m/frontend-design, mattpocock/improve-codebase-architecture · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Diagram Studio

Turn a JSON spec into a crisp diagram. The look is fully configurable:

  • Hand-drawn: rough.js wobble and handwriting fonts.
  • Crisp vector: zero wobble, sans or serif fonts, soft shadows.
  • Anything in between.

All text is converted to outlines, so the SVG and PNG look identical everywhere. A linter catches overlaps, overflowing text, labels on borders and arrows that pass through boxes.

Everything is bundled: Node 18+ is the only requirement, with no npm install and no network. SKILL_DIR below means the absolute path of this skill folder (the folder that contains this file).

node SKILL_DIR/scripts/render.mjs diagram.json --out out/     # → out/diagram.png (2x), .svg, .report.json, .tiles/

0. Running in Codex, Claude Code or another agent

  • SKILL_DIR:
    • In Codex, expand the skill's short path with the skill-roots table (e.g. r0/diagram-studio/SKILL.md → ~/.codex/skills/diagram-studio).
    • In Claude Code it is usually ~/.claude/skills/diagram-studio.
    • Always call the scripts with that absolute path.
  • Looking at images is mandatory: the original, the grid, the tiles and the comparison.
    • Codex: use the view_image tool with the PNG path. render.mjs writes name.preview.png (≤ 1400 px) for this, so there is no need to resize the image yourself; use name.tiles/*.png for detail.
    • Claude Code: use the Read tool.
    • Never judge a render from the lint output alone.
  • Sandbox-friendly:
    • Only node is needed. There are no network calls and no installs.
    • Outputs go to --out; keep it inside the workspace, e.g. ./diagram-out.
    • WebP/HEIC conversion writes to the system temp dir.
  • The user pasted an image instead of giving a path: if you can see an attachment path, use it. Otherwise ask for the file path, because the tools need a real file.
  • Finishing: list the absolute paths of the PNG, SVG and JSON so the user can open them.

1. Pick the job

User wantsJobRead next
"Make this image clearer / higher-res / cleaner", "redraw / rebuild / 复刻 / 高清重建 this"A. Rebuild from image. Fidelity first: keep the original's style unless told otherwisereferences/rebuild-from-image.md (required)
"Beautify / tidy / 美化 this diagram"A + polish. Same as A, then improve hierarchy, spacing and alignmentreferences/rebuild-from-image.md
A new diagram from a description, code or notesB. New diagramreferences/spec.md
A different look ("make it hand-drawn", "flat corporate", "blueprint", "for a paper")C. Restylereferences/style-guide.md

For a given image, match its style by default: hand-drawn stays hand-drawn, flat stays flat, and its colours and font category stay as they are. Only change the look when the user asks. Presets are starting points, not limits; styleOverrides, custom palettes and custom font files ("fonts") can reproduce almost any look. Ask about the fidelity level only when the request is genuinely ambiguous, for example "beautify" with no reference style. Otherwise default to faithful + clearer.

Start from the closest template in templates/: copy it into the working folder and edit the copy. Previews are in assets/gallery/. A template is a pattern, not content: replace all of its text and keep line breaks and arrows exactly as in your source. --expect catches leftovers and changed wording.

TemplateShows
dense-rebuild.jsonRebuild of a dense architecture image: explicit coordinates, cards, panels, merged connectors, inline labels
pipeline-rag.jsonLeft-to-right pipeline: rows with connect, rightOf, auto-fitting panels
layered-architecture-zh.jsonChinese layered architecture: stacked below rows, fan-in arrows, cylinders
flowchart-decision.jsonFlowchart: pill, diamond, yes/no branches, loop-back arrows
agent-loop.jsonCycle: curved arrows, badges, ellipse hub
auto-layout.jsonNo coordinates: ELK auto-layout with groups

2. The loop (every job)

  1. Inventory first. List every text string verbatim (save it as texts.txt, one per line), every node, every arrow (from → to, label) and every group. Nothing gets invented or dropped.

  2. Write name.json, starting from a template.

  3. Render: node SKILL_DIR/scripts/render.mjs name.json --out OUT --expect texts.txt

  4. Fix every ERROR; each one comes with a concrete → fix. Fix WARNs unless intended, and silence intended ones with "ignore": ["code"] on that element or arrow.

  5. Look at OUT/name.png and OUT/name.tiles/*.png, and compare with the original (scripts/compare.mjs). Run the checklist in prompts/visual-review.md; the linter cannot judge meaning, balance or fidelity.

  6. Repeat steps 3–5 until there are 0 errors and it reads well (usually 2–4 rounds).

  7. Deliver:

    • name.png: 2x; use --scale 3 for print.
    • name.svg: vector.
    • name.json: kept for later edits.

    Add one line on what you kept and what you improved.

3. Spec in 60 seconds

{
  "canvas": { "width": 1600 },
  "style": "marker",
  "title": "Checkout Service",
  "subtitle": "{blue:clients} · {purple:services} · {green:data}",
  "elements": [
    { "id": "web", "title": "Web app", "icon": "app-window", "x": 120, "y": 220 },
    { "id": "api", "title": "API", "color": "purple", "emphasis": true, "rightOf": "web", "gap": 160,
      "lines": ["`POST /checkout`", { "text": "validates cart", "muted": true }] },
    { "id": "db", "type": "cylinder", "title": "Orders DB", "color": "green", "below": "api", "gap": 120 },
    { "id": "core", "type": "panel", "title": "Backend", "color": "purple", "contains": ["api", "db"] },
    { "id": "n1", "type": "note", "text": "Idempotent by **order id**", "rightOf": "core", "gap": 40 }
  ],
  "arrows": [
    { "from": "web", "to": "api", "label": "HTTPS" },
    { "from": "api", "to": "db", "label": "INSERT", "color": "green" }
  ]
}
  • Element types: box (default), pill, ellipse, circle, diamond, cylinder, note, card, panel, text, icon, badge, image, path (custom SVG shape), plus the layout helpers row, column and group.

  • Position each element with one of these:

    • x/y for the top-left corner, or cx/cy for the centre.
    • below / above / rightOf / leftOf plus gap.
    • contains, which auto-fits a panel around its children.

    Size is automatic. Set w/h to match an original exactly.

  • Text: title is bold, and \n breaks the line. lines are body lines. Markup inside text:

    • **bold**
    • `code` (uses the code font)
    • {green:span} and {muted:span}
    • -> (drawn as an arrow glyph)

    Chinese and English mix freely. Per element you can set size, textSize, font, textColor and align.

  • Colour with a family (blue purple green orange red teal yellow pink gray navy), a shade (blue.tint), #hex or a plain CSS name such as white, set through color, fill, stroke and textColor.

  • Arrows connect from to to:

    • Pin a side and slide along it with "id.right" or "id.right+20".
    • Labels: label, placed with labelPos (above, below, left, right or inline) and nudged with labelAt.
    • Look: dash, color, width, and head (end, start, both or none).
    • Path: via points, points (an exact polyline), or "route": "curve".

Every key is in references/spec.md.

4. Look: style, palette, font, effects

  • Style presets:

    • Hand-drawn: marker (default), neat, excalidraw, sketchy, whiteboard, pencil, blueprint, chalk.
    • Crisp: clean, paper.

    Any preset field can be overridden through styleOverrides:

    • roughness (0 = perfectly straight lines) and bowing
    • fillStyle (solid, hachure, cross-hatch, dots or none)
    • strokeScale, cornerRadius
    • shadow (none, soft or hard)
    • font, cjkFont, codeFont, background
  • Palettes: marker, pastel, excalidraw, mono, academic, colorblind, modern, blueprint, chalkboard, midnight. To reproduce an original's colours exactly, run node SKILL_DIR/scripts/palette.mjs original.png and paste the result.

  • Fonts:

    • Handwriting: shantell, kalam, caveat, patrick, architects.
    • Sans: inter. Serif: serif. Mono: mono.
    • CJK: kai (handwritten), kuaile (playful), sans-sc (clean).
    • Your own .ttf/.otf/.woff: "fonts": {"brand": {"regular": "Brand.ttf", "bold": "Brand-Bold.ttf"}}, then "font": "brand".
  • Catalogs: assets/gallery/styles.png, palettes.png and fonts.png. Regenerate them with scripts/catalog.mjs.

  • Icons: 1,500+ Lucide icons. Search with node SKILL_DIR/scripts/icons.mjs search 数据库 robot queue, and preview with icons.mjs sheet a,b,c.

  • Original-image tools:

    • grid.mjs: overlay coordinates on the original. Read the red axis labels, never pixel positions.
    • fontmatch.mjs: show sample text in every font next to a zoomed crop of the original.
    • palette.mjs: extract the original's colours.
    • crop.mjs: cut out logos, photos or screenshots to embed as image elements.
    • compare.mjs: side-by-side review; add --crop x,y,w,h to zoom both images to the same region.
  • Dark or alternate versions: keep the same spec and change only palette (midnight, blueprint or chalkboard) or style, then render under another --name.

  • For slides (PPT, Keynote): "canvas": {"aspect": "16:9"} pads the image to the slide ratio. "background": "transparent" gives a PNG with alpha. The SVG can also be pasted directly.

5. Clarity rules (always apply)

  1. Keep the words exactly as given: labels, code identifiers and Chinese terms. Never invent, translate or drop text unless asked.
  2. Make the hierarchy visible:
    • Bold title per box.
    • Identifiers as body or code text.
    • Explanations as muted text.
    • Section titles in their section's colour.
  3. Colour means something: one family per region or role, used consistently. Arrow labels inherit their arrow's colour.
  4. Room to breathe:
    • ≥ 60 px between shapes joined by a labelled arrow, ≥ 24 px otherwise.
    • Panels fitted with contains.
    • No label on a border.
  5. Readable when shrunk:
    • Text ≥ 18 px (defaults: node 30, body 25, label 24).
    • Canvas 1400–2200 px wide, with an aspect ratio between 1:2 and 3:1. The linter warns otherwise.
    • Long chains of 6+ nodes: snake them into 2–3 rows, or use ELK "direction": "DOWN", rather than one very long row.
  6. Few crossings and no detours. Align and reorder before adding via.
  7. Polish, don't redesign, in rebuild jobs: improve alignment, spacing and hierarchy, but keep topology, reading order and style identity.

6. Definition of done

  • render.mjs reports 0 errors. Any remaining warning is intended and silenced with ignore.
  • Every inventory string is present and spelled exactly (--expect texts.txt passes).
  • You viewed the PNG and the tiles, and for rebuilds compared them side by side with the original: same structure, same style identity, clearer.
  • You delivered the PNG, SVG and JSON, with a short "kept / improved" note.

7. Troubleshooting

  • node: command not found: install Node 18+. Nothing else is needed.
  • WebP, HEIC, BMP or TIFF input is converted automatically when sips, magick, dwebp, ffmpeg or Python PIL is available. Otherwise ask the user for a PNG or JPEG.
  • A character renders as ?: the bundled fonts cover Latin, GB2312 Chinese and common symbols. Rephrase it, or register a font that has it.
  • For every lint code and its fix, see references/troubleshooting.md.

相关技能