trpc-router

Guide TRPC router implementation with zod validation and TRPCError handling.

Updated Aug 23, 2026
One-click install
npx skills add https://github.com/kingheu0818-sketch/lobehub_yu --skill trpc-router-kingheu0818-sketch
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: trpc-router
Source: https://github.com/kingheu0818-sketch/lobehub_yu/tree/main/.agents/skills/trpc-router
Command: npx skills add https://github.com/kingheu0818-sketch/lobehub_yu --skill trpc-router-kingheu0818-sketch

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

It standardizes how you design and implement TRPC routers so your server-side endpoints stay consistent, safe, and efficient, while avoiding repetitive boilerplate and slow “N sequential requests” patterns.

Core Features & Use Cases

  • Model injection via middleware: Ensures database models are created once per request and attached to ctx, improving consistency across procedures.
  • Clean procedure patterns: Provides a consistent approach for queries/mutations using zod validation, predictable return shapes, and robust error handling with TRPCError.
  • Aggregated detail endpoints: Enables a single detail procedure to fetch related data in parallel, reducing client round-trips.

Quick Start

Use the trpc-router guide when you create or update src/server/routers/lambda/<domain>.ts to define a router and its procedures using middleware-injected ctx models, zod inputs, and TRPCError-based error handling.

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 to avoid sequential database queries?

To avoid sequential database queries in tRPC routers, use Promise.all within a single detail procedure to fetch related data in parallel. This reduces client round-trips and sequential request overhead, creating an aggregated detail endpoint.

How do I inject database models into tRPC procedures consistently?

Inject database models into tRPC procedures using middleware. This ensures models are created once per request and attached to the context (ctx), providing consistent model injection across all queries and mutations without repetitive boilerplate.

What is the best way to handle errors and validate inputs in a tRPC server API?

The best way to handle errors and validate inputs in a tRPC server API is by wrapping errors with TRPCError and validating inputs using Zod schemas. This enforces standardized return shapes and reliable server-side endpoint logic.

How do I create a tRPC procedure with Zod validation and predictable return shapes?

Create a tRPC procedure with Zod validation by defining schema inputs and enforcing standardized return shapes. Apply this clean procedure pattern to queries and mutations to ensure predictable, safe, and efficient server-side endpoint logic.

Does this tRPC router guide work with existing lambda router files?

Yes, this tRPC router guide works directly with existing lambda router files. It is specifically applicable for creating or modifying routers and endpoint logic located in the src/server/routers/lambda directory using middleware-injected ctx models.