# nileshdhakad18/autosite-studio architecture

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

- Interactive diagram: https://gitdiagram.com/nileshdhakad18/autosite-studio
- Repository: https://github.com/nileshdhakad18/autosite-studio

## Overview

#### Purpose and Runtime
This is a Next.js application for AI-assisted project/code generation. Users create projects, submit messages, and view generated code/files and sandbox output. The browser app runs through Next.js; generation executes asynchronously through Inngest workers and requires a Prisma-backed database.

Entry points:
- App shell and routes: `src/app/layout.tsx`, `src/app/(home)/page.tsx`, `src/app/projects/[projectId]/page.tsx`
- tRPC API boundary: `src/app/api/trpc/[trpc]/route.ts`
- Inngest webhook/function endpoint: `src/app/api/inngest/route.ts`

#### Identity, Routing, and UI Surfaces
Home routes provide landing, pricing, and Clerk-style catch-all sign-in/sign-up pages. Middleware is the likely request/auth enforcement boundary.
- `src/app/(home)/layout.tsx`
- `src/app/(home)/sign-in/[[...sign-in]]/page.tsx`
- `src/middleware.ts`

The authenticated working surface is a project page composed around messaging, generated fragments, file navigation, and embedded rendered output.
- `src/modules/projects/ui/views/project-view.tsx`
- `src/modules/projects/ui/components/messages-container.tsx`
- `src/modules/projects/ui/components/fragment-web.tsx`

#### Typed Application API
tRPC is the primary frontend-to-server control plane. Router initialization and client/server adapters isolate UI from database and orchestration implementation.
- `src/trpc/init.ts`
- `src/trpc/routers/_app.ts`
- `src/trpc/client.tsx`

Domain procedures define the principal synchronous operations: project lifecycle, message submission/retrieval, and usage querying/enforcement.
- `src/modules/projects/server/procedures.ts`
- `src/modules/messages/server/procedures.ts`
- `src/modules/usage/server/procedures.ts`

#### Persistence Model
Prisma centralizes durable state for projects, messages/fragments, authentication-related records, and usage. Database schema/migrations are the contract between synchronous procedures and background generation.
- `prisma/schema.prisma`
- `prisma/migrations/20250708060121_message_fragment/migration.sql`
- `prisma/migrations/20250711195541_usage/migration.sql`

The database client and usage logic form shared server-side infrastructure.
- `src/lib/db.ts`
- `src/lib/usage.ts`

#### Asynchronous Agent Pipeline
Submitting a message crosses from tRPC procedures into Inngest event-driven functions. Inngest provides queued, observable, step-based execution for LLM agent work, tool use, code/file writes, summaries, and sandbox activity.
- `src/inngest/client.ts`
- `src/inngest/functions.ts`
- `src/inngest/types.ts`

This boundary keeps long-running generation outside request/response handling. Worker functions persist generated artifacts/status back to Prisma for subsequent UI reads.

#### Code Generation and Sandbox Boundary
Agent behavior is defined by the project prompt and Inngest utilities. Generated applications target a Next.js sandbox template, whose container/build configuration establishes the isolated execution environment.
- `src/prompt.ts`
- `src/inngest/utils.ts`
- `sandbox-templates/nextjs/e2b.Dockerfile`

Sandbox compilation is explicitly represented by:
- `sandbox-templates/nextjs/compile_page.sh`
- `sandbox-templates/nextjs/e2b.toml`

#### Primary Flow
1. User authenticates and creates/selects a project from home UI.
2. Project UI sends typed tRPC mutations for messages and project state.
3. Server procedures validate persistence/usage concerns, write records, and trigger Inngest work.
4. Inngest functions run the agent and sandbox operations asynchronously.
5. Generated messages, fragments, files, and sandbox results are saved in Prisma.
6. The project view reloads/query-updates and renders messages, file explorer/code view, and fragment preview.

External/runtime dependencies materially include Next.js, Prisma/database, Inngest, an LLM/tooling layer implied by the agent pipeline, and an E2B-oriented sandbox template.

