Lovable AI is an AI-powered web application generator and iterative development platform. It enables users to describe web applications using natural language, automatically provisions isolated cloud sandbox environments, streams live project creation, provides an embedded code editor, and supports interactive human-in-the-loop requirement gathering.
- Natural Language Application Generation: Transform text prompts into functional Next.js applications using advanced LLM reasoning.
- Isolated Cloud Sandboxes: Dynamically provision and connect to E2B containerized environments for secure file execution and live HTTP previews.
- Interactive Requirement Gathering: Built-in human-in-the-loop tool (
askUser) allowing the AI agent to ask structured clarifying questions (single-choice, multiple-choice, or freeform text) before and during construction. - Real-Time Server-Sent Events (SSE): Live streaming of agent status, preview URLs, interactive prompts, and completion events.
- Integrated Monaco Code Browser: Interactive file explorer and full syntax-highlighted code viewer with breadcrumbs, file tabs, and custom dark mode themes.
- Live App Preview: Embedded responsive iFrame preview pointing directly to the sandbox development server port.
- User Management & Persistence: Full authentication integration with Clerk and persistent relational database storage via Prisma and PostgreSQL.
+-----------------------------------------------------------------------+
| NEXT.JS FRONTEND |
| +-------------------+ +--------------------+ +----------------+ |
| | Prompt Input UI | | Monaco Code Editor | | Live App Preview| |
| +-------------------+ +--------------------+ +----------------+ |
| | ^ ^ |
| | User Prompt | Fetch Code Files | Live URL |
| v | | |
+------------|----------------------|------------------------|----------+
| REST / SSE | REST API | iFrame
v | |
+-----------------------------------|------------------------|----------+
| EXPRESS SERVER |
| +-------------------+ +--------------------+ |
| | Clerk Auth Gate | | AI Orchestrator | |
| +-------------------+ +--------------------+ |
| | |
| +---------------------------+------------------------+ |
| | | | |
| v v v |
| +-----------+ +---------------+ +--------------+ |
| | Prisma DB | | LLMs | | E2B Sandbox | |
| | Postgres | | (Groq/Google) | | Containers | |
| +-----------+ +---------------+ +--------------+ |
+-----------------------------------------------------------------------+
- Framework: Next.js 16 (App Router), React 19, TypeScript
- Styling: Tailwind CSS v4, Radix UI primitives, Lucide React
- Code Editor:
@monaco-editor/react(Monaco Editor integration) - Authentication:
@clerk/nextjs - Layout & UI:
react-resizable-panels, custom SSE client for live streaming - Package Manager:
npm
- Framework: Express.js (ES Modules, TypeScript)
- Database ORM: Prisma ORM with PostgreSQL (
@prisma/adapter-pg) - Authentication:
@clerk/expressmiddleware - Cloud Sandbox Engine:
@e2b/code-interpreter(E2B Sandboxes) - AI SDK & LLMs: Vercel AI SDK (
ai),@ai-sdk/groq(openai/gpt-oss-120b),@ai-sdk/google(gemini-3.5-flash) - Validation: Zod schemas (
zod)
The database schema (server/prisma/schema.prisma) defines three primary entities:
-
User: Stores authenticated user accounts synced from Clerk.
id: CUID primary keyclerkId: Unique Clerk user identificationusername: Account identifierprojects: Relation to created projects
-
Project: Represents an individual generated web application.
id: UUID primary keytitle: AI-generated short project titleSandboxId: Unique E2B sandbox container IDFiles: JSON representation of current file structurestatus: Enum (PENDING,READY,FAILED,UPDATING)userId: Foreign key linking to User
-
ConversationHistory: Stores all messages, agent actions, and Q&A responses.
id: UUID primary keycontent: Message text or JSON payloadprojectId: Foreign key linking to Projectfrom: Enum (USER,ASSISTANT)type: Enum (TOOL_CALL,TEXT_MESSAGE)
Create a .env file inside the server/ directory with the following variables:
# AI Model Provider Credentials
GROQ_API_KEY=your_groq_api_key
GOOGLE_GENERATIVE_AI_API_KEY=your_google_ai_key
ANTHROPIC_API_KEY=your_anthropic_api_key
# E2B Sandbox Credentials
E2B_API_KEY=your_e2b_api_key
# Database Connection
DATABASE_URL=postgresql://user:password@host:port/database_name?sslmode=verify-full
# Clerk Authentication Credentials
CLERK_SECRET_KEY=your_clerk_secret_key
CLERK_PUBLISHABLE_KEY=your_clerk_publishable_keyCreate a .env.local file inside the frontend/ directory with the following variables:
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=your_clerk_publishable_key
CLERK_SECRET_KEY=your_clerk_secret_key
NEXT_PUBLIC_API_URL=http://localhost:8080
NEXT_PUBLIC_BASE_URL=http://localhost:8080- Node.js version 18.x or higher
- npm package manager
- PostgreSQL database instance (or Neon DB connection)
- Clerk account for authentication
- E2B API Key for sandbox management
- Groq / Google AI API Keys for model inference
Navigate to the server/ directory:
cd serverInstall dependencies:
npm installGenerate Prisma client and run database migrations:
npx prisma generate
npx prisma db pushStart the backend development server:
npm run devThe Express server will run on http://localhost:8080.
In a separate terminal window, navigate to the frontend/ directory:
cd frontendInstall dependencies:
npm installStart the Next.js development server:
npm run devOpen http://localhost:3000 in your web browser.
POST /api/auth/sync: Sync user profile from Clerk token to local PostgreSQL database.
POST /api/project/create: Initialize project entry in database and request E2B sandbox allocation.POST /api/project/generate: Stream project generation via Server-Sent Events (SSE).POST /api/project/update: Submit follow-up prompt to modify existing sandbox project.GET /api/project/: Retrieve live preview web URL for the project's sandbox port.GET /api/project/chats: Retrieve message history and status for a specific project.GET /api/project/files: List file directory tree from the project's sandbox.GET /api/project/file: Fetch contents of a specific file from the sandbox.POST /api/project/answer: Submit user's answer to an agent clarification question (askUser).
The backend AI agent uses custom tools defined in server/src/tool.ts to inspect and modify the Next.js app running inside E2B sandboxes:
createFile: Writes new files to absolute paths inside the sandbox container.updateFile: Overwrites contents of existing files inside the sandbox.deleteFile: Removes target files from the container filesystem.readFile: Reads and returns content of sandbox files for agent verification.listAllFiles: Recursively fetches active file structure from sandbox.askUser: Pauses agent execution, emits an SSE question event to the frontend UI, displays interactive choices or text fields to the user, and waits for submission before continuing.
Lovable/
├── frontend/ # Next.js Frontend Application
│ ├── app/ # App router pages and layouts
│ │ ├── components/ # ChatPanel, CodeBrowser, PreviewToolbar, InputField, etc.
│ │ ├── hooks/ # Custom hooks (useProject)
│ │ ├── projects/[id]/ # Project workstation page
│ │ └── utils/ # API client & SSE stream handlers
│ ├── components/ui/ # Shared UI components (shadcn / Radix UI)
│ ├── public/ # Static assets
│ ├── package.json # Frontend dependencies
│ └── tsconfig.json # TypeScript config
│
├── server/ # Express.js Backend Application
│ ├── prisma/ # Database schema & migrations
│ ├── src/ # Server source code
│ │ ├── e2b/ # E2B sandbox templates
│ │ ├── handler/ # Express request handlers (AI tasks, Auth)
│ │ ├── middleware/ # Clerk authentication middleware
│ │ ├── routes/ # Express route definitions
│ │ ├── schema/ # Zod validation schemas
│ │ ├── index.ts # Server entry point
│ │ ├── system_prompt.ts # AI agent system prompt & guidelines
│ │ └── tool.ts # E2B sandbox AI tools
│ ├── package.json # Server dependencies
│ └── tsconfig.json # TypeScript config
│
└── README.md # Project Documentation