# viplavkhode/vibe architecture

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

- Interactive diagram: https://gitdiagram.com/viplavkhode/vibe
- Repository: https://github.com/viplavkhode/vibe

## Overview

1. **Overall shape**
   - This is a Next.js 15 App Router application organized around two big concerns: the public marketing/auth experience and the authenticated “project builder” experience.
   - The codebase is split into presentation routes in `src/app`, feature modules in `src/modules`, shared infrastructure in `src/lib`, `src/trpc`, and `src/inngest`, plus Prisma schema/migrations and sandbox templates.

2. **User-facing route surface**
   - `src/app/(home)` contains the landing page, pricing page, and Clerk sign-in/sign-up flows.
   - `src/app/projects/[projectId]` is the authenticated project workspace, which is where users inspect a generated project, send messages/prompts, and view preview/code-related UI.
   - `src/app/error.tsx` and `src/app/layout.tsx` provide the global shell/error handling for the app.

3. **Feature-module boundaries**
   - `src/modules/home` owns the home-page UI pieces such as the navbar, project form, and project list.
   - `src/modules/projects` owns the project workspace UI: header, message composer, message list/cards, loading states, usage display, and project view switching.
   - `src/modules/messages` and `src/modules/usage` hold server-side procedures for those domains, keeping business logic out of route components.

4. **Client/server API layer**
   - The app uses **tRPC** for type-safe server communication.
   - `src/app/api/trpc/[trpc]/route.ts` exposes the tRPC HTTP endpoint, while `src/trpc/*` contains the client, server initialization, query client, and router composition.
   - Domain procedures live in `src/modules/*/server/procedures.ts`, then get composed into the root router in `src/trpc/routers/_app.ts`.

5. **Persistence layer**
   - Prisma is the main persistence boundary: `prisma/schema.prisma` and the migrations define the data model.
   - The presence of migrations for `projects`, `user_id`, and `usage` indicates at least three core stored entities/concerns: project records, user ownership, and consumption tracking.
   - `src/lib/db.ts` is the shared DB access point, and `src/lib/usage.ts` likely encapsulates metering/credit logic used by usage-related procedures.

6. **Authentication and request gating**
   - Clerk is the auth provider, reflected in the sign-in/sign-up routes and the environment variables documented in the README.
   - `src/middleware.ts` is the main request gate for authenticated sections and route protection, so auth decisions likely happen before the project workspace or API layer is reached.
   - `src/components/user-controls.tsx` suggests the authenticated header/account controls live in the shared UI shell.

7. **Background orchestration**
   - The repo has a dedicated Inngest integration under `src/inngest`, with `client.ts`, `functions.ts`, and `util.ts`, plus an API handler at `src/app/api/inngest/route.ts`.
   - This is the async execution boundary for prompt processing, generation, validation, or other long-running tasks described in the README.
   - `.inngest/main.db` suggests local Inngest state is used in development.

8. **Generated-app runtime / sandbox boundary**
   - `sandbox-templates/nextjs` contains a Dockerfile, E2B config, and compile script for running generated apps in isolated sandboxes.
   - This is a distinct runtime from the main Next.js app: the builder generates code here, but execution/preview happens in sandboxed environments rather than inside the host app process.
   - That boundary is important for the architecture diagram because preview execution is intentionally isolated from the product UI/API.

9. **Project workspace UI flow**
   - The project detail page likely composes the message stream, project header, preview/code views, and usage widgets from `src/modules/projects/ui`.
   - Components like `file-explorer`, `tree-view`, and `code-view` support the “inspect generated code” experience described in the README.
   - `project-views.tsx` and `fragment-web.tsx` suggest the workspace can switch between preview and code/navigation-oriented views.

10. **Shared UI and design system**
   - The repo uses a large shared component set in `src/components/ui`, which is consistent with a Shadcn/Radix-based design system.
   - This shared layer feeds both marketing pages and the project workspace, so the diagram should treat it as a cross-cutting presentation library rather than a separate business subsystem.

11. **Operational concerns**
   - `src/modules/usage` and `src/lib/usage.ts` show metering/credits are first-class product logic, not just analytics.
   - The README’s billing mention plus the `usage` schema migration imply the system must enforce or display quota/credit state during generation workflows.

12. **End-to-end data flow**
   - A user enters the app through the home/auth routes, authenticates with Clerk, and creates or opens a project.
   - The project workspace sends typed actions through tRPC into server procedures, which read/write Prisma records and may enqueue Inngest jobs for long-running generation.
   - Inngest-driven work produces code/artifacts and triggers sandbox validation/preview setup, while the UI reads back project state, messages, and usage to render the live builder experience.

