# tirthbhatt1208/vibestudio architecture

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

- Interactive diagram: https://gitdiagram.com/tirthbhatt1208/vibestudio
- Repository: https://github.com/tirthbhatt1208/vibestudio

## Overview

1. **Repo shape**
   - This is a full-stack **Next.js App Router** application, mostly JavaScript/JSX with some generated TypeScript typings under `generated/prisma`.
   - The app is organized around a **project workspace** for prompt-driven UI generation, plus auth, billing/usage, and background processing.

2. **Primary runtime boundary**
   - There are three main execution zones:
     - **Client UI** in `src/app` and `src/components`
     - **Server-side feature actions** in `src/modules/*/actions`
     - **Background jobs** in `src/inngest/*`, exposed through `src/app/api/inngest/route.js`
   - That separation is the core architectural boundary: user interactions happen in the browser, state-changing work runs on the server, and long-running generation work is offloaded.

3. **Route structure**
   - Public routes live under `src/app/(root)` for the landing page, pricing, sign-in, and sign-up.
   - The main app experience is under `src/app/projects/[projectId]`, which is the project detail/workspace screen.
   - `src/app/layout.js` and `src/app/globals.css` provide the app shell and global styling.

4. **Feature-oriented modules**
   - Business logic is split by domain in `src/modules`:
     - `auth` for authentication-related actions
     - `home` for the landing/dashboard experience
     - `projects` for project workspace behavior
     - `messages` for prompt/message threading
     - `usage` for quota and billing/consumption tracking
   - Each module has its own `actions`, and many also have `components` and `hooks`, which keeps UI and domain logic co-located.

5. **Project workspace UI**
   - The project page is composed from focused UI pieces in `src/modules/projects/components`, including:
     - message composer and message cards
     - file explorer / tree view
     - code viewer with syntax styling
     - project header and overall project view container
     - preview-related fragments
   - This strongly suggests the main workspace is a split-view editor/review surface: prompt/messages on one side, generated code/files/preview on the other.

6. **Data flow for generation**
   - The README describes a prompt-to-code pipeline, and the tree supports that with `src/prompt.js`, message utilities, and the job system.
   - The likely flow is: user submits a prompt in the project UI → a server action persists/validates it → an Inngest event is emitted → background functions generate or update code → results are stored and surfaced back in the project workspace.

7. **Background job subsystem**
   - `src/inngest/client.js`, `functions.js`, and `utils.js` define the async job layer.
   - `src/app/api/inngest/route.js` is the webhook/handler boundary that lets Inngest invoke the app.
   - This subsystem exists to keep generation and sandbox execution out of the request/response path, so the UI can stay responsive while work completes asynchronously.

8. **Persistence layer**
   - Prisma is the database boundary: `prisma/schema.prisma`, migration files, `prisma.config.ts`, and the generated client under `generated/prisma`.
   - The schema includes `User`, `Project`, `Message`, `Fragment`, and `Usage`, which maps to the app’s core concepts:
     - identity and ownership
     - project grouping
     - chat/prompt history
     - generated code fragments
     - metering/quotas
   - `src/lib/db.js` is the shared database access point.

9. **Sandbox execution boundary**
   - `sandbox-templates/next-js` is a separate execution environment template for running generated code in isolation.
   - The presence of `e2b.Dockerfile`, `e2b.toml`, and `compile_page.sh` shows the generated UI is meant to be built/run inside a controlled sandbox, not on the main app server.
   - This is a major architectural boundary: the app produces code, but execution happens in an external isolated runtime.

10. **Auth, billing, and usage control**
   - The repo has dedicated sign-in/sign-up routes and a `src/proxy.js`, indicating route protection at the edge or middleware layer.
   - `src/modules/usage` and `src/lib/usage.js` suggest generation limits and billing/entitlement checks are enforced server-side before expensive work starts.
   - `src/components/user-control.jsx` likely anchors the authenticated account menu/session controls in the UI.

11. **Shared client infrastructure**
   - `src/components/query-provider.jsx` and `src/components/theme-provider.jsx` provide app-wide client context for server-state caching and theming.
   - `src/hooks` contains reusable client behavior such as mobile detection, scrolling, and theme state.
   - `src/lib/utils.js` and `src/lib/message-role.js` hold cross-cutting helpers used across modules.

12. **UI system**
   - `src/components/ui/*` is a large shadcn/ui-style component library used to assemble the interface.
   - This means most screens are built from composable primitives rather than custom one-off widgets, which keeps the design system consistent across home, auth, and workspace views.

