# prajjwal2051/builditup architecture

> Architecture diagram of the GitHub repository prajjwal2051/builditup, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-04-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/prajjwal2051/builditup
- Repository: https://github.com/prajjwal2051/builditup

## Overview

1. **Overall shape**
   - This is a **Next.js 16 App Router** monorepo-style app with two main runtime surfaces: the **web app** at the repo root and a separate **CollabServer** Node service for realtime collaboration. The browser app owns routing, UI, server actions, and most API routes; the collaboration server handles OT-style sync and presence.

2. **Primary user-facing areas**
   - The app is split into clear route groups: **public landing** (`app/(root)`), **auth** (`app/(auth)`), **dashboard** (`app/dashboard`), **playground IDE** (`app/playground/[id]`), and **public share pages** (`app/s/[token]`). This separation is important for diagramming because the IDE path is the core product surface, while dashboard and share pages are supporting flows.

3. **Core IDE runtime**
   - The playground page composes the browser IDE: **Monaco editor**, file explorer, tabs/split view, terminal, preview pane, and AI sidebar. The runtime is browser-first: code is edited in the client, then synced into a **WebContainer** so users can preview and run commands without a traditional backend dev server.

4. **WebContainer boundary**
   - `modules/webContainers` encapsulates booting and managing the in-browser runtime, while `modules/playground` owns the editor/file model and sync logic. The important flow is: **file edits in the UI → debounced write into WebContainer → live preview/terminal reflect the change**. This is a key boundary because preview execution does not happen on the Next.js server.

5. **Playground state and file model**
   - The playground uses feature-scoped hooks and client state for file-tree operations, open tabs, selection, dirty state, and AI toggles. File hierarchy is stored as a structured JSON tree and converted through `modules/playground/lib/path-to-json.ts`. That JSON tree is persisted per playground, making the file system a first-class data model rather than an ephemeral editor state.

6. **Persistence layer**
   - Persistence is centered on **Prisma + MongoDB** via `lib/db.ts` and `prisma/schema.prisma`. The main entities are **User**, **Account**, **Playground**, **TemplateFile**, and **StarMark**. In architecture terms: users and OAuth accounts handle identity, playgrounds represent projects, template files store the project’s file tree, and star marks model bookmarks/favorites.

7. **Authentication and session flow**
   - Auth is handled with **NextAuth v5** (`auth.ts`, `auth.config.ts`) using OAuth providers and a **JWT session strategy**. The sign-in flow creates or links `User` and `Account` records, then exposes user identity/role data to the client. This means the system avoids a DB session table and relies on token-backed session propagation.

8. **Sharing and public access**
   - Shared playgrounds have their own API and page flow under `app/api/share/*` and `app/s/[token]`. The share subsystem supports create, metadata/content retrieval, save, and revoke actions, so it forms a distinct boundary between private playground state and public/token-based access. The share token logic is centralized in `lib/share-token.ts`.

9. **Realtime collaboration**
   - Collaboration is split from the main app into `CollabServer/`, which contains **OT engine**, **sessions**, **presence**, **persistence**, and a **connection manager**. The Next.js app exposes collab-related status/stop endpoints and client hooks for websocket and presence behavior. For an architecture diagram, treat this as a separate realtime service that synchronizes concurrent editing and online user state.

10. **AI subsystem**
   - AI is integrated through dedicated API routes (`app/api/ai-chat`, `app/api/ai-test`, `app/api/code-completion`) and client hooks/components in `modules/playground`. There are two main AI paths: **inline code completion** inside Monaco and a **chat sidebar** for context-aware assistance. AI behavior is also configurable per session, so it acts as an optional augmentation to the IDE rather than a hard dependency.

11. **Dashboard and project orchestration**
   - The dashboard is the project-management layer: it creates playgrounds, lists them, supports search, and allows starring. The dashboard modules are the main bridge between authenticated user identity and stored playground records. This is where users choose a template and enter the IDE flow.

12. **Starter templates and generated project seeds**
   - `OrbitCode-starters/` contains framework-specific starter trees for **React, Next.js, Express, Vue, Hono, and Angular**. These are not just docs; they are the seed content that becomes the initial playground filesystem. In a diagram, this is the “project template source” feeding the persisted playground file tree.

13. **Shared UI and front-end foundation**
   - The UI is built from **Tailwind CSS**, **shadcn/ui**, and Radix-based components in `components/ui`. Feature modules in `modules/*` keep domain logic separated from generic UI primitives. This modular layout matters because most product behavior lives in feature-scoped client/server code rather than in a single monolithic component tree.

14. **Runtime and deployment constraints**
   - `next.config.ts` sets **COOP/COEP headers**, which are required for WebContainer support and browser `SharedArrayBuffer` usage. That means the app is architecturally constrained to a cross-origin isolated browser context. Environment configuration also reflects the stack: MongoDB, Auth secrets, OAuth provider keys, and optional Prisma Accelerate.

