How nileshdhakad18/autosite-studio works
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: procedures.ts Project, message, and usage procedures · functions.ts Generation workers · project-view.tsx Project workspace · _app.ts tRPC router and adapters
Components 16
Next.js web app
- Home and auth routes · Landing, project entry, and sign-in surfaces.
src/app/(home)/page.tsx - Auth middleware
src/middleware.ts - Project route
src/app/projects/[projectId]/page.tsx - Project workspace · Messages, generated files, and rendered fragments.
src/modules/projects/ui/views/project-view.tsx
Application API
- tRPC endpoint
src/app/api/trpc/[trpc]/route.ts - tRPC router and adapters · Connects UI clients to domain procedures.
src/trpc/routers/_app.ts - Project, message, and usage procedures · Handles synchronous lifecycle, submission, retrieval, and limits.
src/modules/messages/server/procedures.ts
Generation pipeline
- Inngest endpoint
src/app/api/inngest/route.ts - Generation workers · Runs long-lived agent, tool, and artifact-generation steps.
src/inngest/functions.ts - Prompt and agent tools
src/inngest/utils.ts
Persistence
- Prisma data contract · Defines projects, messages, fragments, auth records, and usage.
prisma/schema.prisma - Prisma client
src/lib/db.ts - Database
- Usage enforcement
src/lib/usage.ts
Sandbox
- Sandbox compilation
sandbox-templates/nextjs/compile_page.sh - Next.js sandbox image · Isolated E2B-oriented generation runtime.
sandbox-templates/nextjs/e2b.Dockerfile
Connections 17
- 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