13. **What to diagram**
   - The most important diagram boundaries are:
     - browser UI vs server actions
     - server app vs Inngest jobs
     - app vs PostgreSQL via Prisma
     - app vs isolated sandbox runtime
     - auth/usage gating around generation entry points
   - The central object in the architecture is the **project**, with messages/prompts and generated fragments flowing through it.

Main entry points: [`src/lib/db.js`](https://github.com/tirthbhatt1208/vibestudio/blob/main/src/lib/db.js) (DB access), [`src/app/layout.js`](https://github.com/tirthbhatt1208/vibestudio/blob/main/src/app/layout.js) (App layout), [`src/modules/messages/actions/index.js`](https://github.com/tirthbhatt1208/vibestudio/blob/main/src/modules/messages/actions/index.js) (Message actions), [`src/modules/projects/components`](https://github.com/tirthbhatt1208/vibestudio/tree/main/src/modules/projects/components) (Workspace UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App Shell"]
  node_root_layout["App layout<br/>next shell<br/>[layout.js]"]
  node_root_styles["Global styles<br/>css<br/>[globals.css]"]
  node_public_routes["Public pages<br/>routes"]
  node_project_route["Project workspace<br/>route<br/>[page.jsx]"]
  node_inngest_route["Inngest handler<br/>api route<br/>[route.js]"]
end

subgraph group_modules["Feature Modules"]
  node_auth_module["Auth module<br/>server actions<br/>[index.js]"]
  node_home_ui["Home screens<br/>ui module"]
  node_projects_actions["Project actions<br/>server actions<br/>[index.js]"]
  node_messages_actions["Message actions<br/>server actions<br/>[index.js]"]
  node_usage_actions["Usage actions<br/>server actions<br/>[index.js]"]
  node_workspace_ui["Workspace UI<br/>ui module"]
  node_message_hook["Message hook<br/>client hook<br/>[message.js]"]
  node_prompt_def["Prompt config<br/>prompting<br/>[prompt.js]"]
end

subgraph group_jobs["Async Jobs"]
  node_inngest_core["Job engine<br/>background jobs<br/>[functions.js]"]
end

subgraph group_data["Data Layer"]
  node_db[("DB access<br/>prisma client<br/>[db.js]")]
  node_schema["Prisma schema<br/>data model<br/>[schema.prisma]"]
  node_prisma_gen["Generated client<br/>generated types"]
end

subgraph group_runtime["External Runtime"]
  node_sandbox_template["Sandbox template<br/>isolated runtime"]
end

subgraph group_shared["Shared UI"]
  node_query_provider["Query provider<br/>client context<br/>[query-provider.jsx]"]
  node_theme_provider["Theme provider<br/>client context<br/>[theme-provider.jsx]"]
  node_ui_kit["UI kit<br/>component library"]
  node_usage_lib["Usage guard<br/>server policy<br/>[usage.js]"]
end

node_root_layout -->|"wraps"| node_public_routes
node_root_layout -->|"wraps"| node_project_route
node_root_layout -->|"hosts"| node_query_provider
node_root_layout -->|"hosts"| node_theme_provider
node_root_layout -->|"loads"| node_root_styles
node_public_routes -->|"signs in"| node_auth_module
node_public_routes -->|"renders"| node_home_ui
node_project_route -->|"composes"| node_workspace_ui
node_project_route -->|"mutates"| node_projects_actions
node_workspace_ui -->|"sends prompts"| node_messages_actions
node_workspace_ui -->|"uses"| node_message_hook
node_projects_actions -->|"reads/writes"| node_db
node_messages_actions -->|"reads/writes"| node_db
node_usage_actions -->|"checks"| node_usage_lib
node_usage_actions -->|"records"| node_db
node_messages_actions -->|"gates"| node_usage_actions
node_messages_actions -->|"uses"| node_prompt_def
node_messages_actions -->|"emits"| node_inngest_core
node_inngest_route -->|"invokes"| node_inngest_core
node_inngest_core -->|"runs in"| node_sandbox_template
node_inngest_core -->|"updates"| node_db
node_db -->|"backed by"| node_schema
node_db -->|"typed by"| node_prisma_gen
node_workspace_ui -->|"builds from"| node_ui_kit
node_home_ui -->|"builds from"| node_ui_kit

click node_root_layout "https://github.com/tirthbhatt1208/vibestudio/blob/main/src/app/layout.js"
click node_root_styles "https://github.com/tirthbhatt1208/vibestudio/blob/main/src/app/globals.css"
click node_public_routes "https://github.com/tirthbhatt1208/vibestudio/tree/main/src/app/(root)"
click node_project_route "https://github.com/tirthbhatt1208/vibestudio/blob/main/src/app/projects/[projectId]/page.jsx"
click node_inngest_route "https://github.com/tirthbhatt1208/vibestudio/blob/main/src/app/api/inngest/route.js"
click node_auth_module "https://github.com/tirthbhatt1208/vibestudio/blob/main/src/modules/auth/actions/index.js"
click node_home_ui "https://github.com/tirthbhatt1208/vibestudio/tree/main/src/modules/home/components"
click node_projects_actions "https://github.com/tirthbhatt1208/vibestudio/blob/main/src/modules/projects/actions/index.js"
click node_messages_actions "https://github.com/tirthbhatt1208/vibestudio/blob/main/src/modules/messages/actions/index.js"
click node_usage_actions "https://github.com/tirthbhatt1208/vibestudio/blob/main/src/modules/usage/actions/index.js"
click node_workspace_ui "https://github.com/tirthbhatt1208/vibestudio/tree/main/src/modules/projects/components"
click node_message_hook "https://github.com/tirthbhatt1208/vibestudio/blob/main/src/modules/messages/hooks/message.js"
click node_query_provider "https://github.com/tirthbhatt1208/vibestudio/blob/main/src/components/query-provider.jsx"
click node_theme_provider "https://github.com/tirthbhatt1208/vibestudio/blob/main/src/components/theme-provider.jsx"
click node_ui_kit "https://github.com/tirthbhatt1208/vibestudio/tree/main/src/components/ui"
click node_db "https://github.com/tirthbhatt1208/vibestudio/blob/main/src/lib/db.js"
click node_schema "https://github.com/tirthbhatt1208/vibestudio/blob/main/prisma/schema.prisma"
click node_prisma_gen "https://github.com/tirthbhatt1208/vibestudio/tree/main/generated/prisma"
click node_prompt_def "https://github.com/tirthbhatt1208/vibestudio/blob/main/src/prompt.js"
click node_inngest_core "https://github.com/tirthbhatt1208/vibestudio/blob/main/src/inngest/functions.js"
click node_sandbox_template "https://github.com/tirthbhatt1208/vibestudio/tree/main/sandbox-templates/next-js"
click node_usage_lib "https://github.com/tirthbhatt1208/vibestudio/blob/main/src/lib/usage.js"

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_root_styles,node_public_routes,node_project_route,node_inngest_route toneBlue
class node_auth_module,node_home_ui,node_projects_actions,node_messages_actions,node_usage_actions,node_workspace_ui,node_message_hook,node_prompt_def toneAmber
class node_inngest_core toneMint
class node_db,node_schema,node_prisma_gen toneRose
class node_sandbox_template toneIndigo
class node_query_provider,node_theme_provider,node_ui_kit,node_usage_lib toneTeal
```

## Components

### App Shell

Next.js routes, layout, and API entrypoints.

- [App layout](https://github.com/tirthbhatt1208/vibestudio/blob/main/src/app/layout.js): next shell · Global app wrapper and shell styles. · `src/app/layout.js`
- [Global styles](https://github.com/tirthbhatt1208/vibestudio/blob/main/src/app/globals.css): css · Application-wide styling entrypoint. · `src/app/globals.css`
- [Public pages](https://github.com/tirthbhatt1208/vibestudio/tree/main/src/app/(root)): routes · Landing, pricing, sign-in, and sign-up screens. · `src/app/(root)`
- [Project workspace](https://github.com/tirthbhatt1208/vibestudio/blob/main/src/app/projects/[projectId]/page.jsx): route · Main project detail workspace for prompt-driven generation. · `src/app/projects/[projectId]/page.jsx`
- [Inngest handler](https://github.com/tirthbhatt1208/vibestudio/blob/main/src/app/api/inngest/route.js): api route · Webhook boundary for background job execution. · `src/app/api/inngest/route.js`

### Feature Modules

Domain-specific server actions and UI pieces.

- [Auth module](https://github.com/tirthbhatt1208/vibestudio/blob/main/src/modules/auth/actions/index.js): server actions · Authentication-related actions and flows. · `src/modules/auth/actions/index.js`
- [Home screens](https://github.com/tirthbhatt1208/vibestudio/tree/main/src/modules/home/components): ui module · Landing/dashboard UI such as navbar, project list, and project form. · `src/modules/home/components`
- [Project actions](https://github.com/tirthbhatt1208/vibestudio/blob/main/src/modules/projects/actions/index.js): server actions · Server-side project workspace mutations and coordination. · `src/modules/projects/actions/index.js`
- [Message actions](https://github.com/tirthbhatt1208/vibestudio/blob/main/src/modules/messages/actions/index.js): server actions · Prompt and thread persistence plus message-related workflows. · `src/modules/messages/actions/index.js`
- [Usage actions](https://github.com/tirthbhatt1208/vibestudio/blob/main/src/modules/usage/actions/index.js): server actions · Quota, billing, and entitlement checks. · `src/modules/usage/actions/index.js`
- [Workspace UI](https://github.com/tirthbhatt1208/vibestudio/tree/main/src/modules/projects/components): ui module · Project header, messages, file tree, code view, and preview fragments. · `src/modules/projects/components`
- [Message hook](https://github.com/tirthbhatt1208/vibestudio/blob/main/src/modules/messages/hooks/message.js): client hook · Client-side message state helpers for the workspace. · `src/modules/messages/hooks/message.js`
- [Prompt config](https://github.com/tirthbhatt1208/vibestudio/blob/main/src/prompt.js): prompting · Prompt definitions and generation instructions. · `src/prompt.js`

### Async Jobs

Inngest background processing for generation work.

- [Job engine](https://github.com/tirthbhatt1208/vibestudio/blob/main/src/inngest/functions.js): background jobs · Inngest client, utilities, and function definitions. · `src/inngest/functions.js`

### Data Layer

Prisma schema, generated client, and shared DB access.

- [DB access](https://github.com/tirthbhatt1208/vibestudio/blob/main/src/lib/db.js): prisma client · Shared database access point. · `src/lib/db.js`
- [Prisma schema](https://github.com/tirthbhatt1208/vibestudio/blob/main/prisma/schema.prisma): data model · Core entities for users, projects, messages, fragments, and usage. · `prisma/schema.prisma`
- [Generated client](https://github.com/tirthbhatt1208/vibestudio/tree/main/generated/prisma): generated types · Generated Prisma client and model typings. · `generated/prisma`

### External Runtime

Isolated sandbox used to build and run generated apps.

- [Sandbox template](https://github.com/tirthbhatt1208/vibestudio/tree/main/sandbox-templates/next-js): isolated runtime · Next.js template used for executing generated code in isolation. · `sandbox-templates/next-js`

### Shared UI

Cross-cutting client providers, hooks, and reusable UI primitives.

- [Query provider](https://github.com/tirthbhatt1208/vibestudio/blob/main/src/components/query-provider.jsx): client context · App-wide server-state caching context. · `src/components/query-provider.jsx`
- [Theme provider](https://github.com/tirthbhatt1208/vibestudio/blob/main/src/components/theme-provider.jsx): client context · App-wide theme state and switching context. · `src/components/theme-provider.jsx`
- [UI kit](https://github.com/tirthbhatt1208/vibestudio/tree/main/src/components/ui): component library · Reusable shadcn-style primitives used across the app. · `src/components/ui`
- [Usage guard](https://github.com/tirthbhatt1208/vibestudio/blob/main/src/lib/usage.js): server policy · Shared usage and entitlement logic used before expensive generation work. · `src/lib/usage.js`

## Connections

- App layout → Public pages: wraps · Provides the shell for public pages.
- App layout → Project workspace: wraps · Provides the shell for the project workspace.
- App layout → Query provider: hosts · Mounts shared client state providers.
- App layout → Theme provider: hosts · Mounts shared theme state.
- App layout → Global styles: loads · Applies global styles across the app.
- Public pages → Auth module: signs in · Public auth screens trigger authentication actions.
- Public pages → Home screens: renders · Landing and dashboard-facing UI is assembled here.
- Project workspace → Workspace UI: composes · The project page is built from workspace components.
- Project workspace → Project actions: mutates · Workspace interactions call server actions.
- Workspace UI → Message actions: sends prompts · Composer and message thread interactions persist through message actions.
- Workspace UI → Message hook: uses · Client-side message state is coordinated with hook logic.
- Project actions → DB access: reads/writes · Project mutations persist through the database layer.
- Message actions → DB access: reads/writes · Messages and fragments are stored via Prisma.
- Usage actions → Usage guard: checks · Server actions enforce quota and entitlement rules.
- Usage actions → DB access: records · Usage is tracked in persistence.
- Message actions → Usage actions: gates · Prompt work is constrained by usage rules.
- Message actions → Prompt config: uses · Prompting behavior is defined in shared prompt config.
- Message actions → Job engine: emits · Prompt submissions enqueue background generation work.
- Inngest handler → Job engine: invokes · External job callbacks are handled by the job engine.
- Job engine → Sandbox template: runs in · Generated app work executes in the isolated sandbox.
- Job engine → DB access: updates · Background jobs persist results and state.
- DB access → Prisma schema: backed by · Schema defines the persistent entities.
- DB access → Generated client: typed by · Shared DB access uses generated Prisma types.
- Workspace UI → UI kit: builds from · Workspace screens are composed from reusable primitives.
- Home screens → UI kit: builds from · Home and auth-facing surfaces use the shared component kit.