Main entry points: [`src/trpc/routers/_app.ts`](https://github.com/viplavkhode/vibe/blob/main/src/trpc/routers/_app.ts) (tRPC core), [`src/app/projects/[projectId]/page.tsx`](https://github.com/viplavkhode/vibe/blob/main/src/app/projects/[projectId]/page.tsx) (Project workspace), [`src/modules/projects/ui/components/project-header.tsx`](https://github.com/viplavkhode/vibe/blob/main/src/modules/projects/ui/components/project-header.tsx) (Project UI), [`src/inngest/functions.ts`](https://github.com/viplavkhode/vibe/blob/main/src/inngest/functions.ts) (Inngest jobs)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["App routes"]
  node_layout["App shell<br/>next layout<br/>[layout.tsx]"]
  node_error["Error page<br/>next error<br/>[error.tsx]"]
  node_home_page["Landing<br/>marketing route<br/>[page.tsx]"]
  node_pricing_page["Pricing<br/>marketing route<br/>[page.tsx]"]
  node_auth_routes["Auth pages<br/>clerk routes<br/>[page.tsx]"]
  node_project_page["Project workspace<br/>workspace route<br/>[page.tsx]"]
end

subgraph group_features["Feature modules"]
  node_home_module["Home module<br/>feature UI<br/>[navbar.tsx]"]
  node_projects_ui["Project UI<br/>feature UI<br/>[project-header.tsx]"]
  node_projects_server["Projects API<br/>tRPC procedures<br/>[procedures.ts]"]
  node_messages_server["Messages API<br/>tRPC procedures<br/>[procedures.ts]"]
  node_usage_server["Usage API<br/>tRPC procedures<br/>[procedures.ts]"]
end

subgraph group_infra["Infrastructure"]
  node_trpc_route["tRPC route<br/>http endpoint<br/>[route.ts]"]
  node_trpc_core["tRPC core<br/>rpc runtime<br/>[_app.ts]"]
  node_middleware["Auth gate<br/>middleware<br/>[middleware.ts]"]
  node_db[("Database<br/>prisma<br/>[db.ts]")]
  node_usage_lib["Usage logic<br/>metering<br/>[usage.ts]"]
  node_inngest_api["Inngest API<br/>webhook endpoint<br/>[route.ts]"]
  node_inngest_runtime["Inngest jobs<br/>background jobs<br/>[functions.ts]"]
end

subgraph group_ui["Shared UI"]
  node_shared_ui["UI kit<br/>design system<br/>[button.tsx]"]
  node_file_tools["Code browser<br/>workspace UI<br/>[index.tsx]"]
  node_user_controls["User controls<br/>account ui<br/>[user-controls.tsx]"]
end

subgraph group_sandbox["Sandbox runtime"]
  node_sandbox_templates["Sandbox template<br/>runtime template<br/>[e2b.toml]"]
end

node_layout -->|"wraps"| node_home_page
node_layout -->|"wraps"| node_project_page
node_layout -->|"handles"| node_error
node_home_page -->|"uses"| node_home_module
node_pricing_page -->|"uses"| node_shared_ui
node_auth_routes -->|"uses"| node_shared_ui
node_project_page -->|"composes"| node_projects_ui
node_project_page -->|"uses"| node_file_tools
node_project_page -->|"uses"| node_user_controls
node_projects_ui -->|"calls"| node_messages_server
node_projects_ui -->|"calls"| node_projects_server
node_projects_ui -->|"calls"| node_usage_server
node_projects_server -->|"registered in"| node_trpc_core
node_messages_server -->|"registered in"| node_trpc_core
node_usage_server -->|"registered in"| node_trpc_core
node_trpc_core -->|"served by"| node_trpc_route
node_trpc_core -->|"reads/writes"| node_db
node_trpc_core -->|"uses"| node_usage_lib
node_middleware -->|"protects"| node_project_page
node_middleware -->|"protects"| node_trpc_route
node_inngest_api -->|"dispatches"| node_inngest_runtime
node_trpc_core -->|"enqueues"| node_inngest_runtime
node_inngest_runtime -->|"uses"| node_sandbox_templates
node_inngest_runtime -->|"updates"| node_db

click node_layout "https://github.com/viplavkhode/vibe/blob/main/src/app/layout.tsx"
click node_error "https://github.com/viplavkhode/vibe/blob/main/src/app/error.tsx"
click node_home_page "https://github.com/viplavkhode/vibe/blob/main/src/app/(home)/page.tsx"
click node_pricing_page "https://github.com/viplavkhode/vibe/blob/main/src/app/(home)/pricing/page.tsx"
click node_auth_routes "https://github.com/viplavkhode/vibe/blob/main/src/app/(home)/sign-in/[[...sign-in]]/page.tsx"
click node_project_page "https://github.com/viplavkhode/vibe/blob/main/src/app/projects/[projectId]/page.tsx"
click node_home_module "https://github.com/viplavkhode/vibe/blob/main/src/modules/home/ui/components/navbar.tsx"
click node_projects_ui "https://github.com/viplavkhode/vibe/blob/main/src/modules/projects/ui/components/project-header.tsx"
click node_projects_server "https://github.com/viplavkhode/vibe/blob/main/src/modules/projects/server/procedures.ts"
click node_messages_server "https://github.com/viplavkhode/vibe/blob/main/src/modules/messages/server/procedures.ts"
click node_usage_server "https://github.com/viplavkhode/vibe/blob/main/src/modules/usage/server/procedures.ts"
click node_trpc_route "https://github.com/viplavkhode/vibe/blob/main/src/app/api/trpc/[trpc]/route.ts"
click node_trpc_core "https://github.com/viplavkhode/vibe/blob/main/src/trpc/routers/_app.ts"
click node_middleware "https://github.com/viplavkhode/vibe/blob/main/src/middleware.ts"
click node_db "https://github.com/viplavkhode/vibe/blob/main/src/lib/db.ts"
click node_usage_lib "https://github.com/viplavkhode/vibe/blob/main/src/lib/usage.ts"
click node_inngest_api "https://github.com/viplavkhode/vibe/blob/main/src/app/api/inngest/route.ts"
click node_inngest_runtime "https://github.com/viplavkhode/vibe/blob/main/src/inngest/functions.ts"
click node_shared_ui "https://github.com/viplavkhode/vibe/blob/main/src/components/ui/button.tsx"
click node_file_tools "https://github.com/viplavkhode/vibe/blob/main/src/components/code-view/index.tsx"
click node_user_controls "https://github.com/viplavkhode/vibe/blob/main/src/components/user-controls.tsx"
click node_sandbox_templates "https://github.com/viplavkhode/vibe/blob/main/sandbox-templates/nextjs/e2b.toml"

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_layout,node_error,node_home_page,node_pricing_page,node_auth_routes,node_project_page toneBlue
class node_home_module,node_projects_ui,node_projects_server,node_messages_server,node_usage_server toneAmber
class node_trpc_route,node_trpc_core,node_middleware,node_db,node_usage_lib,node_inngest_api,node_inngest_runtime toneMint
class node_shared_ui,node_file_tools,node_user_controls toneRose
class node_sandbox_templates toneIndigo
```

## Components

### App routes

Next.js App Router surface for marketing, auth, and the authenticated workspace.

- [App shell](https://github.com/viplavkhode/vibe/blob/main/src/app/layout.tsx): next layout · Global app layout and error handling. · `src/app/layout.tsx`
- [Error page](https://github.com/viplavkhode/vibe/blob/main/src/app/error.tsx): next error · Global route error boundary. · `src/app/error.tsx`
- [Landing](https://github.com/viplavkhode/vibe/blob/main/src/app/(home)/page.tsx): marketing route · Public home page and entry experience. · `src/app/(home)/page.tsx`
- [Pricing](https://github.com/viplavkhode/vibe/blob/main/src/app/(home)/pricing/page.tsx): marketing route · Public pricing page. · `src/app/(home)/pricing/page.tsx`
- [Auth pages](https://github.com/viplavkhode/vibe/blob/main/src/app/(home)/sign-in/[[...sign-in]]/page.tsx): clerk routes · Sign-in and sign-up flows. · `src/app/(home)/sign-in/[[...sign-in]]/page.tsx`
- [Project workspace](https://github.com/viplavkhode/vibe/blob/main/src/app/projects/[projectId]/page.tsx): workspace route · Authenticated project detail and builder surface. · `src/app/projects/[projectId]/page.tsx`

### Feature modules

Domain-specific UI and server procedures.

- [Home module](https://github.com/viplavkhode/vibe/blob/main/src/modules/home/ui/components/navbar.tsx): feature UI · Home-page composition and project entry UI. · `src/modules/home/ui/components/navbar.tsx`
- [Project UI](https://github.com/viplavkhode/vibe/blob/main/src/modules/projects/ui/components/project-header.tsx): feature UI · Workspace header, messaging, loading, usage, and view switching. · `src/modules/projects/ui/components/project-header.tsx`
- [Projects API](https://github.com/viplavkhode/vibe/blob/main/src/modules/projects/server/procedures.ts): tRPC procedures · Server procedures for project operations. · `src/modules/projects/server/procedures.ts`
- [Messages API](https://github.com/viplavkhode/vibe/blob/main/src/modules/messages/server/procedures.ts): tRPC procedures · Server procedures for messaging and prompt flow. · `src/modules/messages/server/procedures.ts`
- [Usage API](https://github.com/viplavkhode/vibe/blob/main/src/modules/usage/server/procedures.ts): tRPC procedures · Server procedures for metering and quota state. · `src/modules/usage/server/procedures.ts`

### Infrastructure

Shared persistence, API, auth gating, and background execution.

- [tRPC route](https://github.com/viplavkhode/vibe/blob/main/src/app/api/trpc/[trpc]/route.ts): http endpoint · HTTP entrypoint for typed client-server calls. · `src/app/api/trpc/[trpc]/route.ts`
- [tRPC core](https://github.com/viplavkhode/vibe/blob/main/src/trpc/routers/_app.ts): rpc runtime · Client, server init, query client, and router wiring. · `src/trpc/routers/_app.ts`
- [Auth gate](https://github.com/viplavkhode/vibe/blob/main/src/middleware.ts): middleware · Request gating and route protection. · `src/middleware.ts`
- [Database](https://github.com/viplavkhode/vibe/blob/main/src/lib/db.ts): prisma · Shared Prisma access and persisted application state. · `src/lib/db.ts`
- [Usage logic](https://github.com/viplavkhode/vibe/blob/main/src/lib/usage.ts): metering · Shared quota and credit helpers. · `src/lib/usage.ts`
- [Inngest API](https://github.com/viplavkhode/vibe/blob/main/src/app/api/inngest/route.ts): webhook endpoint · HTTP handler for background job events. · `src/app/api/inngest/route.ts`
- [Inngest jobs](https://github.com/viplavkhode/vibe/blob/main/src/inngest/functions.ts): background jobs · Async orchestration for generation and long-running work. · `src/inngest/functions.ts`

### Shared UI

Reusable presentation components and hooks.

- [UI kit](https://github.com/viplavkhode/vibe/blob/main/src/components/ui/button.tsx): design system · Reusable shared components across routes and features. · `src/components/ui/button.tsx`
- [Code browser](https://github.com/viplavkhode/vibe/blob/main/src/components/code-view/index.tsx): workspace UI · File explorer, tree view, and code display for generated projects. · `src/components/code-view/index.tsx`
- [User controls](https://github.com/viplavkhode/vibe/blob/main/src/components/user-controls.tsx): account ui · Authenticated header/account controls. · `src/components/user-controls.tsx`

### Sandbox runtime

Isolated generated-app execution and build environment.

- [Sandbox template](https://github.com/viplavkhode/vibe/blob/main/sandbox-templates/nextjs/e2b.toml): runtime template · Next.js sandbox build and compile environment for generated apps. · `sandbox-templates/nextjs/e2b.toml`

## Connections

- App shell → Landing: wraps · Provides the global shell for public pages.
- App shell → Project workspace: wraps · Provides the global shell for the authenticated workspace.
- App shell → Error page: handles · Displays route-level failures.
- Landing → Home module: uses · Composes landing-page sections and entry forms.
- Pricing → UI kit: uses · Renders marketing UI from the shared component kit.
- Auth pages → UI kit: uses · Builds Clerk auth screens with shared UI primitives.
- Project workspace → Project UI: composes · Assembles the workspace from feature UI pieces.
- Project workspace → Code browser: uses · Surfaces generated files and code views.
- Project workspace → User controls: uses · Shows authenticated account actions in the shell.
- Project UI → Messages API: calls · Loads and mutates message state through typed procedures.
- Project UI → Projects API: calls · Reads project state and workspace metadata.
- Project UI → Usage API: calls · Displays usage and quota state.
- Projects API → tRPC core: registered in · Composed into the root application router.
- Messages API → tRPC core: registered in · Composed into the root application router.
- Usage API → tRPC core: registered in · Composed into the root application router.
- tRPC core → tRPC route: served by · Exposed over the HTTP API.
- tRPC core → Database: reads/writes · Uses Prisma-backed persistence.
- tRPC core → Usage logic: uses · Applies shared metering logic.
- Auth gate → Project workspace: protects · Gates authenticated workspace routes.
- Auth gate → tRPC route: protects · Constrains access to typed API calls.
- Inngest API → Inngest jobs: dispatches · Hands off incoming events to background jobs.
- tRPC core → Inngest jobs: enqueues · Triggers long-running generation and validation work.
- Inngest jobs → Sandbox template: uses · Builds and runs generated apps in isolated sandboxes.
- Inngest jobs → Database: updates · Persists generation results and workflow state.
