Next.js + tRPC Setup
This guide walks you through configuring Massu AI for a Next.js project that uses tRPC for API routing and Prisma for database access. This is the configuration that enables the most Massu AI features.
Prerequisites
- Next.js 13+ with App Router
- tRPC v10 or v11
- Prisma ORM
- Massu AI installed (Installation Guide)
Step 1: Configuration
Create massu.config.yaml in your project root:
project:
name: my-nextjs-app
root: auto
framework:
type: typescript
router: trpc
orm: prisma
ui: nextjs
paths:
source: src
aliases:
"@": src
"@/components": src/components
"@/lib": src/lib
middleware: src/middleware.ts
toolPrefix: massu
domains:
- name: orders
routers:
- "src/server/routers/orders*"
pages:
- "src/app/orders/**"
- "src/app/(dashboard)/orders/**"
components:
- "src/components/orders/**"
allowedImportsFrom:
- shared
- auth
- name: auth
routers:
- "src/server/routers/auth*"
pages:
- "src/app/auth/**"
- "src/app/login/**"
components:
- "src/components/auth/**"
allowedImportsFrom:
- shared
- name: shared
routers: []
pages: []
components:
- "src/components/ui/**"
- "src/lib/**"
allowedImportsFrom: []
rules:
- pattern: "src/server/**/*.ts"
severity: CRITICAL
rules:
- "All mutations must use protectedProcedure"
- "Never expose raw error details to clients"
- "Validate all inputs with Zod schemas"
- pattern: "src/app/**/page.tsx"
severity: HIGH
rules:
- "Pages must be server components by default"
- "Use Suspense boundaries for dynamic content"
- pattern: "src/middleware.ts"
severity: CRITICAL
rules:
- "No Node.js dependencies (Edge Runtime only)"
- "Keep middleware lightweight"
security:
auto_score_on_edit: true
score_threshold_alert: 40
analytics:
cost:
models:
claude-opus-4-6:
input_per_million: 15
output_per_million: 75
cache_read_per_million: 1.5
cache_write_per_million: 3.75
currency: USDStep 2: Initial Sync
Start Claude Code and run the initial sync:
> Run massu_sync to index the codebaseWith tRPC configured, you should see tRPC procedure mapping in the output:
Indexes rebuilt:
Import edges: 342
tRPC procedures: 84 (62 with UI, 22 without)
Page deps: 31 pages
Middleware tree: 12 filesStep 3: Verify tRPC Mapping
Check that tRPC mapping is working:
> Run massu_trpc_map with uncoupled: trueThis shows procedures without UI callers -- potential dead code in your API layer.
Step 4: Verify Domain Boundaries
> Run massu_domains with crossings: trueThis shows cross-domain import violations based on your domain configuration.
Step 5: Check Middleware Tree
> Run massu_context for src/middleware.tsVerify the middleware tree analysis is working. Any file in the middleware import chain will get Edge Runtime warnings.
Tips for Next.js Projects
- Set
paths.middlewareto enable middleware tree analysis and Edge Runtime warnings - Configure domains to match your Next.js route groups
- The
massu_schematool works with Prisma to catch column name mismatches - Use
massu_coupling_checkto find tRPC procedures that no UI component calls - The
post-edit-contexthook will warn about Edge Runtime restrictions when editing middleware-tree files