"Whiteboard Architect" is a production-grade full-stack application that transforms static whiteboard sketches (images) into working SQL scripts and database visualizations. Users upload an image of a database schema, and the system uses Gemini 1.5 Flash to extract the schema, generating both an interactive diagram (React Flow) and optimized PostgreSQL DDL scripts (Monaco Editor). The UI follows a premium "Brutalist" design system with smooth Framer Motion animations and glassmorphism.
- Framework: Next.js 15 (App Router)
- Language: TypeScript
- Runtime: Bun (strictly for package management and script running)
- Styling: Tailwind CSS, Lucide React (Icons)
- Key Libraries:
reactflow(Schema Visualization)@monaco-editor/react(SQL Display/Editing)framer-motion(Advanced Animations)
- Framework: FastAPI
- Security: SlowAPI (Dual-layer Rate Limiting: IP + Global), CORS (Whitelist), Security Headers (OWASP)
- AI Model: Google Generative AI (Gemini 1.5 Flash)
- Validation: Pydantic (Strict mode with
extra="forbid") - Sanitization: Bleach
/
├── backend/ # FastAPI Backend
│ ├── main.py # Entry point (Rate limiting, Security, Routes)
│ ├── models.py # Strict Pydantic Models (Schema definitions)
│ ├── services.py # Gemini Logic & Graph Transformation
│ ├── requirements.txt # Dependencies (slowapi, bleach, etc.)
│ └── .env # GEMINI_API_KEY
├── frontend/ # Next.js Frontend
│ ├── src/app/ # App Router (Home, Whiteboard, Settings)
│ ├── src/app/api/ # Server-side proxy Route Handlers (reads BACKEND_API_URL at runtime)
│ │ ├── generate/ # Proxies POST /api/generate → FastAPI
│ │ ├── generate-data/ # Proxies POST /api/generate-data → FastAPI
│ │ └── deploy/ # Proxies /deploy/supabase, /deploy/firebase → FastAPI
│ ├── src/components/ # UI Components (DatabaseNode, Stitch System)
│ ├── .env.local # BACKEND_API_URL (private) or NEXT_PUBLIC_API_URL (legacy)
│ └── tailwind.config.ts # Design Tokens
└── context.md # Single Source of Truth
- Project Foundation
- Create
context.md - Initialize Next.js & FastAPI
- Implement File Headers for all core files
- Create
- Secure Backend
-
/api/generateEndpoint with Multi-part upload - Dual-layer Rate Limiting (5 req/min for AI endpoints)
- Strict Schema Validation (Pydantic
extra="forbid") - OWASP Security Headers & CORS Lockdown
-
- Premium Frontend
- Whiteboard / SQL Generator (
/whiteboard) - Interactive React Flow Diagram with Custom Nodes
- Monaco Editor with JetBrains Mono font
- Global Layout & Navigation (Navbar, Sidebar)
- Home (Landing Page) with Premium Animations & Mesh Background
- Simplified Settings Page
- Environment-aware API requests
- Smooth Error Notifications (AnimatePresence)
- Fixed port collision and environment loading issues
- Persistent "Save Schema" and "Schema History" system (localStorage)
- Multi-Dialect Support (PostgreSQL, MySQL, SQLite, MSSQL)
- Mock Data Generation (AI-powered INSERT statements)
- Whiteboard / SQL Generator (
cd backend
# 1. Create .env: GEMINI_API_KEY=your_key, ALLOWED_ORIGINS=http://localhost:3000
# 2. Install deps
pip install -r requirements.txt
# 3. Start server
python main.pycd frontend
# 1. Create .env.local: NEXT_PUBLIC_API_URL=http://localhost:8000
# 2. Install deps
bun install
# 3. Start dev server
bun run dev- Push Code: Push the
backend/folder to a GitHub repository. - New Project: In Railway, select "Deploy from GitHub repo".
- Root Directory: Set Root Directory to
/backend. - Environment Variables:
GEMINI_API_KEY: Your Gemini API Key.ALLOWED_ORIGINS:https://your-vercel-app.vercel.app,http://localhost:3000(Add frontend URL after deployment).PORT:8000(Railway sets this automatically, but good to be aware).
- Start Command: Railway automatically detects
Procfile(uvicorn main:app --host 0.0.0.0 --port $PORT).
- Import Project: Import the same GitHub repo in Vercel.
- Root Directory: Set Root Directory to
/frontend. - Environment Variables (CRITICAL):
BACKEND_API_URL: The https URL of your Railway backend (e.g.,https://web-production-1234.up.railway.app).- This is a private server-side variable — do NOT prefix with
NEXT_PUBLIC_. - The Next.js API Route Handlers in
src/app/api/read this at runtime (not build time).
- Deploy: Click Deploy.
- Update
ALLOWED_ORIGINSin Railway with the final Vercel URL. - Redeploy Backend to apply changes.
Column:name (str),type (str),is_primary_key (bool),is_foreign_key (bool),foreign_key_target (str?)TableModel:name (str),columns (List[Column])Relationship:source_table (str),target_table (str),type (1:1|1:N|N:M),source_column (str),target_column (str)SchemaExtraction:tables (List[TableModel]),relationships (List[Relationship]),sql_code (str)
DatabaseNode: Custom node rendering table name and column list.Edge: Directed animated edge representing relationships.
- Request: Multipart/Form-Data (Image File)
- Rate Limit: 5 requests per minute
- Response:
{ "sql_code": "CREATE TABLE...", "graph_data": { "nodes": [...], "edges": [...] } }
- Rate Limiting: Managed via
SlowAPI. - Validation: Every field is length-limited and strictly typed.
- Headers:
X-Frame-Options,X-Content-Type-Options,HSTSenforced. - Privacy: No user data or images are stored on disk; processed in-memory.
- Fix CORS preflight error handling with Railway backend.
- Resilient API Url fetching
trimpadding error on Vercel deployment. - Root-cause fix: 404 on /api/generate in production — replaced
next.config.tsrewrites (which bakedNEXT_PUBLIC_API_URLat build time, silently falling back tolocalhost:8000) with server-side Next.js Route Handlers insrc/app/api/*/route.tsthat readBACKEND_API_URLat request time. - Implement robust error handling for edge cases in graph transformation.
- Add unit tests for
services.pytransformation logic. - Implement local schema persistence (Saved via localStorage).
- Implement database-backed user authentication for saving schemas.
- Optimize React Flow re-rendering for large diagrams.
- Add support for MySQL and SQLite DDL generation.
- Refactor relative imports to absolute imports.