This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.
pnpm install # Install dependencies
pnpm dev # Run development server (localhost:3000)
pnpm build # Build for production
pnpm lint # Run ESLintDrawit is an AI-powered collaborative whiteboard built with Next.js 16 (App Router), React 19, Vercel AI SDK v5, and Supabase.
- Canvas State - Zustand store (
lib/store.ts) manageselements(shapes) andconnections(smart connectors) - Authentication - Supabase Auth with Google OAuth (
components/auth-provider.tsx) - Persistence - Supabase database for diagrams and chat history (
lib/services/) - AI Integration - Dual-mode AI execution:
- Streaming Chat -
/api/ai-chatwith client-side tool execution - Background Jobs - Trigger.dev tasks for complex diagrams (
src/trigger/)
- Streaming Chat -
CanvasElement- All drawable shapes (rectangle, ellipse, diamond, arrow, line, freedraw, text, image)SmartConnection- Connectors between elements with routing types (bezier, smoothstep, straight)AppState- Current tool, selection, and default styling properties
Drawit uses a custom SVG canvas, NOT React Flow for canvas management.
What React Flow IS used for:
- Connection path rendering only (
components/editor/smart-connector-layer.tsx) - Invisible nodes are created at element positions
- React Flow's edge algorithms (bezier, smoothstep) calculate connection paths
- The paths are rendered, but React Flow does NOT manage the actual canvas elements
What React Flow IS NOT used for:
- Node/element creation or management
- Canvas state (managed by Zustand)
- AI diagram generation (all tools create SVG
CanvasElementobjects)
The Workflow Page (/app/workflow):
- Contains a React Flow-based workflow canvas (currently disabled)
- This is a separate experiment, NOT integrated with the AI system
- The
createWorkflowAI tool creates SVG shapes on the main canvas, not React Flow nodes - See documentation in
app/workflow/page.tsxfor details
Key Files:
components/editor/canvas.tsx- Main 2330-line custom SVG canvas (where AI creates diagrams)components/editor/smart-connector-layer.tsx- React Flow for connection paths onlylib/ai-chat/tool-handlers/- All handlers createCanvasElementobjects (SVG)app/workflow/page.tsx- Disabled React Flow canvas (different system)
Centralized tool definitions using Zod schemas:
canvas-tools.ts- getCanvasState, clearCanvas, analyzeDiagram, beautifyDiagramdiagram-tools.ts- createFlowchart, createWorkflow, createMindMap, createOrgChart, createERDiagram, createNetworkDiagram, createMoleculeshape-tools.ts- createShape, updateShape, getShapeInfo, placeImage, previewDiagramstyle-tools.ts- updateStylesschemas.ts- Shared Zod schemas for all tools
Client-side execution functions that mutate the Zustand store.
The getSystemPrompt() function uses a layered contract architecture:
| Module | Purpose |
|---|---|
| ROLE & MISSION | Agent identity and primary objective |
| CANVAS STATE | Dynamic context injection (center, dimensions, theme) |
| TOOL REGISTRY | Decision matrix with "Use When" guidance for all 15 tools |
| TOOL GOVERNANCE | Mandatory workflow, color rules, connection rules, multi-step limits |
| NODE TYPES REFERENCE | Quick lookup for valid enum values |
| COMMUNICATION CONTRACT | Response structure + tone guidelines |
| IMAGE RECREATION | Step-by-step protocol for recreating uploaded images |
| COMMON PATTERNS | User intent → tool sequence mapping |
| HARD CONSTRAINTS | Inviolable rules (always connect, always check state, etc.) |
For complex diagrams that need longer execution time:
src/trigger/ai-diagram.ts- Background task with server-side toolsapp/api/ai-diagram/route.ts- Trigger endpointhooks/use-ai-diagram.ts- React hook for triggering/pollingcomponents/ai-quick-create.tsx- Quick Create UI (wand button)
components/editor/canvas.tsx- Main SVG-based canvas with shape rendering, selection, pan/zoomcomponents/ai-chat-panel.tsx- Chat interface using@ai-sdk/reactuseChat hookcomponents/ai-quick-create.tsx- Quick Create panel for Trigger.dev background jobscomponents/editor/smart-connector-layer.tsx- Connection rendering with automatic routingcomponents/auth-provider.tsx- Authentication context providercomponents/diagram-picker.tsx- Diagram selection and managementcomponents/chat-history-sheet.tsx- Chat session historycomponents/ui/- shadcn/ui components
diagram-service.ts- CRUD operations for diagrams in Supabasechat-service.ts- Chat session and message management in Supabaseimage-service.ts- Upload images to Supabase Storage, returns public URLs for AI
src/trigger/cleanup-temp-images.ts- Daily cleanup of expired temp images (runs at 3 AM UTC)
# Required
AI_GATEWAY_API_KEY= # Vercel AI Gateway API key
NEXT_PUBLIC_SUPABASE_URL= # Supabase project URL
NEXT_PUBLIC_SUPABASE_ANON_KEY= # Supabase anon key
SUPABASE_SERVICE_ROLE_KEY= # Supabase service role key (server-side)
# Optional
TRIGGER_SECRET_KEY= # Trigger.dev secret for background jobs@/* maps to project root (configured in tsconfig.json)
See supabase/migrations/ for full schema:
001_initial_schema.sql:
profiles- User profiles (extends Supabase auth)diagrams- User diagrams with elements and connectionschat_sessions- AI chat sessionschat_messages- Individual chat messages
002_temp_images_storage.sql:
temp-imagesStorage bucket - For AI chat image uploadstemp_imagestable - Tracks uploads with 24h expiry for cleanup