Architecture Overview
How Next.js App Router, tRPC, Better Auth, and Prisma connect.
VibeKit uses a modern fullstack TypeScript architecture designed for maintainability and type safety.
Request flow
When a user visits your app or submits a form, the request flows through these layers:
- Client / Browser: React 19 components in
apps/webrender UI using Tailwind CSS and Radix UI. Form submissions and queries call tRPC procedures via@trpc/react-query. - Next.js App Router: Next.js handles server rendering, flat routes (no locale prefix), layout composition, and route handlers (
/api/[trpc],/api/webhooks/stripe). - Context & Authentication: Better Auth in
packages/authextracts and validates theauth_sessioncookie, loading the user session into the tRPC request context. - tRPC Procedures: Procedures in
packages/apivalidate incoming inputs with Zod and apply authorization middleware (publicProcedure,protectedProcedure,adminProcedure). - Database Layer: Prisma Client in
packages/databasequeries PostgreSQL with full TypeScript type inference.
End-to-end type safety
If you rename a database column or modify an API input schema, TypeScript immediately flags any mismatch across backend procedures and frontend components.
Design principles
- Explicit trust boundaries: Input data is always validated with Zod on the server. Authorization checks run server-side even if the UI hides a button.
- Isolated package workspaces: Core utilities, auth logic, and payment adapters live in reusable packages without depending on web-specific globals.
- Unified database schema:
schema.prismaserves as the single source of truth for database models, migrations, and derived Zod validation schemas. - Plain language documentation: Every feature is documented with actionable commands and straightforward explanations.
Read next: Database & ORM.