trpc-router

Build and maintain TRPC server-side API routers with TypeScript and zod.

1|Updated May 20, 2026
One-click install
npx skills add https://github.com/mDevsLabs/mAI --skill trpc-router-mdevslabs
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: trpc-router
Source: https://github.com/mDevsLabs/mAI/tree/main/.agents/skills/trpc-router
Command: npx skills add https://github.com/mDevsLabs/mAI --skill trpc-router-mdevslabs

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

TRPC router development and wiring for server-side APIs can be error-prone without a clear blueprint. This guide provides a structured approach to building routers, procedures, and middleware with consistent patterns.

Core Features & Use Cases

  • Router structure & conventions: standardized file layout, middleware use, and type-safe procedures.
  • Context injection & error handling: guidance on injecting models into ctx and wrapping errors consistently.
  • Use Case: rapidly implement endpoints for domain-specific data access with zod validation and TRPCError handling.

Quick Start

Create or modify src/server/routers/lambda/<domain>.ts using the templates and samples to implement your API.

Frequently Asked Questions about trpc-router

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

FAQPage Schema
How do I structure a tRPC router for server-side APIs?

Structure a tRPC router by defining domain-specific modules under a standardized file layout, using lambda-style routers to organize procedures and middleware for server-side APIs. This ensures consistent patterns and type safety across endpoints.

How does middleware work in tRPC routers?

Middleware in tRPC routers works by intercepting procedure calls to inject context, such as data models, and enforce consistent error handling before passing execution to the main procedure. This provides a structured approach for API request processing.

How do I add zod validation to tRPC procedures?

Add zod validation to tRPC procedures by defining zod schemas for your inputs and applying them to procedure definitions. This enforces type-safe inputs and ensures consistent error handling before the server-side API logic executes.

What is the best way to handle TRPCError in TypeScript routers?

The best way to handle TRPCError in TypeScript routers is by wrapping errors consistently within your procedures using standard tRPC error handling patterns. This ensures type-safe error responses across your server-side API endpoints.

Do I need TypeScript to use tRPC routers?

Yes, you need TypeScript to use tRPC routers effectively. Building and maintaining these server-side APIs requires TypeScript, tRPC, and zod to ensure type-safe inputs, context injection, and consistent error handling.

How do I inject models into tRPC context?

Inject models into tRPC context by defining a context creation function that passes required data models into the ctx object. This allows your procedures and middleware to access domain-specific data safely during API execution.