Generate modern whiteboard-style diagrams as .tldr JSON files and export to PNG/SVG using @kitschpatrol/tldraw-cli. tldraw produces clean hand-drawn aesthetic diagrams with rich shape libraries and smooth arrow routing — well-suited for casual or whiteboard-style visualizations.
Format: .tldr JSON
Export: PNG, SVG (via @kitschpatrol/tldraw-cli)
Aesthetic: Hand-drawn whiteboard style by default; switchable to clean fonts via font prop.
Explicit triggers: user says "diagram", "flowchart", "draw", "visualize", "whiteboard diagram", "tldraw diagram", "architecture diagram", "sketch this out".
Proactive triggers:
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.
bash
# Install tldraw-cli
npm install -g @kitschpatrol/tldraw-cli
# Verify
tldraw --version
Works identically on macOS, Windows, and Linux — no extra setup required.
Before starting, assess whether the user's request is specific enough. If key details are missing, ask 1-3 focused questions:
./artifacts/"). Don't ask if they didn't mention one.Skip clarification if the request already specifies these details or is clearly simple (e.g., "draw a flowchart of X").
Auto-update (first use per conversation) — silently keep the skill current. Check the timestamp of <this-skill-dir>/.last_update. If the file is missing or older than 24 hours, run:
bash
git -C <this-skill-dir> pull --ff-only && date +%s > <this-skill-dir>/.last_update
If the pull fails (offline, conflict, not a git checkout, etc.), ignore the error and continue normally. Do not mention the update to the user unless they ask.
Check deps — verify tldraw --version 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 .tldr JSON file. Default output dir is the user's working dir; if the user specified a path or directory (e.g. ./artifacts/), mkdir -p 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 .tldr source and exported image(s).
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:
CheckWhat to look forAuto-fix actionOverlapping shapesTwo or more shapes stacked on top of each otherShift shapes apart by ≥200pxClipped labelsText cut off at shape boundariesIncrease shape w/ h to fit labelMissing arrowsArrows that don't visually connect to shapesVerify boundShapeId matches an existing shape's idOff-canvas shapesShapes at negative coordinates or far from the main groupMove to positive coordinates near the clusterArrow-shape overlapAn arrow visually crosses through an unrelated shapeAdjust bend value or move endpoints to a different normalizedAnchor sideStacked arrowsMultiple arrows overlap each other on the same pathDistribute normalizedAnchor across the shape perimeter (use different x/y values)
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 requestJSON edit actionChange color of XFind shape by props.text matching X, update props.colorAdd a new nodeAppend a new shape record with next available index, position near related nodesRemove a nodeDelete the shape record and any arrow records bound to itMove shape XUpdate the shape's x/ y fieldsResize shape XUpdate props.w/ props.hAdd arrow from A to BAppend a new arrow record binding to A and B's shape idsChange label textUpdate props.text on the matching shape or arrowChange layout directionFull regeneration — replan the grid and rebuild
Rules:
{name}.png each iteration — do not create v1, v2, v3 files..tldr file in tldraw.com or the desktop app for fine-grained adjustments.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:
document:document and page:page1 records are ALWAYS required.records array after the page record."parentId": "page:page1"."shape:xxx" with unique suffix (e.g., "shape:s1", "shape:a1").index values MUST start with "a" followed by digits or uppercase letters: "a1", "a2", ..., "a9", "aA", "aB", ..., "aZ", "a10", etc."b1", "c1" etc. as indices — only "a*" format is valid for shapes.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 valueUse forrectangleservices, modules, componentsellipsedatabases, start/end nodesdiamonddecision pointscloudexternal services, infrastructurehexagonevent hubs, message busestrianglegateways, load balancersstarhighlights, key features
colorUse forblueclients, core servicesgreensuccess, databases, storageorangequeues, event buses, warningsredexternal APIs, errors, alertslight-redsoft alerts, secondary warningsvioletgateways, security, authyellowdecisions, cachesgreyneutral, background, legacylight-bluesecondary services, metadatablacktitles, emphasis
PropertyValuesNotesfill``semi, solid, none, pattern``semi = tinted fill (recommended)dash``draw, solid, dashed, dotted``draw = hand-drawn defaultsize``s, m, l, xl``m = defaultfont``draw, sans, serif, mono``draw = default whiteboard style
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 record x and y are always 0, 0.
Use "type": "binding" with boundShapeId to connect to a specific shape.
normalizedAnchor specifies WHERE on the target shape the arrow connects (0–1 range):
{x: 0.5, y: 0} = top center{x: 0.5, y: 1} = bottom center{x: 0, y: 0.5} = left center{x: 1, y: 0.5} = right center{x: 0.5, y: 0.5} = centerAdd "text": "label" in arrow props for labeled connections.
Use "bend": 20 (or -20) for slight curves to avoid overlap with other arrows.
For dashed/dotted arrows (e.g., async flows, optional links), set "dash": "dashed" or "dotted".
When multiple arrows connect to the same shape, assign different normalizedAnchor points to prevent stacking:
PositionxyUse whenTop center0.50connecting to node aboveTop-left0.2502nd connection from topTop-right0.7503rd connection from topRight center10.5connecting to node on rightBottom center0.51connecting to node belowLeft center00.5connecting 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).
Indices control z-order (stacking). Use this sequence:
text
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 through aF (or as many as needed).aG, aH, etc.Spacing — scale with complexity:
Diagram complexityNodesHorizontal gapVertical gapSimple≤5200px150pxMedium6–10280px200pxComplex>10350px250px
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 x, y, w, h values to multiples of 10 — this matches tldraw's default gridSize: 10 and makes manual editing easier.
General rules:
w to cover the full span.normalizedAnchor.x = 1 left side, 0 right side), eliminating crossings.Avoiding arrow-shape overlap:
bend to curve around.When the user requests a specific diagram type, apply the matching preset below for shapes, colors, and layout conventions.
Elementgeo``colorNotesClient (web/mobile)rectangle``blueTop row, label by client typeService / modulerectangle``blueMid rows, group by tierDatabaseellipse``greenBottom row, one per serviceCacheellipse``yellowSits beside its owning serviceQueue / event bushexagon``orangeCenter of service row for hub patternGateway / load balancertriangle``violetAbove servicesExternal APIcloud``redEdge of canvas, dashed arrows inAuth / securityrectangle``violetOften near gateway
Layout: TB or LR by tier count; ≥4 tiers → TB. Hub nodes centered. Spacing scales with complexity (see table above).
Elementgeo``colorNotesStart / Endellipse``greenAlways at top and bottomProcess steprectangle``blueDefault action boxDecisiondiamond``yellowAlways label outgoing arrows (Yes / No)I/Orectangle (with dash: dashed)orangeDistinguish from process via dashed borderSubprocessrectangle``violetIndicates 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.
tldraw doesn't have native lifeline shapes. Approximate with:
Elementgeo``colorNotesActor / object headerrectangle``blueTop of columnLifelinerectangle ( w: 2, fill: solid, color: grey)greyThin vertical line under each actor headerSync messagearrow with arrowheadEnd: arrow``blackSolid horizontal arrowAsync messagearrow with dash: dashed``blackDashed horizontal arrowReturn messagearrow with dash: dashed, color: grey``greyGrey dashed
Layout: LR for actors (200–280px apart), TB for time. Each message is a horizontal arrow between two lifelines at increasing y.
For neural network architecture diagrams — useful for paper figures and explainers.
Elementgeo``colorNotesInput / Outputrectangle``greenTop and bottom of stackConv / Poolingrectangle``blueStandard layer blockAttention / Transformerrectangle``violetDistinct color for self-attention blocksRNN / LSTM / GRUrectangle``yellowRecurrent layersFC / Linearrectangle``orangeDense projection layersLoss / Activationrectangle``redFinal loss / softmax / activationSkip connectionarrow with bend: 30, dash: dashed``greyCurved dashed bypass
Tensor shape annotation: include the dimensions in props.text on a second line. tldraw renders \n literally inside JSON strings, so use a real newline (the JSON encoder will write \n):
text
"text": "Conv2D\n(B, 64, 32, 32)"
Layout: TB (data flows top → bottom), layers ~150px apart. Skip connections curve around the main stack.
tldraw lacks native table/row shapes. Approximate each entity as a tall rectangle with multi-line text.
Elementgeo``colorNotesEntityrectangle ( fill: solid, color: light-blue)light-blueTitle + columns as one multi-line text labelColumn listembedded in props.text with \n between rows—Mark PK with * prefix, FK with >Relationshiparrow with arrowheadStart: arrow, arrowheadEnd: arrow``blackBoth ends arrowed for many-to-manyOptional / weak relationshiparrow with dash: dashed``greyDashed for optional FK
Label the arrow with cardinality (e.g., 1..*, 0..1) via props.text.
Layout: TB or grid; entities spaced ≥300px apart to leave room for column lists.
Elementgeo``colorNotesClassrectangle ( fill: solid, color: light-blue)light-blueTitle + attributes + methods as one multi-line textInheritancearrow with arrowheadEnd: triangle (open)blackUse a single arrow shape; tldraw doesn't natively render hollow triangles, so suggest user open in editor for true UML notation if neededCompositionarrow with bend: 0, label ◆ in text``blackAdd diamond glyph in arrow text as a workaroundAssociationarrow with arrowheadEnd: arrow``blackStandard 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.
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: -o is an output directory, not a file path. The output file is named after the input file ( diagram.tldr → diagram.png).
Offer to open the .tldr file in the user's default tldraw viewer/editor:
OSCommandmacOSopen diagram.tldrLinuxxdg-open diagram.tldrWindowsstart diagram.tldr
Or upload to https://tldraw.com (drag-and-drop the .tldr file) for browser editing.
MistakeFixtldraw command not foundRun npm install -g @kitschpatrol/tldraw-cli``invalidRecords on exportCheck: index values must start with a (e.g., a1, aA) — never b1, c1Blank/empty exportVerify document:document and page:page1 records are presentOutput file not found-o is a directory; file name matches input: tldraw export foo.tldr -o ./ → ./foo.pngArrow doesn't appearUse "type": "binding" with boundShapeId; set arrow x/ y to 0,0Shapes overlapPlan a 200px+ grid before assigning x/y; scale spacing with complexityText not visibleCheck props.text is set; if fill: "none", ensure text color contrastsIndex collisionAll shapes must have unique index valuesShape ID clashUse unique IDs: "shape:s1", "shape:s2", "shape:a1", etc.Export failsEnsure the .tldr file is valid JSON: python3 -m json.tool file.tldr > /dev/nullMulti-line labelUse a real newline character inside the JSON string ( "text": "Line1\nLine2"); tldraw respects \nArrow crosses shapeUse bend to curve around, or move endpoint to a different normalizedAnchorIteration loop never endsAfter 5 rounds, suggest the user open .tldr in tldraw.com for fine-tuning
When tools are unavailable, degrade gracefully:
ScenarioBehaviortldraw-cli missingGenerate .tldr JSON only; instruct user to drag-and-drop into https://tldraw.com or install the CLIVision unavailable for self-checkSkip self-check (step 5); proceed directly to showing user the exported PNGExport failsValidate JSON with python3 -m json.tool; deliver the .tldr file and suggest opening in tldraw.com