tldraw Whiteboard Diagrams
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.
Format: JSON
Export: PNG, SVG (via
)
Aesthetic: Hand-drawn whiteboard style by default; switchable to clean fonts via
prop.
When 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.
Prerequisites
bash
# Install tldraw-cli
npm install -g @kitschpatrol/tldraw-cli
# Verify
tldraw --version
Works identically on macOS, Windows, and Linux — no extra setup required.
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.
- 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
<this-skill-dir>/.last_update
; never mutate the skill directory without explicit user consent.
-
If
exists and is <24 h old, skip this step entirely.
-
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's
from the frontmatter. If the upstream tag is strictly newer (semver), tell the user one line and ask:
"A newer version of this skill is available: vX.Y.Z → vA.B.C. Want me to
?"
If they say yes, run
git -C <this-skill-dir> pull --ff-only
. Refresh
either way so the prompt doesn't repeat for 24 hours.
-
If upstream is the same or older, refresh
silently and continue.
-
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 — verify
succeeds; if missing, run
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 the
JSON file. Default output dir is the user's working dir; if the user specified a path or directory (e.g.
),
it first and write there. Apply the same dir choice to PNG/SVG exports in steps 4 and 7.
-
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 the
source and exported image(s).
Step 5: Self-Check
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 / to fit label |
| Missing arrows | Arrows that don't visually connect to shapes | Verify matches an existing shape's id |
| 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 value or move endpoints to a different side |
| Stacked arrows | Multiple arrows overlap each other on the same path | Distribute across the shape perimeter (use different x/y values) |
- 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.
Step 6: Review Loop
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 matching X, update |
| 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 / fields |
| 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 on the matching shape or arrow |
| 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 , , files.
- 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.
File Format
Complete .tldr Skeleton
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 records are ALWAYS required.
- All shapes go in the array after the page record.
- All shapes have .
- Shape IDs use format with unique suffix (e.g., , ).
- values MUST start with followed by digits or uppercase letters: , , ..., , , , ..., , , etc.
- Never use , etc. as indices — only format is valid for shapes.
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": ""
}
}
Geo Types
| value | 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 |
Style Options
| Property | Values | Notes |
|---|
| , , , | = tinted fill (recommended) |
| , , , | = hand-drawn default |
| , , , | = default |
| , , , | = default whiteboard style |
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"
}
}
Arrow Connection Rules
- Arrow record and are always .
- Use with to connect to a specific shape.
- specifies WHERE on the target shape the arrow connects (0–1 range):
- = top center
- = bottom center
- = left center
- = right center
- = center
- Add in arrow props for labeled connections.
- Use (or ) for slight curves to avoid overlap with other arrows.
- For dashed/dotted arrows (e.g., async flows, optional links), set or .
Distributing Arrows on a Shape
When multiple arrows connect to the same shape, assign different
points to prevent stacking:
| 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).
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 (or as many as needed).
- Arrow shapes after: , , etc.
- Every shape must have a unique index.
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.
General 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.
- 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, right side), eliminating crossings.
- 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.
- 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.
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).
Flowchart
| Element | | | Notes |
|---|
| Start / End | | | Always at top and bottom |
| Process step | | | Default action box |
| Decision | | | Always label outgoing arrows (Yes / No) |
| I/O | (with ) | | 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
.
Sequence 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
.
ML / Deep Learning Model Diagram
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
):
"text": "Conv2D\n(B, 64, 32, 32)"
Layout: TB (data flows top → bottom), layers ~150px apart. Skip connections curve around the main stack.
ER Diagram (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 with between rows | — | Mark PK with prefix, FK 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
.
Layout: TB or grid; entities spaced ≥300px apart to leave room for column lists.
UML Class Diagram
| Element | | | Notes |
|---|
| Class | (, ) | | Title + attributes + methods as one multi-line |
| Inheritance | arrow with (open) | | 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 , label in | | 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.
Export Commands
bash
# Check CLI version
tldraw --version
# PNG at 2x scale (recommended) — outputs diagram.png in ./
tldraw export diagram.tldr -f png --scale 2 -o ./
# SVG — outputs diagram.svg in ./
tldraw export diagram.tldr -f svg -o ./
# Transparent background
tldraw export diagram.tldr -f png --scale 2 --transparent -o ./
# Dark theme
tldraw export diagram.tldr -f png --scale 2 --dark -o ./
# Custom output directory (e.g. CI artifacts dir) — create if missing, then export there
mkdir -p ./artifacts && tldraw export diagram.tldr -f png --scale 2 -o ./artifacts/
Note: is an output
directory, not a file path. The output file is named after the input file (
→
).
Auto-launch after export
Offer to open the
file in the user's default tldraw viewer/editor:
| OS | Command |
|---|
| macOS | |
| Linux | |
| Windows | |
Or upload to
https://tldraw.com (drag-and-drop the
file) for browser editing.
Common Mistakes
| Mistake | Fix |
|---|
| command not found | Run npm install -g @kitschpatrol/tldraw-cli
|
| on export | Check: index values must start with (e.g., , ) — never , |
| Blank/empty export | Verify and records are present |
| Output file not found | is a directory; file name matches input: tldraw export foo.tldr -o ./
→ |
| Arrow doesn't appear | Use with ; set arrow / to |
| Shapes overlap | Plan a 200px+ grid before assigning x/y; scale spacing with complexity |
| Text not visible | Check is set; if , ensure text color contrasts |
| Index collision | All shapes must have unique values |
| Shape ID clash | Use unique IDs: , , , etc. |
| Export fails | Ensure the file is valid JSON: python3 -m json.tool file.tldr > /dev/null
|
| Multi-line label | Use a real newline character inside the JSON string (); tldraw respects |
| Arrow crosses shape | Use to curve around, or move endpoint to a different |
| Iteration loop never ends | After 5 rounds, suggest the user open in tldraw.com for fine-tuning |
Fallback Chain
When tools are unavailable, degrade gracefully:
| Scenario | Behavior |
|---|
| missing | Generate JSON only; instruct user to drag-and-drop into https://tldraw.com or install the CLI |
| Vision unavailable for self-check | Skip self-check (step 5); proceed directly to showing user the exported PNG |
| Export fails | Validate JSON with ; deliver the file and suggest opening in tldraw.com |