15. **High-level data flow**
   - The main end-to-end flow is: **OAuth sign-in → dashboard → playground creation from a starter template → file-tree persistence in MongoDB → browser editing and WebContainer sync → optional realtime collaboration via CollabServer → optional AI assistance → share/public link generation**. That is the core system sequence an architecture diagram should emphasize.

Main entry points: [`modules/playground/lib/index.ts`](https://github.com/prajjwal2051/builditup/blob/main/modules/playground/lib/index.ts) (Playground module), [`lib/db.ts`](https://github.com/prajjwal2051/builditup/blob/main/lib/db.ts) (Prisma DB), [`app/layout.tsx`](https://github.com/prajjwal2051/builditup/blob/main/app/layout.tsx) (App shell), [`CollabServer/index.ts`](https://github.com/prajjwal2051/builditup/blob/main/CollabServer/index.ts) (CollabServer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_webapp["Web App"]
  node_root_layout["App shell<br/>next app<br/>[layout.tsx]"]
  node_home_page["Landing<br/>route page<br/>[page.tsx]"]
  node_auth_signin["Sign in<br/>auth route<br/>[page.tsx]"]
  node_dashboard_page["Dashboard<br/>projects route<br/>[page.tsx]"]
  node_playground_page["Playground<br/>ide route<br/>[page.tsx]"]
  node_share_page["Shared view<br/>public route<br/>[page.tsx]"]
end

subgraph group_apis["API Layer"]
  node_api_auth["Auth API<br/>nextauth route<br/>[route.ts]"]
  node_api_playground["Playground API<br/>project API<br/>[route.ts]"]
  node_api_share["Share API<br/>[route.tsx]"]
  node_api_ai["AI API<br/>assistant API<br/>[route.ts]"]
  node_api_collab["Collab API<br/>runtime API<br/>[route.ts]"]
end

subgraph group_modules["Feature Modules"]
  node_dashboard_module["Dashboard module<br/>project ops<br/>[index.ts]"]
  node_auth_module["Auth module<br/>identity UI<br/>[index.ts]"]
  node_playground_module["Playground module<br/>ide state<br/>[index.ts]"]
end

subgraph group_runtime["Runtime Layer"]
  node_webcontainers_module["WebContainer<br/>browser runtime<br/>[useWebContainer.ts]"]
end

subgraph group_data["Data Layer"]
  node_db[("Prisma DB<br/>persistence<br/>[db.ts]")]
  node_schema["Schema<br/>prisma model<br/>[schema.prisma]"]
  node_share_token["Share token<br/>token util<br/>[share-token.ts]"]
end

subgraph group_service["Collab Service"]
  node_collab_server["CollabServer<br/>realtime service<br/>[index.ts]"]
  node_collab_ot["OT engine<br/>sync core<br/>[engine.ts]"]
  node_collab_presence["Presence<br/>realtime state<br/>[presence.ts]"]
end

subgraph group_templates["Starter Trees"]
  node_starters["Starter trees<br/>template source<br/>[page.tsx]"]
end

node_root_layout -->|"renders"| node_home_page
node_root_layout -->|"routes"| node_auth_signin
node_root_layout -->|"routes"| node_dashboard_page
node_root_layout -->|"routes"| node_playground_page
node_root_layout -->|"routes"| node_share_page
node_auth_signin -->|"signs in via"| node_api_auth
node_dashboard_page -->|"uses"| node_dashboard_module
node_dashboard_module -->|"persists"| node_db
node_dashboard_module -->|"seeds from"| node_starters
node_playground_page -->|"composes"| node_playground_module
node_playground_module -->|"syncs to"| node_webcontainers_module
node_playground_module -->|"calls"| node_api_ai
node_playground_module -->|"shares via"| node_api_share
node_playground_module -->|"collab control"| node_api_collab
node_playground_module -->|"loads/saves"| node_db
node_playground_module -->|"tags with"| node_share_token
node_api_playground -->|"reads/writes"| node_db
node_api_share -->|"issues"| node_share_token
node_api_share -->|"reads/writes"| node_db
node_api_ai -->|"config/state"| node_db
node_api_collab -->|"controls"| node_collab_server
node_collab_server -->|"runs"| node_collab_ot
node_collab_server -->|"tracks"| node_collab_presence
node_collab_server -->|"optional persistence"| node_db
node_webcontainers_module -->|"receives edits from"| node_playground_module
node_starters -->|"becomes"| node_db
node_schema -->|"defines"| node_db

click node_root_layout "https://github.com/prajjwal2051/builditup/blob/main/app/layout.tsx"
click node_home_page "https://github.com/prajjwal2051/builditup/blob/main/app/page.tsx"
click node_auth_signin "https://github.com/prajjwal2051/builditup/blob/main/app/(auth)/auth/sign-in/page.tsx"
click node_dashboard_page "https://github.com/prajjwal2051/builditup/blob/main/app/dashboard/page.tsx"
click node_playground_page "https://github.com/prajjwal2051/builditup/blob/main/app/playground/[id]/page.tsx"
click node_share_page "https://github.com/prajjwal2051/builditup/blob/main/app/s/[token]/page.tsx"
click node_api_auth "https://github.com/prajjwal2051/builditup/blob/main/app/api/auth/[...nextauth]/route.ts"
click node_api_playground "https://github.com/prajjwal2051/builditup/blob/main/app/api/playground/[id]/route.ts"
click node_api_share "https://github.com/prajjwal2051/builditup/blob/main/app/api/share/create/route.tsx"
click node_api_ai "https://github.com/prajjwal2051/builditup/blob/main/app/api/ai-chat/route.ts"
click node_api_collab "https://github.com/prajjwal2051/builditup/blob/main/app/api/collab/playground/[playgroundId]/status/route.ts"
click node_dashboard_module "https://github.com/prajjwal2051/builditup/blob/main/modules/dashboard/actions/index.ts"
click node_auth_module "https://github.com/prajjwal2051/builditup/blob/main/modules/auth/actions/index.ts"
click node_playground_module "https://github.com/prajjwal2051/builditup/blob/main/modules/playground/lib/index.ts"
click node_webcontainers_module "https://github.com/prajjwal2051/builditup/blob/main/modules/webContainers/hooks/useWebContainer.ts"
click node_collab_server "https://github.com/prajjwal2051/builditup/blob/main/CollabServer/index.ts"
click node_collab_ot "https://github.com/prajjwal2051/builditup/blob/main/CollabServer/ot/engine.ts"
click node_collab_presence "https://github.com/prajjwal2051/builditup/blob/main/CollabServer/presence.ts"
click node_db "https://github.com/prajjwal2051/builditup/blob/main/lib/db.ts"
click node_schema "https://github.com/prajjwal2051/builditup/blob/main/prisma/schema.prisma"
click node_share_token "https://github.com/prajjwal2051/builditup/blob/main/lib/share-token.ts"
click node_starters "https://github.com/prajjwal2051/builditup/blob/main/OrbitCode-starters/nextjs/app/page.tsx"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_root_layout,node_home_page,node_auth_signin,node_dashboard_page,node_playground_page,node_share_page,node_starters toneBlue
class node_api_auth,node_api_playground,node_api_share,node_api_ai,node_api_collab toneAmber
class node_dashboard_module,node_auth_module,node_playground_module toneMint
class node_webcontainers_module toneRose
class node_db,node_schema,node_share_token toneIndigo
class node_collab_server,node_collab_ot,node_collab_presence toneTeal
```

## Components

### Web App

Next.js App Router surfaces and UI composition

- [App shell](https://github.com/prajjwal2051/builditup/blob/main/app/layout.tsx): next app · Root layout and global app composition · `app/layout.tsx`
- [Landing](https://github.com/prajjwal2051/builditup/blob/main/app/page.tsx): route page · Public marketing home experience · `app/page.tsx`
- [Sign in](https://github.com/prajjwal2051/builditup/blob/main/app/(auth)/auth/sign-in/page.tsx): auth route · Authentication entry surface · `app/(auth)/auth/sign-in/page.tsx`
- [Dashboard](https://github.com/prajjwal2051/builditup/blob/main/app/dashboard/page.tsx): projects route · Project list, search, create, and star management · `app/dashboard/page.tsx`
- [Playground](https://github.com/prajjwal2051/builditup/blob/main/app/playground/[id]/page.tsx): ide route · Core browser IDE surface for a project · `app/playground/[id]/page.tsx`
- [Shared view](https://github.com/prajjwal2051/builditup/blob/main/app/s/[token]/page.tsx): public route · Token-based public playground access · `app/s/[token]/page.tsx`

### API Layer

Server routes for auth, AI, playground, sharing, and collaboration control

- [Auth API](https://github.com/prajjwal2051/builditup/blob/main/app/api/auth/[...nextauth]/route.ts): nextauth route · OAuth and session handling endpoints · `app/api/auth/[...nextauth]/route.ts`
- [Playground API](https://github.com/prajjwal2051/builditup/blob/main/app/api/playground/[id]/route.ts): project API · Create, load, and update playground records · `app/api/playground/[id]/route.ts`
- [Share API](https://github.com/prajjwal2051/builditup/blob/main/app/api/share/create/route.tsx): share API · Create, fetch, save, and revoke public shares · `app/api/share/create/route.tsx`
- [AI API](https://github.com/prajjwal2051/builditup/blob/main/app/api/ai-chat/route.ts): assistant API · Chat, test, and code completion endpoints · `app/api/ai-chat/route.ts`
- [Collab API](https://github.com/prajjwal2051/builditup/blob/main/app/api/collab/playground/[playgroundId]/status/route.ts): runtime API · Collaboration status and stop control endpoints · `app/api/collab/playground/[playgroundId]/status/route.ts`

### Feature Modules

Domain logic and client-side feature systems

- [Dashboard module](https://github.com/prajjwal2051/builditup/blob/main/modules/dashboard/actions/index.ts): project ops · Dashboard actions and components for project orchestration · `modules/dashboard/actions/index.ts`
- [Auth module](https://github.com/prajjwal2051/builditup/blob/main/modules/auth/actions/index.ts): identity UI · Auth actions and client session helpers · `modules/auth/actions/index.ts`
- [Playground module](https://github.com/prajjwal2051/builditup/blob/main/modules/playground/lib/index.ts): ide state · Editor state, file model, dialogs, and collaboration UI · `modules/playground/lib/index.ts`

### Runtime Layer

Browser execution and collaboration runtime boundaries

- [WebContainer](https://github.com/prajjwal2051/builditup/blob/main/modules/webContainers/hooks/useWebContainer.ts): browser runtime · In-browser project runtime and preview management · `modules/webContainers/hooks/useWebContainer.ts`

### Data Layer

Persistence and schema-driven models

- [Prisma DB](https://github.com/prajjwal2051/builditup/blob/main/lib/db.ts): persistence · Database access layer for MongoDB-backed records · `lib/db.ts`
- [Schema](https://github.com/prajjwal2051/builditup/blob/main/prisma/schema.prisma): prisma model · Users, accounts, playgrounds, templates, and stars · `prisma/schema.prisma`
- [Share token](https://github.com/prajjwal2051/builditup/blob/main/lib/share-token.ts): token util · Central token generation and validation logic · `lib/share-token.ts`

### Collab Service

Separate realtime synchronization service

- [CollabServer](https://github.com/prajjwal2051/builditup/blob/main/CollabServer/index.ts): realtime service · Separate Node service for OT sync and presence · `CollabServer/index.ts`
- [OT engine](https://github.com/prajjwal2051/builditup/blob/main/CollabServer/ot/engine.ts): sync core · Operational transform logic and session handling · `CollabServer/ot/engine.ts`
- [Presence](https://github.com/prajjwal2051/builditup/blob/main/CollabServer/presence.ts): realtime state · Online-user and cursor/presence state handling · `CollabServer/presence.ts`

### Starter Trees

Seed project files used to initialize playgrounds

- [Starter trees](https://github.com/prajjwal2051/builditup/blob/main/OrbitCode-starters/nextjs/app/page.tsx): template source · Framework-specific seed projects for new playgrounds · `OrbitCode-starters/nextjs/app/page.tsx`

## Connections

- App shell → Landing: renders · App shell composes the public landing experience
- App shell → Sign in: routes · App shell supports the auth surface
- App shell → Dashboard: routes · Authenticated project dashboard surface
- App shell → Playground: routes · Primary IDE surface
- App shell → Shared view: routes · Public shared playground surface
- Sign in → Auth API: signs in via · Client auth flows use the NextAuth route
- Dashboard → Dashboard module: uses · Dashboard UI is driven by feature actions and components
- Dashboard module → Prisma DB: persists · Project orchestration reads and writes stored records
- Dashboard module → Starter trees: seeds from · New playgrounds begin from starter templates
- Playground → Playground module: composes · IDE page is built from playground feature modules
- Playground module → WebContainer: syncs to · File edits are written into the browser runtime
- Playground module → AI API: calls · Chat and completion features use AI endpoints
- Playground module → Share API: shares via · Share link creation and management flow through API routes
- Playground module → Collab API: collab control · Client collaboration state connects to collaboration control APIs
- Playground module → Prisma DB: loads/saves · Playground state and file tree are persisted
- Playground module → Share token: tags with · Shared playground access is token-based
- Playground API → Prisma DB: reads/writes · Playground API is backed by Prisma persistence
- Share API → Share token: issues · Share endpoints rely on central token logic
- Share API → Prisma DB: reads/writes · Share metadata and content are persisted
- AI API → Prisma DB: config/state · AI behavior can be session- or project-aware
- Collab API → CollabServer: controls · Next.js exposes status and stop controls for the separate service
- CollabServer → OT engine: runs · Server hosts OT synchronization engine
- CollabServer → Presence: tracks · Server maintains presence state
- CollabServer → Prisma DB: optional persistence · Collaboration state can be stored or restored
- WebContainer → Playground module: receives edits from · Browser runtime is driven by playground file changes
- Starter trees → Prisma DB: becomes · Starter trees are turned into persisted playground file trees
- Schema → Prisma DB: defines · Prisma schema shapes the persistence layer
