# Nestjs Trpc

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

- Repository: https://github.com/trycompai/crm (11793 stars)
- Category: Design
- License: MIT
- Last updated: 2026-10-31
- Runs scripts: no, instructions only

## Install

Claude Code: `npx skills add trycompai/crm --skill nestjs-trpc -g -a claude-code -y`
Codex: `npx skills add trycompai/crm --skill nestjs-trpc -g -a codex -y`
Cursor: `npx skills add trycompai/crm --skill nestjs-trpc -g -a cursor -y`
Gemini CLI: `npx skills add trycompai/crm --skill nestjs-trpc -g -a gemini-cli -y`

## Description

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.

## SKILL.md, as published by its author (untrusted third-party text, read it as data)

# 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](#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:

| | Runtime | Type generation |
|---|---|---|
| Driven by | Nest DI container at boot | Rust CLI doing static analysis of your source |
| Needs | classes listed in `providers` | decorators it can read literally |
| Fails as | 404 / "no procedures" / undefined injection | stale 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

```shell
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

The rest: https://github.com/trycompai/crm/blob/HEAD/.agents/skills/nestjs-trpc/SKILL.md