Main entry points: [`src/modules/messages/server/procedures.ts`](https://github.com/nileshdhakad18/autosite-studio/blob/main/src/modules/messages/server/procedures.ts) (Project, message, and usage procedures), [`src/inngest/functions.ts`](https://github.com/nileshdhakad18/autosite-studio/blob/main/src/inngest/functions.ts) (Generation workers), [`src/modules/projects/ui/views/project-view.tsx`](https://github.com/nileshdhakad18/autosite-studio/blob/main/src/modules/projects/ui/views/project-view.tsx) (Project workspace), [`src/trpc/routers/_app.ts`](https://github.com/nileshdhakad18/autosite-studio/blob/main/src/trpc/routers/_app.ts) (tRPC router and adapters)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Next.js web app"]
  node_home["Home and auth routes<br/>Next.js routes<br/>[page.tsx]"]
  node_middleware["Auth middleware<br/>request boundary<br/>[middleware.ts]"]
  node_project_page["Project route<br/>Next.js route<br/>[page.tsx]"]
  node_project_view["Project workspace<br/>UI view<br/>[project-view.tsx]"]
end

subgraph group_api["Application API"]
  node_trpc_route["tRPC endpoint<br/>API route<br/>[route.ts]"]
  node_trpc_core["tRPC router and adapters<br/>typed API<br/>[_app.ts]"]
  node_domain_procedures["Project, message, and usage procedures<br/>server procedures<br/>[procedures.ts]"]
end

subgraph group_worker["Generation pipeline"]
  node_inngest_route["Inngest endpoint<br/>webhook route<br/>[route.ts]"]
  node_inngest_functions["Generation workers<br/>Inngest functions<br/>[functions.ts]"]
  node_agent_logic["Prompt and agent tools<br/>generation logic<br/>[utils.ts]"]
end

subgraph group_data["Persistence"]
  node_prisma_schema["Prisma data contract<br/>schema and migrations<br/>[schema.prisma]"]
  node_db_client["Prisma client<br/>database access<br/>[db.ts]"]
  node_database[("Database<br/>durable store")]
  node_usage_logic["Usage enforcement<br/>shared server logic<br/>[usage.ts]"]
end

subgraph group_sandbox["Sandbox"]
  node_sandbox_compile["Sandbox compilation<br/>build script<br/>[compile_page.sh]"]
  node_sandbox_image{{"Next.js sandbox image<br/>container template<br/>[e2b.Dockerfile]"}}
end

node_home -->|"requests pass through"| node_middleware
node_middleware -->|"authorizes access"| node_project_page
node_project_page -->|"renders"| node_project_view
node_project_view -->|"queries and mutations"| node_trpc_core
node_trpc_route -->|"serves"| node_trpc_core
node_trpc_core -->|"dispatches"| node_domain_procedures
node_domain_procedures -->|"checks limits"| node_usage_logic
node_domain_procedures -->|"reads and writes"| node_db_client
node_domain_procedures -->|"triggers generation"| node_inngest_functions
node_inngest_route -->|"registers and invokes"| node_inngest_functions
node_inngest_functions -->|"runs agent steps"| node_agent_logic
node_agent_logic -->|"generates and builds app"| node_sandbox_compile
node_sandbox_compile -->|"executes in"| node_sandbox_image
node_inngest_functions -->|"persists artifacts and status"| node_db_client
node_db_client -->|"accesses"| node_database
node_prisma_schema -.->|"defines"| node_database
node_project_view -.->|"browser transport"| node_trpc_route

click node_home "https://github.com/nileshdhakad18/autosite-studio/blob/main/src/app/(home)/page.tsx"
click node_middleware "https://github.com/nileshdhakad18/autosite-studio/blob/main/src/middleware.ts"
click node_project_page "https://github.com/nileshdhakad18/autosite-studio/blob/main/src/app/projects/%5BprojectId%5D/page.tsx"
click node_project_view "https://github.com/nileshdhakad18/autosite-studio/blob/main/src/modules/projects/ui/views/project-view.tsx"
click node_trpc_route "https://github.com/nileshdhakad18/autosite-studio/blob/main/src/app/api/trpc/%5Btrpc%5D/route.ts"
click node_trpc_core "https://github.com/nileshdhakad18/autosite-studio/blob/main/src/trpc/routers/_app.ts"
click node_domain_procedures "https://github.com/nileshdhakad18/autosite-studio/blob/main/src/modules/messages/server/procedures.ts"
click node_inngest_route "https://github.com/nileshdhakad18/autosite-studio/blob/main/src/app/api/inngest/route.ts"
click node_inngest_functions "https://github.com/nileshdhakad18/autosite-studio/blob/main/src/inngest/functions.ts"
click node_agent_logic "https://github.com/nileshdhakad18/autosite-studio/blob/main/src/inngest/utils.ts"
click node_sandbox_compile "https://github.com/nileshdhakad18/autosite-studio/blob/main/sandbox-templates/nextjs/compile_page.sh"
click node_sandbox_image "https://github.com/nileshdhakad18/autosite-studio/blob/main/sandbox-templates/nextjs/e2b.Dockerfile"
click node_prisma_schema "https://github.com/nileshdhakad18/autosite-studio/blob/main/prisma/schema.prisma"
click node_db_client "https://github.com/nileshdhakad18/autosite-studio/blob/main/src/lib/db.ts"
click node_usage_logic "https://github.com/nileshdhakad18/autosite-studio/blob/main/src/lib/usage.ts"

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_home,node_middleware,node_project_page,node_project_view toneBlue
class node_trpc_route,node_trpc_core,node_domain_procedures toneAmber
class node_inngest_route,node_inngest_functions,node_agent_logic toneMint
class node_prisma_schema,node_db_client,node_database,node_usage_logic toneRose
class node_sandbox_compile,node_sandbox_image toneIndigo
```

## Components

### Next.js web app

- [Home and auth routes](https://github.com/nileshdhakad18/autosite-studio/blob/main/src/app/(home)/page.tsx): Next.js routes · Landing, project entry, and sign-in surfaces. · `src/app/(home)/page.tsx`
- [Auth middleware](https://github.com/nileshdhakad18/autosite-studio/blob/main/src/middleware.ts): request boundary · `src/middleware.ts`
- [Project route](https://github.com/nileshdhakad18/autosite-studio/blob/main/src/app/projects/%5BprojectId%5D/page.tsx): Next.js route · `src/app/projects/[projectId]/page.tsx`
- [Project workspace](https://github.com/nileshdhakad18/autosite-studio/blob/main/src/modules/projects/ui/views/project-view.tsx): UI view · Messages, generated files, and rendered fragments. · `src/modules/projects/ui/views/project-view.tsx`

### Application API

- [tRPC endpoint](https://github.com/nileshdhakad18/autosite-studio/blob/main/src/app/api/trpc/%5Btrpc%5D/route.ts): API route · `src/app/api/trpc/[trpc]/route.ts`
- [tRPC router and adapters](https://github.com/nileshdhakad18/autosite-studio/blob/main/src/trpc/routers/_app.ts): typed API · Connects UI clients to domain procedures. · `src/trpc/routers/_app.ts`
- [Project, message, and usage procedures](https://github.com/nileshdhakad18/autosite-studio/blob/main/src/modules/messages/server/procedures.ts): server procedures · Handles synchronous lifecycle, submission, retrieval, and limits. · `src/modules/messages/server/procedures.ts`

### Generation pipeline

- [Inngest endpoint](https://github.com/nileshdhakad18/autosite-studio/blob/main/src/app/api/inngest/route.ts): webhook route · `src/app/api/inngest/route.ts`
- [Generation workers](https://github.com/nileshdhakad18/autosite-studio/blob/main/src/inngest/functions.ts): Inngest functions · Runs long-lived agent, tool, and artifact-generation steps. · `src/inngest/functions.ts`
- [Prompt and agent tools](https://github.com/nileshdhakad18/autosite-studio/blob/main/src/inngest/utils.ts): generation logic · `src/inngest/utils.ts`

### Persistence

- [Prisma data contract](https://github.com/nileshdhakad18/autosite-studio/blob/main/prisma/schema.prisma): schema and migrations · Defines projects, messages, fragments, auth records, and usage. · `prisma/schema.prisma`
- [Prisma client](https://github.com/nileshdhakad18/autosite-studio/blob/main/src/lib/db.ts): database access · `src/lib/db.ts`
- **Database**: durable store
- [Usage enforcement](https://github.com/nileshdhakad18/autosite-studio/blob/main/src/lib/usage.ts): shared server logic · `src/lib/usage.ts`

### Sandbox

- [Sandbox compilation](https://github.com/nileshdhakad18/autosite-studio/blob/main/sandbox-templates/nextjs/compile_page.sh): build script · `sandbox-templates/nextjs/compile_page.sh`
- [Next.js sandbox image](https://github.com/nileshdhakad18/autosite-studio/blob/main/sandbox-templates/nextjs/e2b.Dockerfile): container template · Isolated E2B-oriented generation runtime. · `sandbox-templates/nextjs/e2b.Dockerfile`

## Connections

- Home and auth routes → Auth middleware: requests pass through
- Auth middleware → Project route: authorizes access
- Project route → Project workspace: renders
- Project workspace → tRPC router and adapters: queries and mutations
- tRPC endpoint → tRPC router and adapters: serves
- tRPC router and adapters → Project, message, and usage procedures: dispatches
- Project, message, and usage procedures → Usage enforcement: checks limits
- Project, message, and usage procedures → Prisma client: reads and writes
- Project, message, and usage procedures → Generation workers: triggers generation
- Inngest endpoint → Generation workers: registers and invokes
- Generation workers → Prompt and agent tools: runs agent steps
- Prompt and agent tools → Sandbox compilation: generates and builds app
- Sandbox compilation → Next.js sandbox image: executes in
- Generation workers → Prisma client: persists artifacts and status
- Prisma client → Database: accesses
- Prisma data contract → Database: defines
- Project workspace → tRPC endpoint: browser transport
