How sawyerhood/draw-a-ui works
draw-a-ui turns a wireframe drawn in a tldraw canvas into generated Tailwind HTML. The user exports the current page; the client rasterizes its SVG, encodes the PNG, and posts it to the conversion route. That route sends the image to OpenAI and returns the completion, which the client extracts and displays in a preview/code modal. Canvas-size detection and PNG metadata handling support rasterization. Other README capabilities are limited to this workflow; links reflect the excerpts and documented behavior.
Main entry points: page.tsx Export workflow · getSvgAsImage.ts SVG rasterizer · route.ts HTML conversion route · PreviewModal.tsx Preview and code modal
Components 10
Wireframe drawing
- Drawing canvas
app/page.tsx - Export workflow
app/page.tsx
Image conversion
- SVG rasterizer
lib/getSvgAsImage.ts - Canvas limits
lib/getBrowserCanvasMaxSize.ts - PNG metadata
lib/png.ts - Blob encoder
lib/blobToBase64.ts
HTML generation
- HTML conversion route
app/api/toHtml/route.ts - OpenAI vision API
- Preview and code modal
components/PreviewModal.tsx
Other components
- User
Connections 12
- User → Drawing canvas: draws wireframe
README.md - User → Export workflow: requests export
app/page.tsx - Drawing canvas → Export workflow: provides canvas SVG
app/page.tsx - Export workflow → SVG rasterizer: rasterizes SVG
app/page.tsx - SVG rasterizer → Canvas limits: checks dimensions
lib/getSvgAsImage.ts - SVG rasterizer → PNG metadata: sets PNG metadata
lib/getSvgAsImage.ts - Export workflow → Blob encoder: encodes PNG
app/page.tsx - Export workflow → HTML conversion route: posts image
app/page.tsx - HTML conversion route → OpenAI vision API: requests HTML
app/api/toHtml/route.ts - HTML conversion route → Export workflow: returns completion
app/page.tsx - Export workflow → Preview and code modal: displays HTML
app/page.tsx - User → Preview and code modal: views or closes
components/PreviewModal.tsx