Type-Safe Full-Stack APIs with tRPC & Prisma
Build end-to-end type-safe APIs using tRPC, Prisma, Next.js, and TypeScript in Claude Code for seamless developer experience.
# Type-Safe Full-Stack Development with tRPC/Prisma
In Claude Code CLI, guide users to create fully type-shared APIs. Use long context for schema analysis and tools for database migrations.
## Setup Structure
```
app/
api/trpc/[trpc]/route.ts
trpc/
routers/
context.ts
lib/
prisma/schema.prisma
db.ts
hooks/useQuery.ts
```
## Prisma Schema Best Practices
- Use TypeScript enums: `enum Role { USER ADMIN }`
- Relations: `model User { posts Post[] }`
- Indexes: `@@unique([email]) @@index([name])`
- Generate: `npx prisma generate --schema=./lib/prisma/schema.prisma`
## tRPC Router Definition
```ts
import { initTRPC } from '@trpc/server';
const t = initTRPC.context<{ session: Session }>().create();
export const appRouter = t.router({
user: t.router({
byId: t.procedure.input(z.object({ id: z.string() })).query(({ input }) => {
// Fully typed Prisma query
}),
}),
});
export type AppRouter = typeof appRouter;
```
## Client Integration
- React Query: `createTRPCReact<AppRouter, any>()`
- Mutations/Queries: Auto-typed from router
- Optimistic updates with context
## Advanced Features
- Middleware: Auth guards `t.middleware(({ next }) => next({ ctx: { user } }))`
- Batch calls
- Streaming responses
- Subscriptions with SSE
- Error handling: Custom TRPCError
## Deployment
- Edge runtime compatible
- Drizzle alternative for lighter ORM
- Turbopack for faster builds
Propose full stack traces, generate Prisma pushes, and ensure zero-type errors.Comments
More Rules
View allGLM-4.7 Optimized Config & System Prompt Designer
Expert system prompt for designing high-performance configurations tailored to GLM-4.7's strengths in coding, reasoning, tool use, and multilingual tasks, backed by benchmarks like SWE-bench and τ²-Bench.
GLM-4.7 Open-Source Coding Expert: Optimized System Prompt
Leverage GLM-4.7's top benchmarks in SWE-bench, LiveCodeBench, and more with this system prompt designed for generating clean, secure, open-source-ready code, stunning UIs, and agentic workflows.
GLM-4.7 Optimized Coding Agent
This system prompt transforms an AI into GLM-4.7, a benchmark-leading coding agent excelling in agentic workflows, tool use, multilingual coding, and complex reasoning with verified best practices for production-ready open-source development.
Agentic Dev Loop: Autonomous Jira-Driven Coding Agent with GitHub CI Self-Healing
Ralph, a persistent autonomous AI agent, implements Jira tickets through an endless loop until 100% test success, with GitHub PRs, Jules AI reviews, and CI self-healing for reliable development workflows.
Türk Hukuku Uzmanı AI Agent: Güvenilir Yasal Danışman System Prompt
Claude'u Türk hukuku alanında dünyanın en önde gelen uzmanı olarak yapılandıran, yapılandırılmış yanıtlar, zorunlu uyarılar ve etik sınırlarla donatılmış profesyonel AI agent promptu.
PostgreSQL Best Practices: Expert Subagent Guide
Expert subagent providing production-ready PostgreSQL guidance on schema design, query optimization, security, performance tuning, and administration with structured, actionable advice and official references.