tldraw-skill
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesetldraw Whiteboard Diagrams
tldraw 白板图表
Overview
概述
Generate modern whiteboard-style diagrams as JSON files and export to PNG/SVG using . tldraw produces clean hand-drawn aesthetic diagrams with rich shape libraries and smooth arrow routing — well-suited for casual or whiteboard-style visualizations.
.tldr@kitschpatrol/tldraw-cliFormat: JSON
Export: PNG, SVG (via )
Aesthetic: Hand-drawn whiteboard style by default; switchable to clean fonts via prop.
.tldr@kitschpatrol/tldraw-clifont通过生成现代白板风格的.tldr JSON格式图表,并导出为PNG/SVG。tldraw可生成具有简洁手绘风格的图表,拥有丰富的形状库和流畅的箭头路由,非常适合非正式或白板风格的可视化需求。
@kitschpatrol/tldraw-cli格式: .tldr JSON
导出格式: PNG、SVG(通过)
风格: 默认手绘白板风格;可通过属性切换为简洁字体。
@kitschpatrol/tldraw-clifontWhen to Use
使用场景
Explicit triggers: user says "diagram", "flowchart", "draw", "visualize", "whiteboard diagram", "tldraw diagram", "architecture diagram", "sketch this out".
Proactive triggers:
- Explaining a system with 3+ interacting components
- Describing a multi-step process, data flow, or pipeline
- Showing relationships between services/modules
- Architecture overviews, sequence flows, decision trees, ML model layers
Skip when: a simple list or table suffices, the user wants a polished business-presentation diagram (prefer drawio-skill), or the user is in a quick Q&A flow.
明确触发条件: 用户提及“图表”“流程图”“绘制”“可视化”“白板图表”“tldraw图表”“架构图”“把这个画出来”等词汇。
主动触发条件:
- 解释包含3个及以上交互组件的系统
- 描述多步骤流程、数据流或管道
- 展示服务/模块之间的关系
- 架构概览、序列流、决策树、ML模型层级
跳过场景: 简单列表或表格即可满足需求时,用户需要专业商务演示风格图表(推荐使用drawio-skill),或用户处于快速问答流程中。
Prerequisites
前置要求
bash
undefinedbash
undefinedInstall tldraw-cli
安装tldraw-cli
npm install -g @kitschpatrol/tldraw-cli
npm install -g @kitschpatrol/tldraw-cli
Verify
验证版本
tldraw --version
Works identically on macOS, Windows, and Linux — no extra setup required.tldraw --version
在macOS、Windows和Linux系统上运行方式完全一致,无需额外配置。Workflow
工作流程
Before starting, assess whether the user's request is specific enough. If key details are missing, ask 1-3 focused questions:
- Diagram type — which preset? (Architecture, Flowchart, Sequence, ML/DL, ERD, UML, or general)
- Output format — PNG (default), SVG?
- Output location — default is the user's working dir; honor any explicit path the user gives (e.g. "put it in "). Don't ask if they didn't mention one.
./artifacts/ - Scope/fidelity — how many components? Any specific technologies or labels?
Skip clarification if the request already specifies these details or is clearly simple (e.g., "draw a flowchart of X").
-
Update check (notify, don't pull) — first use per conversation. Throttle to once per 24 h via; never mutate the skill directory without explicit user consent.
<this-skill-dir>/.last_update-
Ifexists and is <24 h old, skip this step entirely.
.last_update -
Otherwise, fetch the latest tag from upstream:bash
git -C <this-skill-dir> ls-remote --tags origin 'v*' 2>/dev/null \ | awk '{print $2}' | sed 's|refs/tags/||' | sort -V | tail -1 -
Compare with this skill'sfrom the frontmatter. If the upstream tag is strictly newer (semver), tell the user one line and ask:
metadata.version"A newer version of this skill is available: vX.Y.Z → vA.B.C. Want me to?"git pullIf they say yes, run. Refreshgit -C <this-skill-dir> pull --ff-onlyeither way so the prompt doesn't repeat for 24 hours..last_update -
If upstream is the same or older, refreshsilently and continue.
.last_update -
On any failure (offline, not a git checkout — e.g. ClawHub-installed copy, read-only path, no permission), swallow the error silently and continue with the user's task. Do not mention the failure.
-
-
Check deps — verifysucceeds; if missing, run
tldraw --version.npm install -g @kitschpatrol/tldraw-cli -
Plan — identify shapes (geo type per node), connections (arrows with source/target), and layout (TB or LR, group by tier/role). Sketch a coordinate grid before writing JSON.
-
Generate — write theJSON file. Default output dir is the user's working dir; if the user specified a path or directory (e.g.
.tldr),./artifacts/it first and write there. Apply the same dir choice to PNG/SVG exports in steps 4 and 7.mkdir -p -
Export draft — run CLI to produce a PNG for preview.
-
Self-check — use the agent's built-in vision capability to read the exported PNG, catch obvious issues, auto-fix before showing the user (requires a vision-enabled model such as Claude Sonnet/Opus). If vision is unavailable, skip this step.
-
Review loop — show image to user, collect feedback, apply targeted JSON edits, re-export, repeat until approved.
-
Final export — export the approved version to all requested formats; report file paths for both thesource and exported image(s).
.tldr
开始前,评估用户的请求是否足够明确。如果缺少关键细节,可提出1-3个针对性问题:
- 图表类型 — 使用哪种预设?(架构图、流程图、序列图、ML/DL图、ERD、UML或通用类型)
- 输出格式 — PNG(默认)还是SVG?
- 输出位置 — 默认是用户的工作目录;若用户指定了路径(如“放到”)则遵循其要求。用户未提及则无需询问。
./artifacts/ - 范围/精细度 — 包含多少组件?是否有特定技术或标签?
如果请求已明确包含这些细节或明显简单(如“绘制X的流程图”),则跳过澄清步骤。
-
版本更新检查(仅通知,不自动拉取) — 每次对话首次使用时执行。通过限制为24小时一次;未经用户明确同意,绝不修改技能目录。
<this-skill-dir>/.last_update-
若存在且距今不足24小时,直接跳过此步骤。
.last_update -
否则,从上游获取最新版本标签:bash
git -C <this-skill-dir> ls-remote --tags origin 'v*' 2>/dev/null \ | awk '{print $2}' | sed 's|refs/tags/||' | sort -V | tail -1 -
将其与技能前导内容中的对比。若上游版本更新(遵循语义化版本规则),告知用户并询问:
metadata.version"此技能有新版本可用:vX.Y.Z → vA.B.C。是否需要执行更新?"git pull若用户同意,执行。无论用户是否同意,都刷新git -C <this-skill-dir> pull --ff-only,确保24小时内不再重复提示。.last_update -
若上游版本相同或更旧,静默刷新并继续。
.last_update -
若出现任何失败(离线、非git检出版本——如ClawHub安装的副本、只读路径、无权限),静默忽略错误并继续执行用户任务,不提及失败情况。
-
-
依赖检查 — 验证执行成功;若未安装,运行
tldraw --version。npm install -g @kitschpatrol/tldraw-cli -
规划 — 确定形状(每个节点对应的几何类型)、连接(带源/目标的箭头)和布局(上下或左右方向,按层级/角色分组)。编写JSON前先构思坐标网格。
-
生成文件 — 编写.tldr JSON文件。默认输出目录为用户工作目录;若用户指定了路径或目录(如),先执行
./artifacts/创建目录,再写入文件。步骤4和7中的PNG/SVG导出也使用相同目录。mkdir -p -
导出草稿 — 运行CLI生成PNG预览图。
-
自我检查 — 使用Agent内置的视觉功能读取导出的PNG,发现明显问题后自动修复再展示给用户(需要支持视觉的模型,如Claude Sonnet/Opus)。若不支持视觉功能,跳过此步骤。
-
反馈循环 — 向用户展示图片,收集反馈,针对性修改JSON,重新导出,重复此过程直至用户认可。
-
最终导出 — 将认可的版本导出为所有请求的格式;告知用户.tldr源文件和导出图片的文件路径。
Step 5: Self-Check
步骤5:自我检查
After exporting the draft PNG, use the agent's vision capability (e.g., Claude's image input) to read the image and check for these issues before showing the user. If the agent does not support vision, skip self-check and show the PNG directly:
| Check | What to look for | Auto-fix action |
|---|---|---|
| Overlapping shapes | Two or more shapes stacked on top of each other | Shift shapes apart by ≥200px |
| Clipped labels | Text cut off at shape boundaries | Increase shape |
| Missing arrows | Arrows that don't visually connect to shapes | Verify |
| Off-canvas shapes | Shapes at negative coordinates or far from the main group | Move to positive coordinates near the cluster |
| Arrow-shape overlap | An arrow visually crosses through an unrelated shape | Adjust |
| Stacked arrows | Multiple arrows overlap each other on the same path | Distribute |
- Max 2 self-check rounds — if issues remain after 2 fixes, show the user anyway.
- Re-export after each fix and re-read the new PNG.
导出草稿PNG后,使用Agent的视觉功能(如Claude的图片输入)读取图片,在展示给用户前检查以下问题。若Agent不支持视觉功能,跳过自我检查直接展示PNG:
| 检查项 | 检查内容 | 自动修复操作 |
|---|---|---|
| 形状重叠 | 两个或多个形状堆叠在一起 | 将形状错开至少200px |
| 标签截断 | 文本被形状边界截断 | 增大形状的 |
| 箭头缺失 | 箭头未与形状视觉连接 | 验证 |
| 形状超出画布 | 形状位于负坐标或远离主群组 | 将形状移至主群组附近的正坐标区域 |
| 箭头与形状重叠 | 箭头穿过无关形状 | 调整 |
| 箭头堆叠 | 多个箭头在同一路径上重叠 | 在形状周边分配不同的 |
- 最多执行2轮自我检查 — 若2次修复后仍有问题,直接展示给用户。
- 每次修复后重新导出并读取新的PNG。
Step 6: Review Loop
步骤6:反馈循环
After self-check, show the exported image and ask the user for feedback.
Targeted edit rules — for each type of feedback, apply the minimal JSON change:
| User request | JSON edit action |
|---|---|
| Change color of X | Find shape by |
| Add a new node | Append a new shape record with next available index, position near related nodes |
| Remove a node | Delete the shape record and any arrow records bound to it |
| Move shape X | Update the shape's |
| Resize shape X | Update |
| Add arrow from A to B | Append a new arrow record binding to A and B's shape ids |
| Change label text | Update |
| Change layout direction | Full regeneration — replan the grid and rebuild |
Rules:
- For single-element changes: edit the existing JSON in place — preserves layout tuning from prior iterations.
- For layout-wide changes (e.g., swap LR↔TB, "start over"): regenerate full JSON.
- Overwrite the same each iteration — do not create
{name}.png,v1,v2files.v3 - After applying edits, re-export and show the updated image.
- Loop continues until user says approved / done / LGTM.
- Safety valve: after 5 iteration rounds, suggest the user open the file in tldraw.com or the desktop app for fine-grained adjustments.
.tldr
自我检查完成后,向用户展示导出的图片并请求反馈。
针对性修改规则 — 根据反馈类型,进行最小化的JSON修改:
| 用户请求 | JSON修改操作 |
|---|---|
| 修改X的颜色 | 通过 |
| 添加新节点 | 添加新的形状记录,使用下一个可用索引,放置在相关节点附近 |
| 删除节点 | 删除形状记录以及所有绑定到该节点的箭头记录 |
| 移动形状X | 更新形状的 |
| 调整形状X大小 | 更新 |
| 添加从A到B的箭头 | 添加新的箭头记录,绑定到A和B的形状id |
| 修改标签文本 | 更新匹配形状或箭头的 |
| 修改布局方向 | 完全重新生成 — 重新规划网格并重建JSON |
规则:
- 单元素修改:直接编辑现有JSON — 保留之前迭代的布局调整。
- 全局布局修改(如切换上下/左右方向、“重新开始”):重新生成完整JSON。
- 每次迭代覆盖同一个文件 — 不创建
{name}.png、v1、v2等版本文件。v3 - 修改后重新导出并展示更新后的图片。
- 循环持续到用户表示认可/完成/LGTM。
- 安全机制: 经过5轮迭代后,建议用户在tldraw.com或桌面应用中打开.tldr文件进行精细调整。
File Format
文件格式
Complete .tldr Skeleton
完整.tldr骨架
json
{
"tldrawFileFormatVersion": 1,
"schema": {
"schemaVersion": 1,
"storeVersion": 4,
"recordVersions": {
"asset": {"version": 1, "subTypeKey": "type", "subTypeVersions": {"image": 2, "video": 2, "bookmark": 0}},
"camera": {"version": 1},
"document": {"version": 2},
"instance": {"version": 17},
"instance_page_state": {"version": 3},
"page": {"version": 1},
"shape": {"version": 3, "subTypeKey": "type", "subTypeVersions": {"group": 0, "embed": 4, "bookmark": 1, "image": 2, "text": 1, "draw": 1, "geo": 7, "line": 0, "note": 4, "frame": 0, "arrow": 1, "highlight": 0, "video": 1}},
"instance_presence": {"version": 4},
"pointer": {"version": 1}
}
},
"records": [
{"id": "document:document", "typeName": "document", "gridSize": 10, "name": "", "meta": {}},
{"id": "page:page1", "typeName": "page", "name": "Page 1", "index": "a1", "meta": {}}
/* shapes and arrows go here */
]
}Critical rules:
- and
document:documentrecords are ALWAYS required.page:page1 - All shapes go in the array after the page record.
records - All shapes have .
"parentId": "page:page1" - Shape IDs use format with unique suffix (e.g.,
"shape:xxx","shape:s1")."shape:a1" - values MUST start with
indexfollowed by digits or uppercase letters:"a","a1", ...,"a2","a9","aA", ...,"aB","aZ", etc."a10" - Never use ,
"b1"etc. as indices — only"c1"format is valid for shapes."a*"
json
{
"tldrawFileFormatVersion": 1,
"schema": {
"schemaVersion": 1,
"storeVersion": 4,
"recordVersions": {
"asset": {"version": 1, "subTypeKey": "type", "subTypeVersions": {"image": 2, "video": 2, "bookmark": 0}},
"camera": {"version": 1},
"document": {"version": 2},
"instance": {"version": 17},
"instance_page_state": {"version": 3},
"page": {"version": 1},
"shape": {"version": 3, "subTypeKey": "type", "subTypeVersions": {"group": 0, "embed": 4, "bookmark": 1, "image": 2, "text": 1, "draw": 1, "geo": 7, "line": 0, "note": 4, "frame": 0, "arrow": 1, "highlight": 0, "video": 1}},
"instance_presence": {"version": 4},
"pointer": {"version": 1}
}
},
"records": [
{"id": "document:document", "typeName": "document", "gridSize": 10, "name": "", "meta": {}},
{"id": "page:page1", "typeName": "page", "name": "Page 1", "index": "a1", "meta": {}}
/* 形状和箭头放在这里 */
]
}关键规则:
- 和
document:document记录是必须的。page:page1 - 所有形状都放在页面记录之后的数组中。
records - 所有形状的。
"parentId": "page:page1" - 形状ID使用格式,后缀唯一(如
"shape:xxx"、"shape:s1")。"shape:a1" - 值必须以
index开头,后跟数字或大写字母:"a"、"a1"……"a2"、"a9"、"aA"……"aB"、"aZ"等。"a10" - 绝不能使用、
"b1"等作为索引 — 只有"c1"格式对形状有效。"a*"
Geo Shape Record
几何形状记录
json
{
"id": "shape:s1",
"typeName": "shape",
"type": "geo",
"parentId": "page:page1",
"index": "a1",
"x": 100,
"y": 100,
"rotation": 0,
"isLocked": false,
"opacity": 1,
"meta": {},
"props": {
"w": 180,
"h": 60,
"geo": "rectangle",
"color": "blue",
"labelColor": "black",
"fill": "semi",
"dash": "draw",
"size": "m",
"font": "draw",
"text": "API Gateway",
"align": "middle",
"verticalAlign": "middle",
"growY": 0,
"url": ""
}
}json
{
"id": "shape:s1",
"typeName": "shape",
"type": "geo",
"parentId": "page:page1",
"index": "a1",
"x": 100,
"y": 100,
"rotation": 0,
"isLocked": false,
"opacity": 1,
"meta": {},
"props": {
"w": 180,
"h": 60,
"geo": "rectangle",
"color": "blue",
"labelColor": "black",
"fill": "semi",
"dash": "draw",
"size": "m",
"font": "draw",
"text": "API Gateway",
"align": "middle",
"verticalAlign": "middle",
"growY": 0,
"url": ""
}
}Geo Types
几何类型
| Use for |
|---|---|
| services, modules, components |
| databases, start/end nodes |
| decision points |
| external services, infrastructure |
| event hubs, message buses |
| gateways, load balancers |
| highlights, key features |
| 用途 |
|---|---|
| 服务、模块、组件 |
| 数据库、开始/结束节点 |
| 决策点 |
| 外部服务、基础设施 |
| 事件中心、消息总线 |
| 网关、负载均衡器 |
| 高亮、关键特性 |
Color Palette
调色板
| Use for |
|---|---|
| clients, core services |
| success, databases, storage |
| queues, event buses, warnings |
| external APIs, errors, alerts |
| soft alerts, secondary warnings |
| gateways, security, auth |
| decisions, caches |
| neutral, background, legacy |
| secondary services, metadata |
| titles, emphasis |
| 用途 |
|---|---|
| 客户端、核心服务 |
| 成功状态、数据库、存储 |
| 队列、事件总线、警告 |
| 外部API、错误、警报 |
| 轻度警报、次要警告 |
| 网关、安全、认证 |
| 决策、缓存 |
| 中性、背景、遗留系统 |
| 次要服务、元数据 |
| 标题、强调内容 |
Style Options
样式选项
| Property | Values | Notes |
|---|---|---|
| | |
| | |
| | |
| | |
| 属性 | 可选值 | 说明 |
|---|---|---|
| | |
| | |
| | |
| | |
Arrow Record
箭头记录
json
{
"id": "shape:a1",
"typeName": "shape",
"type": "arrow",
"parentId": "page:page1",
"index": "aG",
"x": 0,
"y": 0,
"rotation": 0,
"isLocked": false,
"opacity": 1,
"meta": {},
"props": {
"dash": "draw",
"size": "m",
"fill": "none",
"color": "black",
"labelColor": "black",
"bend": 0,
"start": {
"type": "binding",
"boundShapeId": "shape:s1",
"normalizedAnchor": {"x": 0.5, "y": 1},
"isExact": false
},
"end": {
"type": "binding",
"boundShapeId": "shape:s2",
"normalizedAnchor": {"x": 0.5, "y": 0},
"isExact": false
},
"arrowheadStart": "none",
"arrowheadEnd": "arrow",
"text": "",
"font": "draw"
}
}json
{
"id": "shape:a1",
"typeName": "shape",
"type": "arrow",
"parentId": "page:page1",
"index": "aG",
"x": 0,
"y": 0,
"rotation": 0,
"isLocked": false,
"opacity": 1,
"meta": {},
"props": {
"dash": "draw",
"size": "m",
"fill": "none",
"color": "black",
"labelColor": "black",
"bend": 0,
"start": {
"type": "binding",
"boundShapeId": "shape:s1",
"normalizedAnchor": {"x": 0.5, "y": 1},
"isExact": false
},
"end": {
"type": "binding",
"boundShapeId": "shape:s2",
"normalizedAnchor": {"x": 0.5, "y": 0},
"isExact": false
},
"arrowheadStart": "none",
"arrowheadEnd": "arrow",
"text": "",
"font": "draw"
}
}Arrow Connection Rules
箭头连接规则
- Arrow record and
xare alwaysy.0, 0 - Use with
"type": "binding"to connect to a specific shape.boundShapeId - specifies WHERE on the target shape the arrow connects (0–1 range):
normalizedAnchor- = top center
{x: 0.5, y: 0} - = bottom center
{x: 0.5, y: 1} - = left center
{x: 0, y: 0.5} - = right center
{x: 1, y: 0.5} - = center
{x: 0.5, y: 0.5}
- Add in arrow props for labeled connections.
"text": "label" - Use (or
"bend": 20) for slight curves to avoid overlap with other arrows.-20 - For dashed/dotted arrows (e.g., async flows, optional links), set or
"dash": "dashed"."dotted"
- 箭头记录的和
x始终为y。0, 0 - 使用和
"type": "binding"连接到特定形状。boundShapeId - 指定箭头连接到目标形状的位置(范围0–1):
normalizedAnchor- = 顶部中心
{x: 0.5, y: 0} - = 底部中心
{x: 0.5, y: 1} - = 左侧中心
{x: 0, y: 0.5} - = 右侧中心
{x: 1, y: 0.5} - = 中心
{x: 0.5, y: 0.5}
- 在箭头属性中添加可为连接添加标签。
"text": "label" - 使用(或
"bend": 20)实现轻微弯曲,避免与其他箭头重叠。-20 - 对于虚线/点线箭头(如异步流、可选链接),设置或
"dash": "dashed"。"dotted"
Distributing Arrows on a Shape
形状上的箭头分布
When multiple arrows connect to the same shape, assign different points to prevent stacking:
normalizedAnchor| Position | x | y | Use when |
|---|---|---|---|
| Top center | 0.5 | 0 | connecting to node above |
| Top-left | 0.25 | 0 | 2nd connection from top |
| Top-right | 0.75 | 0 | 3rd connection from top |
| Right center | 1 | 0.5 | connecting to node on right |
| Bottom center | 0.5 | 1 | connecting to node below |
| Left center | 0 | 0.5 | connecting to node on left |
Rule: if a shape has N connections on one side, space them evenly (e.g., 3 connections on bottom → x = 0.25, 0.5, 0.75).
当多个箭头连接到同一个形状时,分配不同的点以避免堆叠:
normalizedAnchor| 位置 | x | y | 适用场景 |
|---|---|---|---|
| 顶部中心 | 0.5 | 0 | 连接上方节点 |
| 左上角 | 0.25 | 0 | 顶部第2个连接 |
| 右上角 | 0.75 | 0 | 顶部第3个连接 |
| 右侧中心 | 1 | 0.5 | 连接右侧节点 |
| 底部中心 | 0.5 | 1 | 连接下方节点 |
| 左侧中心 | 0 | 0.5 | 连接左侧节点 |
规则: 若形状某一侧有N个连接,均匀分布(如底部有3个连接 → x = 0.25, 0.5, 0.75)。
Index Ordering Rules
索引排序规则
Indices control z-order (stacking). Use this sequence:
a1, a2, a3, a4, a5, a6, a7, a8, a9,
aA, aB, aC, aD, aE, aF, aG, aH, aI, aJ, aK, aL, aM,
aN, aO, aP, aQ, aR, aS, aT, aU, aV, aW, aX, aY, aZ- Geo shapes first: through
a1(or as many as needed).aF - Arrow shapes after: ,
aG, etc.aH - Every shape must have a unique index.
索引控制层级顺序(堆叠)。使用以下序列:
a1, a2, a3, a4, a5, a6, a7, a8, a9,
aA, aB, aC, aD, aE, aF, aG, aH, aI, aJ, aK, aL, aM,
aN, aO, aP, aQ, aR, aS, aT, aU, aV, aW, aX, aY, aZ- 几何形状优先:到
a1(按需增加)。aF - 箭头形状在后:、
aG等。aH - 每个形状必须有唯一的索引。
Layout Tips
布局技巧
Spacing — scale with complexity:
| Diagram complexity | Nodes | Horizontal gap | Vertical gap |
|---|---|---|---|
| Simple | ≤5 | 200px | 150px |
| Medium | 6–10 | 280px | 200px |
| Complex | >10 | 350px | 250px |
Routing corridors: between shape rows/columns, leave an extra ~80px empty corridor where arrows can route without crossing other shapes. Never place a shape in a gap that arrows need to traverse.
Grid alignment: snap all , , , values to multiples of 10 — this matches tldraw's default and makes manual editing easier.
xywhgridSize: 10General rules:
- Plan the grid before assigning x/y coordinates — sketch node positions mentally first.
- Group related nodes in the same horizontal or vertical band.
- Place heavily-connected "hub" nodes centrally so arrows radiate outward instead of crossing.
- For wide shapes (like an API Gateway spanning multiple downstream services), set to cover the full span.
w - Center-align a child node under its parent (same center x) to avoid diagonal routing.
- Event bus pattern: place the bus (hexagon) in the center of the service row, not below — services on either side reach it with short horizontal arrows (left side,
normalizedAnchor.x = 1right side), eliminating crossings.0 - Horizontal connections never cross vertical nodes in the same row; use them for peer-to-peer and publish connections.
Avoiding arrow-shape overlap:
- Before finalizing coordinates, trace each arrow path mentally — if it must cross an unrelated shape, either move the shape or use to curve around.
bend - For tree/hierarchical layouts: assign nodes to layers (rows), connect only between adjacent layers to minimize crossings.
- For star/hub layouts: place the hub center, satellites around it — arrows stay short and radial.
间距 — 随复杂度调整:
| 图表复杂度 | 节点数量 | 水平间距 | 垂直间距 |
|---|---|---|---|
| 简单 | ≤5 | 200px | 150px |
| 中等 | 6–10 | 280px | 200px |
| 复杂 | >10 | 350px | 250px |
路由通道: 在形状行/列之间,预留约80px的空白通道供箭头路由,避免穿过其他形状。绝不要在箭头需要经过的间隙放置形状。
网格对齐: 将所有、、、值对齐到10的倍数 — 这与tldraw默认的匹配,便于手动编辑。
xywhgridSize: 10通用规则:
- 分配x/y坐标前先规划网格 — 先在脑海中勾勒节点位置。
- 将相关节点分组到同一水平或垂直区域。
- 将连接密集的“枢纽”节点放在中心位置,使箭头向外辐射而非交叉。
- 对于宽形状(如覆盖多个下游服务的API网关),设置以覆盖整个跨度。
w - 子节点与父节点居中对齐(x中心相同),避免对角线路由。
- 事件总线模式:将总线(六边形)放在服务行的中心,而非下方 — 两侧的服务通过短水平箭头连接(左侧,右侧
normalizedAnchor.x = 1),消除交叉。0 - 水平连接绝不穿过同一行的垂直节点;用于对等连接和发布连接。
避免箭头与形状重叠:
- 确定坐标前,先在脑海中追踪每条箭头路径 — 若必须穿过无关形状,要么移动形状,要么使用绕开。
bend - 树形/层级布局:将节点分配到不同层(行),仅在相邻层之间连接,以最小化交叉。
- 星形/枢纽布局:将枢纽放在中心,卫星节点环绕 — 箭头短且呈放射状。
Diagram Type Presets
图表类型预设
When the user requests a specific diagram type, apply the matching preset below for shapes, colors, and layout conventions.
当用户请求特定类型的图表时,应用以下匹配的形状、颜色和布局约定。
Architecture Diagram
架构图
| Element | | | Notes |
|---|---|---|---|
| Client (web/mobile) | | | Top row, label by client type |
| Service / module | | | Mid rows, group by tier |
| Database | | | Bottom row, one per service |
| Cache | | | Sits beside its owning service |
| Queue / event bus | | | Center of service row for hub pattern |
| Gateway / load balancer | | | Above services |
| External API | | | Edge of canvas, dashed arrows in |
| Auth / security | | | Often near gateway |
Layout: TB or LR by tier count; ≥4 tiers → TB. Hub nodes centered. Spacing scales with complexity (see table above).
| 元素 | | | 说明 |
|---|---|---|---|
| 客户端(Web/移动端) | | | 顶部行,按客户端类型标注 |
| 服务/模块 | | | 中间行,按层级分组 |
| 数据库 | | | 底部行,每个服务对应一个 |
| 缓存 | | | 位于所属服务旁边 |
| 队列/事件总线 | | | 枢纽模式下放在服务行中心 |
| 网关/负载均衡器 | | | 位于服务上方 |
| 外部API | | | 画布边缘,使用虚线箭头连接 |
| 认证/安全 | | | 通常靠近网关 |
布局: 根据层级数量选择上下(TB)或左右(LR)方向;≥4层 → 上下方向。枢纽节点居中。间距随复杂度调整(见上表)。
Flowchart
流程图
| Element | | | Notes |
|---|---|---|---|
| Start / End | | | Always at top and bottom |
| Process step | | | Default action box |
| Decision | | | Always label outgoing arrows (Yes / No) |
| I/O | | | Distinguish from process via dashed border |
| Subprocess | | | Indicates a callable sub-flow |
Layout: TB, ~200px vertical gap. Decisions branch left/right, then merge back to center. Always label decision branches in the arrow's .
props.text| 元素 | | | 说明 |
|---|---|---|---|
| 开始/结束 | | | 始终位于顶部和底部 |
| 流程步骤 | | | 默认操作框 |
| 决策 | | | 必须标注 outgoing 箭头(是/否) |
| 输入/输出 | | | 通过虚线边框与流程区分 |
| 子流程 | | | 表示可调用的子流程 |
布局: 上下方向,垂直间距约200px。决策分支向左/右,然后合并回中心。必须在箭头的中标注决策分支。
props.textSequence Diagram
序列图
tldraw doesn't have native lifeline shapes. Approximate with:
| Element | | | Notes |
|---|---|---|---|
| Actor / object header | | | Top of column |
| Lifeline | | | Thin vertical line under each actor header |
| Sync message | arrow with | | Solid horizontal arrow |
| Async message | arrow with | | Dashed horizontal arrow |
| Return message | arrow with | | Grey dashed |
Layout: LR for actors (200–280px apart), TB for time. Each message is a horizontal arrow between two lifelines at increasing .
ytldraw没有原生生命线形状,可通过以下方式模拟:
| 元素 | | | 说明 |
|---|---|---|---|
| 参与者/对象标题 | | | 列顶部 |
| 生命线 | | | 每个参与者标题下方的细垂直线 |
| 同步消息 | 箭头设置 | | 实心水平箭头 |
| 异步消息 | 箭头设置 | | 虚线水平箭头 |
| 返回消息 | 箭头设置 | | 灰色虚线箭头 |
布局: 参与者左右排列(间距200–280px),时间上下推进。每条消息是两个生命线之间的水平箭头,值递增。
yML / Deep Learning Model Diagram
ML/深度学习模型图
For neural network architecture diagrams — useful for paper figures and explainers.
| Element | | | Notes |
|---|---|---|---|
| Input / Output | | | Top and bottom of stack |
| Conv / Pooling | | | Standard layer block |
| Attention / Transformer | | | Distinct color for self-attention blocks |
| RNN / LSTM / GRU | | | Recurrent layers |
| FC / Linear | | | Dense projection layers |
| Loss / Activation | | | Final loss / softmax / activation |
| Skip connection | arrow with | | Curved dashed bypass |
Tensor shape annotation: include the dimensions in on a second line. tldraw renders literally inside JSON strings, so use a real newline (the JSON encoder will write ):
props.text\n\n"text": "Conv2D\n(B, 64, 32, 32)"Layout: TB (data flows top → bottom), layers ~150px apart. Skip connections curve around the main stack.
用于神经网络架构图 — 适用于论文插图和讲解。
| 元素 | | | 说明 |
|---|---|---|---|
| 输入/输出 | | | 堆叠的顶部和底部 |
| 卷积/池化层 | | | 标准层块 |
| 注意力/Transformer层 | | | 自注意力块使用独特颜色 |
| RNN/LSTM/GRU层 | | | 循环层 |
| 全连接/线性层 | | | 密集投影层 |
| 损失/激活层 | | | 最终损失/softmax/激活层 |
| 跳跃连接 | 箭头设置 | | 弯曲虚线旁路 |
张量形状标注: 在的第二行包含维度信息。tldraw会在JSON字符串中按字面量渲染,因此使用真实换行(JSON编码器会写入):
props.text\n\n"text": "Conv2D\n(B, 64, 32, 32)"布局: 上下方向(数据从上到下流动),层间距约150px。跳跃连接绕主堆叠弯曲。
ER Diagram (ERD)
ER图(ERD)
tldraw lacks native table/row shapes. Approximate each entity as a tall rectangle with multi-line text.
| Element | | | Notes |
|---|---|---|---|
| Entity | | | Title + columns as one multi-line text label |
| Column list | embedded in | — | Mark PK with |
| Relationship | arrow with | | Both ends arrowed for many-to-many |
| Optional / weak relationship | arrow with | | Dashed for optional FK |
Label the arrow with cardinality (e.g., , ) via .
1..*0..1props.textLayout: TB or grid; entities spaced ≥300px apart to leave room for column lists.
tldraw没有原生表格/行形状,可将每个实体近似为带多行文本的高矩形。
| 元素 | | | 说明 |
|---|---|---|---|
| 实体 | | | 标题+列作为单个多行文本标签 |
| 列列表 | 嵌入在 | — | 主键前缀 |
| 关系 | 箭头设置 | | 多对多关系两端都带箭头 |
| 可选/弱关系 | 箭头设置 | | 虚线表示可选外键 |
通过箭头的标注基数(如、)。
props.text1..*0..1布局: 上下或网格布局;实体间距≥300px,为列列表留出空间。
UML Class Diagram
UML类图
| Element | | | Notes |
|---|---|---|---|
| Class | | | Title + attributes + methods as one multi-line |
| Inheritance | arrow with | | Use a single arrow shape; tldraw doesn't natively render hollow triangles, so suggest user open in editor for true UML notation if needed |
| Composition | arrow with | | Add diamond glyph in arrow text as a workaround |
| Association | arrow with | | Standard arrow |
Note: tldraw's arrowheads are limited compared to UML — for strict UML class diagrams, drawio-skill (separate skill) is a better fit. Use this preset for sketches and high-level explainers.
Layout: TB, classes ~250px apart, interfaces above implementations.
| 元素 | | | 说明 |
|---|---|---|---|
| 类 | | | 标题+属性+方法作为单个多行 |
| 继承 | 箭头设置 | | 使用单个箭头形状;tldraw不原生支持空心三角形,若需要严格UML符号,建议用户在编辑器中打开修改 |
| 组合 | 箭头设置 | | 在箭头文本中添加菱形符号作为替代方案 |
| 关联 | 箭头设置 | | 标准箭头 |
注意: tldraw的箭头样式相比UML有限 — 若需要严格的UML类图,drawio-skill(独立技能)更合适。此预设适用于草图和高层讲解。
布局: 上下方向,类间距约250px,接口位于实现上方。
Export Commands
导出命令
bash
undefinedbash
undefinedCheck CLI version
检查CLI版本
tldraw --version
tldraw --version
PNG at 2x scale (recommended) — outputs diagram.png in ./
2倍缩放PNG(推荐) — 在当前目录输出diagram.png
tldraw export diagram.tldr -f png --scale 2 -o ./
tldraw export diagram.tldr -f png --scale 2 -o ./
SVG — outputs diagram.svg in ./
SVG格式 — 在当前目录输出diagram.svg
tldraw export diagram.tldr -f svg -o ./
tldraw export diagram.tldr -f svg -o ./
Transparent background
透明背景
tldraw export diagram.tldr -f png --scale 2 --transparent -o ./
tldraw export diagram.tldr -f png --scale 2 --transparent -o ./
Dark theme
深色主题
tldraw export diagram.tldr -f png --scale 2 --dark -o ./
tldraw export diagram.tldr -f png --scale 2 --dark -o ./
Custom output directory (e.g. CI artifacts dir) — create if missing, then export there
自定义输出目录(如CI artifacts目录) — 先创建目录(若不存在),再导出
mkdir -p ./artifacts && tldraw export diagram.tldr -f png --scale 2 -o ./artifacts/
**Note:** `-o` is an output **directory**, not a file path. The output file is named after the input file (`diagram.tldr` → `diagram.png`).mkdir -p ./artifacts && tldraw export diagram.tldr -f png --scale 2 -o ./artifacts/
**注意:** `-o`指定的是输出**目录**,而非文件路径。输出文件名与输入文件名一致(`diagram.tldr` → `diagram.png`)。Auto-launch after export
导出后自动打开
Offer to open the file in the user's default tldraw viewer/editor:
.tldr| OS | Command |
|---|---|
| macOS | |
| Linux | |
| Windows | |
Or upload to https://tldraw.com (drag-and-drop the file) for browser editing.
.tldr可提议在用户默认的tldraw查看器/编辑器中打开.tldr文件:
| 操作系统 | 命令 |
|---|---|
| macOS | |
| Linux | |
| Windows | |
Common Mistakes
常见错误
| Mistake | Fix |
|---|---|
| Run |
| Check: index values must start with |
| Blank/empty export | Verify |
| Output file not found | |
| Arrow doesn't appear | Use |
| Shapes overlap | Plan a 200px+ grid before assigning x/y; scale spacing with complexity |
| Text not visible | Check |
| Index collision | All shapes must have unique |
| Shape ID clash | Use unique IDs: |
| Export fails | Ensure the |
| Multi-line label | Use a real newline character inside the JSON string ( |
| Arrow crosses shape | Use |
| Iteration loop never ends | After 5 rounds, suggest the user open |
| 错误 | 修复方法 |
|---|---|
| 运行 |
导出时出现 | 检查:索引值必须以 |
| 导出空白/空文件 | 确认 |
| 找不到输出文件 | |
| 箭头不显示 | 使用 |
| 形状重叠 | 分配x/y前规划200px+的网格;随复杂度调整间距 |
| 文本不可见 | 检查 |
| 索引冲突 | 所有形状必须有唯一的 |
| 形状ID冲突 | 使用唯一ID: |
| 导出失败 | 确保.tldr文件是有效的JSON: |
| 多行标签 | 在JSON字符串中使用真实换行符( |
| 箭头穿过形状 | 使用 |
| 迭代循环无法结束 | 5轮迭代后,建议用户在tldraw.com中打开.tldr文件进行精细调整 |
Fallback Chain
降级方案
When tools are unavailable, degrade gracefully:
| Scenario | Behavior |
|---|---|
| Generate |
| Vision unavailable for self-check | Skip self-check (step 5); proceed directly to showing user the exported PNG |
| Export fails | Validate JSON with |
当工具不可用时,优雅降级:
| 场景 | 行为 |
|---|---|
| 仅生成.tldr JSON文件;指导用户拖放到https://tldraw.com或安装CLI |
| 自我检查无视觉功能支持 | 跳过自我检查(步骤5);直接向用户展示导出的PNG |
| 导出失败 | 使用 |