How hny287/onlook works
Project type and purpose
• This is a full-stack, monorepo web application—“Onlook for Web”—that provides a visual, AI-powered code editor and preview for Next.js + TailwindCSS projects.
• It comprises:
• A Next.js front-end (apps/web/client)
• A server layer (apps/web/server and tRPC endpoints)
• Supabase serverless functions (apps/backend) for auth, database migrations, Stripe webhooks
• A Postgres database (Supabase) using Drizzle ORM (packages/db)
• Multiple shared packages (AI, parser, models, UI components, utilities)
File structure
• Top-level “apps” folder contains:
• backend/ – Supabase Deno functions + migrations
• web/ – Next.js client, Node/Bun-based server, and Electron-style preload script
• “packages” folder holds shared libraries:
• ai, parser, models, db, email, ui, utility, rpc etc.
• “docs” and “assets” for documentation and images
• Configuration files: workspace package.json, tsconfig.json, Dockerfiles, CI workflows
README
• Describes the high-level architecture:
1. On app creation → code loaded into a web container
2. Container serves code → iFrame preview
3. Editor indexes and instruments DOM ↔ code mapping
4. Edits flow bi-directionally: visual canvas ↔ code
5. AI chat tool has code access via functions
• Lists core technologies: Next.js, Supabase, Drizzle, TailwindCSS, Bun, tRPC
a. Main components
• Frontend (Next.js client in apps/web/client)
• Preload Layer (apps/web/preload)
• Editor Canvas & AI Chat UI
• API Server (apps/web/server with tRPC endpoints)
• Supabase Serverless Functions (apps/backend/functions)
• Postgres Database (Supabase)
• Web Container / Sandbox Service (to run user’s code)
• Shared packages (ai, parser, models, db, ui, utility)
• External APIs (OpenAI, Stripe)
b. Relationships & data flows
1. User’s browser ↔ Next.js client
2. Next.js client ↔ tRPC API Server (via HTTP or WebSocket)
3. tRPC API Server ↔ Supabase Postgres (via Drizzle)
4. Next.js client ↔ Supabase Functions (for realtime, auth, webhooks)
5. Editor Canvas ↔ Web Container iFrame ↔ Sandbox Service
6. AI Chat UI → RPC calls to AI package → external LLM providers
7. Stripe Webhook Function → Supabase → API Server notifications
c. Architectural patterns & principles
• Monorepo with Yarn/Bun workspaces
• Separation of concerns: client / server / serverless functions / shared libraries
• Serverless + containerized sandbox for dynamic code execution
• Micro-frontend style: Preview iframe isolated from editor UI
• tRPC for type-safe end-to-end APIs
• Drizzle ORM for type-safe database access
d. Key technologies & libraries
• Next.js (SSR, routing, API routes)
• Bun & Deno (fast JavaScript runtimes for server & functions)
• tRPC (type-safe RPC)
• Supabase (auth, Postgres, Realtime)
• Drizzle ORM (packages/db)
• AI toolkit (packages/ai)
• Parser & Instrumentation (packages/parser)
• UI Component Library (packages/ui)
• Utility & model layers (packages/utility, packages/models)
Detail
• Major sub-systems: preview iframe container, instrumentation, chat tool, migrations
• Shared package dependencies as a “Libraries” side bar or layer
• Don’t be afraid to break the system into modular zones (UI, API, Functions, Data, AI)
• The goal is maximum clarity on how data and events flow end-to-end, and how each component interacts