# aestheticsuraj234/vibecode-playground architecture

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

- Interactive diagram: https://gitdiagram.com/aestheticsuraj234/vibecode-playground
- Repository: https://github.com/aestheticsuraj234/vibecode-playground

## Overview

##### Project Type and Purpose
- This is a full-stack, AI-powered web IDE built with Next.js (App Router), running entirely in the browser.
- Purpose: Provide an in-browser code editor (Monaco), interactive terminal (xterm.js + WebContainers), AI chat/code suggestions (Ollama LLM), project templates, OAuth-backed authentication, and persistent state via MongoDB.

##### File Structure
- Top-level “app/” directory: Next.js App Router pages & API routes.
- app/layout.tsx, app/globals.css: global UI layout and styling.
- app/api/auth, chat, code-suggestion, template: backend API endpoints.
- app/(auth), app/(root), app/dashboard, app/playground: dynamic page segments and layouts.
- “components/” and “features/”: reusable UI building blocks (ShadCN UI + Tailwind) and feature-scoped modules (auth, ai-chat, dashboard, playground, webcontainers).
- “lib/” and “hooks/”: shared utilities (DB access via Prisma, syntax highlighting, template logic) and React hooks.
- “prisma/schema.prisma”: data model (MongoDB).
- Config files: next.config.ts, auth.config.ts, middleware.ts, vercel.json.
- External integrations: WebContainers service (in-browser Node.js), Ollama LLM (Docker), NextAuth (OAuth), MongoDB.

##### README for Additional Insights
- Tech stack: Next.js 15 App Router, TypeScript, TailwindCSS, ShadCN UI, NextAuth (Google/GitHub), Monaco Editor, Ollama, WebContainers, xterm.js, MongoDB.
- Features: OAuth login, project templates, custom file explorer, AI suggestions, embedded terminal, AI chat assistant.

##### Main Components
a. Frontend (Browser)
- Next.js React UI: pages, layouts, feature components.
- Monaco Editor component.
- Custom File Explorer UI.
- Terminal UI (xterm.js + WebContainers).
- AI Chat panel.
b. Backend (Next.js Server / Edge)
- API Routes: /api/auth (NextAuth), /api/chat, /api/code-suggestion, /api/template.
- Data layer: Prisma client → MongoDB.
c. In-Browser Runtime
- WebContainers service: spawns Node.js containers for live code execution.
d. External Services
- OAuth Providers (Google, GitHub).
- Ollama LLM (running locally via Docker).
- MongoDB Atlas (or self-hosted).
e. Infrastructure / Deployment
- Vercel (or custom hosting), environment variables, build pipeline.

##### Relationships and Interactions
- User in Browser → Next.js React UI → API Routes for data, authentication, AI suggestions.
- Next.js API → Prisma → MongoDB.
- Next.js API → Ollama LLM service for code suggestions & AI chat.
- Browser UI ↔ WebContainers: live code execution and embedded terminal I/O.
- OAuth “Sign in” flow: Browser → NextAuth API → OAuth Provider → NextAuth callback → session cookie.
- Template retrieval: Browser → /api/template → file templates served.

##### Architectural Patterns and Design Principles
- Layered architecture: UI layer, application/API layer, data layer.
- Feature-based module organization (under “features/”).
- Next.js App Router for co-located pages, layouts, API.
- Component reusability: ShadCN UI primitives + custom feature components.
- In-browser microservice (WebContainers) for sandboxed execution.

##### Final Checklist
- All main components present.
- Authentication flow to OAuth providers.
- In-browser runtime highlighted as distinct microservice.
- Technology labels (Next.js, TypeScript, Prisma, MongoDB, Ollama, WebContainers, xterm.js).
- Logical grouping of feature modules under broader services.

## Diagram (Mermaid)

