Turn a Hand-Drawn UI into Working Code with tldraw
Sketch a screen on an infinite canvas and have a vision model return a live, working version of it.
Run this workflow
CI-verified, 5/5 fixtures passing.
Intended Use
React developers who want to scaffold a UI by sketching it on a canvas and getting a working draft back, instead of starting from a blank editor.
Not for
- Shipping in a commercial product without a paid tldraw license, the free tier adds a watermark
- Pixel-perfect/production code, 'make real' returns a working draft, not final UI
- Non-React stacks, the SDK is React-first
The Stack
Tested Against
tldraw@3.xnode@20.xreact@19.xSide effects & data flow
- Network
- vision-model API, only in the non-CI 'make real' step
- Writes
- ./src/App.tsx, ./canvas.json
- Credentials
- vision-model API key, for the make-real step only
Data privacy
- your chosen vision-model API (e.g. OpenAI / Anthropic) ← the canvas image + the shape text of your sketch (retention: per that provider's API data policy)
Prerequisites
- A React app (Vite or Next.js)
- Node 20.x + npm
- `npm install tldraw` (plus `import 'tldraw/tldraw.css'`)
- A vision-model API key for the make-real step, e.g. OpenAI or Anthropic
- Commercial use: a paid tldraw license key, check the terms before you ship
Steps
- 1
Check your toolchain
Make sure Node and npm are installed, that's all the deterministic setup needs. (The make-real step later also needs a vision-model API key, but nothing here does.)
for bin in node npm grep sed; do command -v "$bin" >/dev/null 2>&1 || { echo "MISSING required: $bin"; exit 1; } done echo "preflight OK, node $(node -v)" - 2
Drop the canvas into your React app
After `npm install tldraw`, a five-line component gives you a full infinite canvas. This writes that App.tsx and confirms the import and stylesheet are wired correctly.
mkdir -p src cat > src/App.tsx <<'EOF' import { Tldraw } from 'tldraw' import 'tldraw/tldraw.css' export default function App() { return ( <div style={{ position: 'fixed', inset: 0 }}> <Tldraw /> </div> ) } EOF if grep -q "import { Tldraw } from 'tldraw'" src/App.tsx && grep -q "tldraw/tldraw.css" src/App.tsx; then echo "tldraw canvas wired: src/App.tsx" else echo "WIRING FAILED"; exit 1 fi - 3
Turn a sketch into a model prompt
This is the deterministic heart of 'make real': your canvas is just a tree of shapes, and before any model sees it those shapes get serialized into a prompt. Here we take a sample three-shape sketch, Email, Password, Sign in, and build the exact prompt the vision model would receive. No API key needed.
cat > canvas.json <<'EOF' { "shapes": [ { "type": "geo", "props": { "geo": "rectangle", "text": "Email" } }, { "type": "geo", "props": { "geo": "rectangle", "text": "Password" } }, { "type": "geo", "props": { "geo": "button", "text": "Sign in" } } ] } EOF cat > make-prompt.js <<'EOF' const fs = require('fs'); const doc = JSON.parse(fs.readFileSync('canvas.json', 'utf8')); const lines = doc.shapes.map(function (s) { return '- ' + s.props.text + ' (' + s.props.geo + ')'; }); console.log('Build a working HTML UI containing:\n' + lines.join('\n')); EOF node make-prompt.js - 4
Make it real (the vision-model step, not checked by CI)
Send the canvas image plus that prompt to a vision model and render what comes back as live code. This is the magic, but it's non-deterministic and needs an API key, so CI doesn't run it, the verified badge covers only the toolchain check, the canvas wiring, and the prompt build above. This step's proof is the saved transcript.
Eval, 5 fixtures
Last passed: verified 10d agopreflight-okcontainstimeout 15s · max $0Expected:
preflight OKcanvas-wiredcontainstimeout 15s · max $0Expected:
tldraw canvas wiredprompt-headercontainstimeout 15s · max $0Expected:
Build a working HTML UI containing:prompt-buttoncontainstimeout 15s · max $0Expected:
Sign in (button)clean-exitexit_codetimeout 15s · max $0Expected:
0
Results
tldraw's 'make real' went viral; the SDK is at ~47K stars and active.