How aestheticsuraj234/chai-vibe-editor works
Project Type & Purpose
• This is a full-stack, AI-powered web IDE built with Next.js App Router.
• It combines a rich React-based frontend (UI modules, Monaco Editor, xterm.js) with a Next.js backend (API routes for auth, chat, code generation, templates).
• External integrations include MongoDB (via Prisma), OAuth providers (Google/GitHub via NextAuth), local LLMs (Ollama in Docker), and in-browser containers (WebContainers).
High-Level File Structure & Architectural Patterns
• app/ – Next.js App Router pages & layouts, including frontend routes under /(auth), /(root), /dashboard, /playground, and API endpoints under app/api.
• modules/ – Feature modules (ai-chat, auth, dashboard, playground, webcontainers) each containing components, hooks, and actions, enforcing a modular, domain-driven structure.
• components/ – Shared UI components (ShadCN UI wrappers, theme providers).
• lib/ – Utility layers: db.ts (Prisma), template.ts, utils.ts.
• prisma/ – Schema and migrations connecting to MongoDB.
• public/, styles, config files – static assets, TailwindCSS, PostCSS, NextAuth config.
Main Components
a. Frontend (Browser)
• Next.js React App (App Router)
• UI Modules: ShadCN UI, TailwindCSS, Monaco Editor, xterm.js
• Feature modules: Playground (file explorer, editor), Dashboard, AI Chat Panel, Auth flows
b. Backend (Next.js API Layer)
• Auth API (NextAuth) connecting to OAuth providers
• Chat & Code-Completion APIs forwarding requests to Ollama
• Template API serving project templates
• Prisma ORM layer accessing MongoDB
c. External Services
• MongoDB database
• OAuth Providers (Google, GitHub)
• Ollama LLMs (running locally via Docker)
• Docker Engine (for Ollama)
d. In-Browser Containerization
• WebContainers runtime (spawns in-browser Node.js environments)
• xterm.js terminal embedded in the browser
Relationships & Data Flows
• The Browser → Next.js pages call Next.js API routes over HTTP/HTTPS.
• Auth routes ↔ OAuth providers (Google/GitHub) via NextAuth.
• Backend API routes → Prisma → MongoDB for user, session, template, and project data.
• Chat & code-completion API routes → local Ollama via REST/HTTP.
• Frontend Playground → WebContainers runtime (JS APIs) to spin up ephemeral containers → xterm.js communicates with the container.
• Monaco Editor on the client invokes code-completion via API.
Architectural Patterns & Design Principles
• Modular, feature-based code organization (modules/).
• Separation of concerns: UI components vs page layouts vs API layers.
• Next.js App Router fluid routes and nested layouts.
• Domain-driven layering: lib/ for data access, modules/ for business logic.
• In-browser virtualization (WebContainers) for a zero-server dev environment.
• Next.js App Router (pages & layouts)
• Monaco Editor & File Explorer module
• xterm.js → WebContainers Runtime
• AI Chat UI module
• Auth API (NextAuth)
• /api/chat, /api/code-completion, /api/template
• Prisma ORM layer
3. On the right, place External Services:
• MongoDB
• OAuth Providers (Google, GitHub)
• Ollama LLMs (Docker container)
• Browser → Next.js API (HTTP)
• Auth API ↔ OAuth Providers
• API → Prisma → MongoDB
• Chat & Code API → Ollama
• Playground UI ↔ WebContainers Runtime