# sawyerhood/draw-a-ui architecture

> Architecture diagram of the GitHub repository sawyerhood/draw-a-ui, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/sawyerhood/draw-a-ui
- Repository: https://github.com/sawyerhood/draw-a-ui

## Overview

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: [`app/page.tsx`](https://github.com/sawyerhood/draw-a-ui/blob/main/app/page.tsx) (Export workflow), [`lib/getSvgAsImage.ts`](https://github.com/sawyerhood/draw-a-ui/blob/main/lib/getSvgAsImage.ts) (SVG rasterizer), [`app/api/toHtml/route.ts`](https://github.com/sawyerhood/draw-a-ui/blob/main/app/api/toHtml/route.ts) (HTML conversion route), [`components/PreviewModal.tsx`](https://github.com/sawyerhood/draw-a-ui/blob/main/components/PreviewModal.tsx) (Preview and code modal)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_drawing["Wireframe drawing"]
  node_canvas["Drawing canvas<br/>[page.tsx]"]
  node_export["Export workflow<br/>[page.tsx]"]
end

subgraph group_conversion["Image conversion"]
  node_svg_image["SVG rasterizer<br/>[getSvgAsImage.ts]"]
  node_canvas_limits["Canvas limits"]
  node_png_helpers["PNG metadata<br/>[png.ts]"]
  node_base64["Blob encoder<br/>[blobToBase64.ts]"]
end

subgraph group_generation["HTML generation"]
  node_api["HTML conversion route<br/>[route.ts]"]
  node_openai["OpenAI vision API"]
  node_preview["Preview and code modal<br/>[PreviewModal.tsx]"]
end

node_user(("User"))

node_user -->|"draws wireframe"| node_canvas
node_user -->|"requests export"| node_export
node_canvas -->|"provides canvas SVG"| node_export
node_export -->|"rasterizes SVG"| node_svg_image
node_svg_image -->|"checks dimensions"| node_canvas_limits
node_svg_image -->|"sets PNG metadata"| node_png_helpers
node_export -->|"encodes PNG"| node_base64
node_export -->|"posts image"| node_api
node_api -->|"requests HTML"| node_openai
node_api -->|"returns completion"| node_export
node_export -->|"displays HTML"| node_preview
node_user -->|"views or closes"| node_preview

click node_canvas "https://github.com/sawyerhood/draw-a-ui/blob/main/app/page.tsx"
click node_export "https://github.com/sawyerhood/draw-a-ui/blob/main/app/page.tsx"
click node_svg_image "https://github.com/sawyerhood/draw-a-ui/blob/main/lib/getSvgAsImage.ts"
click node_canvas_limits "https://github.com/sawyerhood/draw-a-ui/blob/main/lib/getBrowserCanvasMaxSize.ts"
click node_png_helpers "https://github.com/sawyerhood/draw-a-ui/blob/main/lib/png.ts"
click node_base64 "https://github.com/sawyerhood/draw-a-ui/blob/main/lib/blobToBase64.ts"
click node_api "https://github.com/sawyerhood/draw-a-ui/blob/main/app/api/toHtml/route.ts"
click node_preview "https://github.com/sawyerhood/draw-a-ui/blob/main/components/PreviewModal.tsx"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_canvas,node_export,node_user toneBlue
class node_svg_image,node_canvas_limits,node_png_helpers,node_base64 toneAmber
class node_api,node_openai,node_preview toneMint
```

## Components

### Wireframe drawing

- [Drawing canvas](https://github.com/sawyerhood/draw-a-ui/blob/main/app/page.tsx): `app/page.tsx`
- [Export workflow](https://github.com/sawyerhood/draw-a-ui/blob/main/app/page.tsx): `app/page.tsx`

### Image conversion

- [SVG rasterizer](https://github.com/sawyerhood/draw-a-ui/blob/main/lib/getSvgAsImage.ts): `lib/getSvgAsImage.ts`
- [Canvas limits](https://github.com/sawyerhood/draw-a-ui/blob/main/lib/getBrowserCanvasMaxSize.ts): `lib/getBrowserCanvasMaxSize.ts`
- [PNG metadata](https://github.com/sawyerhood/draw-a-ui/blob/main/lib/png.ts): `lib/png.ts`
- [Blob encoder](https://github.com/sawyerhood/draw-a-ui/blob/main/lib/blobToBase64.ts): `lib/blobToBase64.ts`

### HTML generation

- [HTML conversion route](https://github.com/sawyerhood/draw-a-ui/blob/main/app/api/toHtml/route.ts): `app/api/toHtml/route.ts`
- **OpenAI vision API**
- [Preview and code modal](https://github.com/sawyerhood/draw-a-ui/blob/main/components/PreviewModal.tsx): `components/PreviewModal.tsx`

### Other components

- **User**

## Connections

- User → Drawing canvas: draws wireframe (evidence: `README.md`)
- User → Export workflow: requests export (evidence: `app/page.tsx`)
- Drawing canvas → Export workflow: provides canvas SVG (evidence: `app/page.tsx`)
- Export workflow → SVG rasterizer: rasterizes SVG (evidence: `app/page.tsx`)
- SVG rasterizer → Canvas limits: checks dimensions (evidence: `lib/getSvgAsImage.ts`)
- SVG rasterizer → PNG metadata: sets PNG metadata (evidence: `lib/getSvgAsImage.ts`)
- Export workflow → Blob encoder: encodes PNG (evidence: `app/page.tsx`)
- Export workflow → HTML conversion route: posts image (evidence: `app/page.tsx`)
- HTML conversion route → OpenAI vision API: requests HTML (evidence: `app/api/toHtml/route.ts`)
- HTML conversion route → Export workflow: returns completion (evidence: `app/page.tsx`)
- Export workflow → Preview and code modal: displays HTML (evidence: `app/page.tsx`)
- User → Preview and code modal: views or closes (evidence: `components/PreviewModal.tsx`)