```mermaid
flowchart TD
  %% Swimlanes / Layers
  subgraph "Frontend (Browser)" 
    direction TB
    User[("User")]:::user
    NextLayout["Global Layout"]:::frontend
    RootPage["Root Page & Layout"]:::frontend
    AuthLayout["Auth Pages & Layout"]:::frontend
    DashboardLayout["Dashboard Pages & Layout"]:::frontend
    PlaygroundLayout["Playground Pages & Layout"]:::frontend
    Monaco["Monaco Editor"]:::frontend
    FileExplorer["File Explorer UI"]:::frontend
    TerminalUI["Terminal UI (xterm.js)"]:::frontend
    AIChatUI["AI Chat Panel"]:::frontend
    PlaygroundLogic["Playground Logic & Hooks"]:::frontend
  end

  subgraph "Application/API (Next.js Server)"
    direction TB
    AuthAPI["/api/auth (NextAuth)"]:::api
    AIChatAPI["/api/chat"]:::api
    CodeSuggestionAPI["/api/code-suggestion"]:::api
    TemplateAPI["/api/template"]:::api
    NextServer["Next.js Server"]:::service
  end

  subgraph "Data Layer"
    direction TB
    PrismaClient["Prisma Client & DB Utility"]:::data
    Schema["Prisma Schema"]:::data
    MongoDB[(MongoDB)]:::db
    SyntaxHighlight["Syntax Highlighting Utility"]:::data
    TemplateUtil["Project Template Utilities"]:::data
  end

  subgraph "In-Browser Runtime"
    direction TB
    WebContainerService["WebContainers Service"]:::runtime
  end

  subgraph "External Services"
    direction TB
    OAuth["OAuth Providers (Google, GitHub)"]:::external
    Ollama["Ollama LLM"]:::external
    Vercel["Vercel Hosting"]:::external
  end

  %% Relationships
  User --> NextLayout
  NextLayout --> RootPage
  NextLayout --> AuthLayout
  NextLayout --> DashboardLayout
  NextLayout --> PlaygroundLayout

  PlaygroundLayout --> Monaco
  PlaygroundLayout --> FileExplorer
  PlaygroundLayout --> TerminalUI
  PlaygroundLayout --> PlaygroundLogic

  AIChatUI --> AIChatAPI
  AuthLayout --> AuthAPI
  DashboardLayout --> TemplateAPI
  Monaco --> CodeSuggestionAPI
  PlaygroundLogic --> TemplateAPI

  AuthAPI --> NextServer
  AIChatAPI --> NextServer
  CodeSuggestionAPI --> NextServer
  TemplateAPI --> NextServer

  NextServer --> PrismaClient
  PrismaClient --> MongoDB
  PrismaClient --> Schema
  NextServer --> Ollama
  AuthAPI --> OAuth

  TerminalUI <--> WebContainerService

  NextServer --> Vercel

  SyntaxHighlight --> Monaco
  TemplateUtil --> TemplateAPI

  %% Click Events
  click NextLayout "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/app/layout.tsx"
  click RootPage "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/app/(root)/layout.tsx"
  click RootPage "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/app/(root)/page.tsx"
  click AuthLayout "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/app/(auth)/auth/layout.tsx"
  click AuthLayout "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/app/(auth)/auth/sign-in/page.tsx"
  click DashboardLayout "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/app/dashboard/layout.tsx"
  click DashboardLayout "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/app/dashboard/page.tsx"
  click PlaygroundLayout "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/app/playground/[id]/layout.tsx"
  click PlaygroundLayout "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/app/playground/[id]/page.tsx"
  click AuthAPI "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/app/api/auth/[...nextauth]/route.ts"
  click AIChatAPI "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/app/api/chat/route.ts"
  click CodeSuggestionAPI "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/app/api/code-suggestion/route.ts"
  click TemplateAPI "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/app/api/template/[id]/route.ts"
  click TemplateAPI "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/app/api/template/[id]/main.js"
  click PrismaClient "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/lib/db.ts"
  click Schema "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/prisma/schema.prisma"
  click AIChatUI "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/features/ai-chat/components/ai-chat-sidepanel.tsx"
  click AIChatUI "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/features/ai-chat/components/ai-chat-code-blocks.tsx"
  click AIChatUI "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/features/ai-chat/components/file-attachment.tsx"
  click AIChatUI "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/features/ai-chat/components/file-preview.tsx"
  click Monaco "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/features/playground/components/code-editor.tsx"
  click Monaco "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/features/playground/components/playground-editor.tsx"
  click FileExplorer "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/features/playground/components/file-tree.tsx"
  click FileExplorer "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/features/playground/components/playground-explorer.tsx"
  click PlaygroundLogic "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/features/playground/actions/index.ts"
  click PlaygroundLogic "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/features/playground/hooks/usePlayground.tsx"
  click TerminalUI "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/features/webcontainers/components/terminal.tsx"
  click WebContainerService "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/features/webcontainers/service/webContainerService.ts"
  click WebContainerService "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/features/webcontainers/hooks/useWebContainer.ts"
  click SyntaxHighlight "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/lib/syntax-highlighter.tsx"
  click TemplateUtil "https://github.com/aestheticsuraj234/vibecode-playground/blob/master/lib/template.ts"

  %% Styles
  classDef frontend fill:#f0f8ff,stroke:#333,stroke-width:1px
  classDef api fill:#e6e6fa,stroke:#333,stroke-width:1px
  classDef data fill:#e0ffe0,stroke:#333,stroke-width:1px
  classDef db fill:#ffe4e1,stroke:#333,stroke-width:1px
  classDef runtime fill:#fffacd,stroke:#333,stroke-width:1px
  classDef external fill:#fafad2,stroke:#333,stroke-width:1px
  classDef service fill:#d3d3d3,stroke:#333,stroke-width:1px
  classDef user fill:#ffebee,stroke:#333,stroke-width:1px
```
