Skills

Nestjs Trpc

Build end-to-end type-safe tRPC APIs inside NestJS using the nestjs-trpc adapter, ...

Install

npx skills add trycompai/crm --skill nestjs-trpc -g -a claude-code -y
Repository
trycompai/crm11.8k
Category
Design
Updated
4d ago
License
MIT
Context cost
Mediumabout 2,644 tokens
Runs scripts
No, instructions only

What it does

Build end-to-end type-safe tRPC APIs inside NestJS using the nestjs-trpc adapter, @Router/@Query/@Mutation/@Subscription decorators, TRPCModule.forRoot, injectable middlewares and context, Zod input/output schemas, and the Rust CLI that generates the AppRouter type for clients. Use this skill whenever the user mentions nestjs-trpc, tRPC in a NestJS app, @Router or @Query decorators, TRPCModule, AppRouterHost, "typed API between my Nest backend and frontend", generating AppRouter types, or is migrating a NestJS GraphQL/REST API to tRPC, even if they don't name the library explicitly.

NestJS-tRPC

nestjs-trpc lets you define tRPC procedures as decorated NestJS classes instead of chaining t.procedure builders. Routers are DI-aware classes that look like controllers; a separate CLI reads those decorators and emits an AppRouter type for the client.

Verified against v2.13.0. The published docs at nestjs-trpc.io still contain v1-era examples in several places. Where this skill and the docs disagree, this skill matches the shipped .d.ts files and the official examples/ in the repo, see Docs errata for the specific traps.

The one thing to internalize

There are two separate systems that both need to be correct, and they fail independently:

RuntimeType generation
Driven byNest DI container at bootRust CLI doing static analysis of your source
Needsclasses listed in providersdecorators it can read literally
Fails as404 / "no procedures" / undefined injectionstale or missing AppRouter

A router that works at runtime but was never picked up by the CLI produces a client with no types, and vice versa. When something is wrong, first ask which of the two is broken.

Setup workflow

1. Install

npm install nestjs-trpc zod @trpc/server

Peer deps (v2.13.0): @nestjs/common & @nestjs/core ^9.3.8 || ^10 || ^11, @trpc/server ^11, zod ^3.14 || ^4, rxjs 7.8.1, reflect-metadata ^0.1.13 || ^0.2. tRPC v11 is required, v10 will not work.

Standard NestJS tsconfig.json requirements apply: experimentalDecorators: true, emitDecoratorMetadata: true. tsc must be resolvable, because the CLI shells out to it to typecheck what it generates.

2. Register the module

Read the whole SKILL.md on GitHub

More in Design