# aestheticsuraj234/chai-vibe-editor architecture

> Architecture diagram of the GitHub repository aestheticsuraj234/chai-vibe-editor, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aestheticsuraj234/chai-vibe-editor
- Repository: https://github.com/aestheticsuraj234/chai-vibe-editor

## Overview

##### 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

## Diagram (Mermaid)

```mermaid
flowchart TD
  subgraph "Client Tier"
    style Client Tier fill:#E0F7FA,stroke:#000
    subgraph "Next.js Frontend"
      NextFrontend["Next.js Frontend"]:::client
      AuthPages["Auth Pages & Layouts"]:::client
      DashboardPages["Dashboard Pages & Layouts"]:::client
      PlaygroundPages["Playground Pages & Layouts"]:::client
    end
    SharedUI["Shared UI Components"]:::client
    ThemeProv["Theme Providers"]:::client
    Monaco["Monaco Editor"]:::client
    Explorer["File Explorer"]:::client
    ChatUI["AI Chat Panel"]:::client
    AuthModule["Auth Feature Module"]:::client
    DashboardModule["Dashboard Feature Module"]:::client
    PlaygroundModule["Playground Feature Module"]:::client
    WebContainer["WebContainers Runtime"]:::client
    Xterm["xterm.js Terminal"]:::client

    NextFrontend -->|uses| AuthPages
    NextFrontend -->|uses| DashboardPages
    NextFrontend -->|uses| PlaygroundPages
    NextFrontend -->|imports| SharedUI
    NextFrontend -->|wraps| ThemeProv
    PlaygroundPages -->|embeds| Monaco
    PlaygroundPages -->|embeds| Explorer
    NextFrontend -->|renders| ChatUI
    NextFrontend -->|loads| WebContainer
    WebContainer -->|exposes| Xterm
  end

  subgraph "Server Tier"
    style Server Tier fill:#E8F5E9,stroke:#000
    AuthAPI["Auth API (NextAuth)"]:::server
    ChatAPI["Chat API"]:::server
    CodeAPI["Code-Completion API"]:::server
    TemplateAPI["Template API"]:::server
    Prisma["Prisma ORM"]:::server

    NextFrontend -->|HTTPS| AuthAPI
    NextFrontend -->|HTTPS| ChatAPI
    NextFrontend -->|HTTPS| CodeAPI
    NextFrontend -->|HTTPS| TemplateAPI
    AuthAPI -->|queries| Prisma
    ChatAPI -->|queries| Prisma
    TemplateAPI -->|queries| Prisma
    ChatAPI -->|forwards| Ollama
    CodeAPI -->|forwards| Ollama
  end

  subgraph "External Services"
    style External Services fill:#FFF3E0,stroke:#000
    MongoDB["MongoDB"]:::external
    OAuth["OAuth Providers\n(Google, GitHub)"]:::external
    Ollama["Ollama LLMs (Docker)"]:::external
    Docker["Docker Engine"]:::external

    AuthAPI -->|OAuth Flow| OAuth
    Prisma -->|stores| MongoDB
    Ollama -->|runs on| Docker
  end

  classDef client fill:#BBDEFB,stroke:#1976D2,color:#000;
  classDef server fill:#C8E6C9,stroke:#388E3C,color:#000;
  classDef external fill:#FFE0B2,stroke:#F57C00,color:#000;

  click NextFrontend "https://github.com/aestheticsuraj234/chai-vibe-editor/tree/master/app/"
  click AuthPages "https://github.com/aestheticsuraj234/chai-vibe-editor/blob/master/app/(auth)/auth/layout.tsx"
  click DashboardPages "https://github.com/aestheticsuraj234/chai-vibe-editor/blob/master/app/dashboard/layout.tsx"
  click PlaygroundPages "https://github.com/aestheticsuraj234/chai-vibe-editor/blob/master/app/playground/[id]/layout.tsx"
  click SharedUI "https://github.com/aestheticsuraj234/chai-vibe-editor/tree/master/components/ui/"
  click ThemeProv "https://github.com/aestheticsuraj234/chai-vibe-editor/blob/master/components/providers/theme-providers.tsx"
  click Monaco "https://github.com/aestheticsuraj234/chai-vibe-editor/blob/master/modules/playground/components/playground-editor.tsx"
  click Explorer "https://github.com/aestheticsuraj234/chai-vibe-editor/blob/master/modules/playground/components/playground-explorer.tsx"
  click ChatUI "https://github.com/aestheticsuraj234/chai-vibe-editor/blob/master/modules/ai-chat/components/ai-chat-sidebarpanel.tsx"
  click AuthModule "https://github.com/aestheticsuraj234/chai-vibe-editor/tree/master/modules/auth"
  click DashboardModule "https://github.com/aestheticsuraj234/chai-vibe-editor/tree/master/modules/dashboard"
  click PlaygroundModule "https://github.com/aestheticsuraj234/chai-vibe-editor/tree/master/modules/playground"
  click WebContainer "https://github.com/aestheticsuraj234/chai-vibe-editor/blob/master/modules/webcontainers/components/webcontainer-preview.tsx"
  click Xterm "https://github.com/aestheticsuraj234/chai-vibe-editor/blob/master/modules/webcontainers/components/terminal.tsx"
  click AuthAPI "https://github.com/aestheticsuraj234/chai-vibe-editor/blob/master/app/api/auth/[...nextauth]/route.ts"
  click ChatAPI "https://github.com/aestheticsuraj234/chai-vibe-editor/blob/master/app/api/chat/route.ts"
  click CodeAPI "https://github.com/aestheticsuraj234/chai-vibe-editor/blob/master/app/api/code-completion/route.ts"
  click TemplateAPI "https://github.com/aestheticsuraj234/chai-vibe-editor/blob/master/app/api/template/[id]/route.ts"
  click Prisma "https://github.com/aestheticsuraj234/chai-vibe-editor/blob/master/lib/db.ts"
  click Prisma "https://github.com/aestheticsuraj234/chai-vibe-editor/blob/master/prisma/schema.prisma"
```
