trpc-router

Create tRPC routers with zod validation and TRPCError handling.

1|Updated May 9, 2026
One-click install
npx skills add https://github.com/duwenji/generative-ai-oss-tutorials --skill trpc-router-duwenji
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: trpc-router
Source: https://github.com/duwenji/generative-ai-oss-tutorials/tree/main/sandbox/lobe-chat/.agents/skills/trpc-router
Command: npx skills add https://github.com/duwenji/generative-ai-oss-tutorials --skill trpc-router-duwenji

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill prevents fragmented or error-prone tRPC router implementations by standardizing router layout, procedure patterns, validation, error handling, and shared context construction.

Core Features & Use Cases

  • Middleware-driven model injection: Centralizes model creation by injecting required models into ctx via middleware so procedures stay clean and consistent.
  • Reusable procedure patterns: Encourages uniform return shapes, zod input validation, and robust error handling that re-throws TRPCError and wraps unexpected errors.
  • Performance-friendly aggregated detail endpoints: Provides a pattern for parallel data fetching (e.g., Promise.all) to avoid N sequential API calls from clients.
  • Use cases: Implementing or extending server-side API endpoints in src/server/routers/lambda/**, adding query/mutation procedures, and composing endpoints for views that require multiple related entities.

Quick Start

Use the trpc-router skill to guide you when you create a new router file under src/server/routers/lambda/ and implement procedures that inject models through middleware, validate inputs with zod, and return consistent { data, success: true } / { data?, message, success: true } shapes.

Frequently Asked Questions about trpc-router

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure tRPC routers with middleware for model injection?▼

Structure tRPC routers by centralizing model creation and injecting required models into the ctx via middleware. This keeps procedures clean and ensures consistent context construction across server-side API endpoints.

What is the best way to handle errors in tRPC procedures?▼

The best way to handle errors in tRPC procedures is using TRPCError-first handling. Re-throw TRPCError directly and wrap unexpected errors to ensure robust, standardized error management across the API.

How do I validate tRPC input with zod and return consistent responses?▼

Validate tRPC input by defining zod schemas within your procedures, then return standardized envelopes like { data, success: true } for queries or { data?, message, success: true } for mutations to ensure consistent API responses.

How to optimize tRPC API endpoints to avoid sequential client requests?▼

Optimize tRPC API endpoints by implementing aggregated detail endpoints that use parallel data fetching like Promise.all. This retrieves related data together and minimizes sequential client API calls.

Can I use zod validation with tRPC mutations and queries?▼

Yes, you can use zod validation with both tRPC mutations and queries. The framework supports defining zod input validation directly within procedures to ensure safe and consistent data handling.

When do I need aggregated detail endpoints in tRPC?▼

You need aggregated detail endpoints in tRPC when composing views that require multiple related entities. They use parallelized data retrieval to fetch related data together, preventing fragmented or error-prone sequential API calls.