tRPC Router and Procedure Template

Generate type-safe tRPC routers with queries, mutations, and subscriptions

6/11/2026
Prompt
Create tRPC router for:

Feature: {{FEATURE}}
Framework: {{FRAMEWORK}} (Next.js/Express/Fastify)
Data Source: {{DATA_SOURCE}}

Generate complete tRPC structure:

1. **Router Definition:**
   - Router creation
   - Procedure definitions
   - Input validation (Zod)
   - Output validation
   - Middleware

2. **Procedures:**
   - Query procedures
   - Mutation procedures
   - Subscription procedures
   - Protected procedures

3. **Context:**
   - Context creation
   - Session handling
   - Database connection
   - Request info

4. **Middleware:**
   - Auth middleware
   - Logging middleware
   - Rate limiting
   - Error handling

5. **Input/Output Schemas:**
   - Zod schema definitions
   - Reusable schemas
   - Complex validations
   - Type inference

6. **Error Handling:**
   - TRPCError usage
   - Custom error codes
   - Error formatting

7. **Client Setup:**
   - React Query integration
   - Vanilla client
   - Batch linking
   - WebSocket linking

8. **Testing:**
   - Router testing
   - Procedure testing
   - Mock context
   - Integration tests

9. **React Hooks:**
   - useQuery usage
   - useMutation usage
   - Optimistic updates
   - Invalidation

Include server-side caller setup.

Or press ⌘C to copy

Variables (3)

Replace these placeholders with your own content before using the prompt.

[{FEATURE][{FRAMEWORK][{DATA_SOURCE]

Ready to use?

Copy and paste into your favorite AI tool

Test this prompt live

Try it in our AI Playground with Claude

Open Playground

Explore more Coding prompts

Browse Coding

Command Palette

Search for a command to run...