How ratna-babu/ai-website-builder works
1. Overall shape
- This is a Next.js App Router application for an AI website builder.
- The architecture splits cleanly into:
- a UI layer in app/ and components/
- server API routes in app/api/
- a real-time persistence layer in convex/
- shared prompt/model configuration in data/ and configs/
2. Primary user surfaces
- app/page.js is the public landing page, backed by components like Hero and Header.
- app/(main)/workspace/[id]/page.jsx is the main product workspace, keyed by a workspace ID.
- The workspace page is the central “builder” surface where chat, generated code, and preview likely coexist.
3. Workspace as the core domain
- The repository is organized around a workspace entity rather than a generic document.
- convex/schema.js and convex/workspace.js define and operate on the persistent workspace data.
- The dynamic route [id] indicates the frontend loads and updates a specific workspace record through Convex.
4. AI interaction boundary
- All AI-facing logic is isolated behind Next.js API routes:
- app/api/ai-chat/route.jsx
- app/api/enhance-prompt/route.jsx
- app/api/gen-ai-code/route.jsx
- This boundary keeps Gemini-specific request/response handling out of the React component tree.
- The README and naming strongly suggest these routes call Gemini Flash 2.0 for chat, prompt refinement, and code generation.
5. Frontend composition
- components/custom/ChatView.jsx and components/custom/CodeView.jsx are the two main product views inside the builder.
- components/custom/Header.jsx and components/custom/Hero.jsx serve the marketing/landing surface.
- components/ui/button.jsx and components.json indicate a reusable UI component system layered on top of Tailwind.
6. Client state and cross-component messaging
- context/MessagesContext.js is the main client-side state container for chat or generation messages.
- app/provider.jsx and app/ConvexClientProvider.jsx are top-level wrappers that likely initialize shared providers for the app.
- This suggests chat state is maintained in React context while durable workspace state lives in Convex.
7. Convex as the persistence and realtime layer
- Convex is the backend database/function boundary, not just storage.
- convex/_generated/* shows generated client/server bindings are used by the app.
- convex/workspace.js likely exposes CRUD or streaming-style operations for workspace data, and convex/schema.js defines the shape of persisted records.
- The README’s emphasis on “real-time updates” points to Convex driving live workspace synchronization.
8. Prompt and model configuration
- configs/AiModel.jsx centralizes model selection or AI provider settings.
- data/Prompt.jsx and data/Lookup.jsx likely contain prompt templates, prompt enrichment rules, or mapping logic used by the AI routes.
- This separates “what to ask the model” from the route handlers that send the request.
9. Rendering and styling boundary
- The app uses Tailwind CSS for presentation, with app/globals.css, tailwind.config.mjs, and postcss.config.mjs as the styling foundation.
- app/layout.js is the root shell that applies global providers and styling.
- lib/utils.js is the shared utility boundary for small cross-cutting helpers, likely used by UI components.
10. End-to-end data flow
- A user enters a prompt in the workspace UI.
- The prompt is stored/managed in client state via MessagesContext.
- The client calls one of the API routes for prompt enhancement, chat, or code generation.
- The server route forwards the request to Gemini and returns AI output.
- Generated workspace/code data is persisted or updated through Convex, then reflected back into the UI through the workspace page and provider layer.
11. Important architectural boundary to diagram
- Draw a clear separation between:
- browser/UI: app/, components/, context/
- serverless AI endpoints: app/api/*
- backend state: convex/
- shared prompt/config assets: data/, configs/
- The workspace page is the center node connecting all four.
12. Operational/deployment note
- The README indicates deployment on Vercel and runtime dependency on GEMINI_API_KEY plus NEXT_PUBLIC_CONVEX_URL.
- The live preview may be slow or time out because code generation can exceed Vercel function limits, which is relevant when diagramming the server boundary and latency-sensitive path.
Main entry points: page.jsx Workspace · ChatView.jsx Chat view · route.jsx Prompt enhance · CodeView.jsx Code view
Components 21
UI layer
App Router pages and React views for landing and workspace
- Root shell · App-wide layout and provider composition
app/layout.js - Landing page · Public marketing entry point
app/page.js - Workspace · Main builder surface for a workspace ID
app/(main)/workspace/[id]/page.jsx - App provider · Top-level client provider composition
app/provider.jsx - Convex provider · Initializes Convex client access
app/ConvexClientProvider.jsx - Header · Top navigation for landing pages
components/custom/Header.jsx - Hero · Landing page hero section
components/custom/Hero.jsx - Chat view · Chat and prompt interaction surface
components/custom/ChatView.jsx - Code view · Generated code and preview surface
components/custom/CodeView.jsx - Messages state · Client-side message and generation state
context/MessagesContext.js
AI endpoints
Serverless routes that broker model calls
- AI chat · Chat completion endpoint
app/api/ai-chat/route.jsx - Prompt enhance · Prompt refinement endpoint
app/api/enhance-prompt/route.jsx - Code gen · AI code generation endpoint
app/api/gen-ai-code/route.jsx
Persistence
Convex schema and workspace operations
- Workspace schema · Persistent data model for workspaces
convex/schema.js - Workspace ops · Workspace CRUD and realtime operations
convex/workspace.js
Shared config
Prompt templates and model settings
- Model config · Central model/provider selection
configs/AiModel.jsx - Prompt data · Prompt text and generation instructions
data/Prompt.jsx - Lookup data · Prompt enrichment or lookup support data
data/Lookup.jsx
Style system
Global styling and reusable UI primitives
- Global styles · App-wide styling foundation
app/globals.css - Button UI · Reusable button component
components/ui/button.jsx - Utils · Shared utility helpers
lib/utils.js
Connections 24
- Root shell → App provider: wraps · Composes app-wide client providers
- Root shell → Global styles: loads · Applies global styling
- App provider → Convex provider: includes · Installs Convex client access
- Landing page → Header: renders · Landing page uses the header
- Landing page → Hero: renders · Landing page uses the hero section
- Workspace → Chat view: composes · Builder surface includes chat
- Workspace → Code view: composes · Builder surface includes code preview
- Workspace → Messages state: uses · Workspace reads and updates client message state
- Workspace → Workspace ops: syncs · Loads and persists workspace data
- Chat view → Messages state: reads/writes · Chat interaction is mediated by context state
- Code view → Messages state: reads · Code view reflects generation state
- Chat view → AI chat: calls · Sends chat prompts to the server
- Chat view → Prompt enhance: calls · Requests prompt refinement
- Code view → Code gen: calls · Requests AI code generation
- AI chat → Model config: configures · Uses shared model settings
- Prompt enhance → Model config: configures · Uses shared model settings
- Code gen → Model config: configures · Uses shared model settings
- AI chat → Prompt data: uses · Applies prompt templates
- Prompt enhance → Prompt data: uses · Applies prompt templates
- Code gen → Prompt data: uses · Applies prompt templates
- Prompt enhance → Lookup data: uses · Enrichment and lookup support data
- Workspace schema → Workspace ops: shapes · Workspace functions operate on the schema
- Workspace ops → Convex provider: exposes · Client talks to Convex through generated bindings
- Button UI → Utils: uses · UI primitive depends on shared helpers