Agent skill

Nestjs Trpc

by trycompai in trycompai/crm

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…

MITAuto-check passedBackend & APIs

Install Nestjs Trpc

skills CLI
$ npx skills add trycompai/crm --skill nestjs-trpc -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install trycompai/crm nestjs-trpc --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/trycompai/crm.git skills-src && mkdir -p .claude/skills && cp -r skills-src/.agents/skills/nestjs-trpc .claude/skills/nestjs-trpc && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
nestjs-trpc
GitHub stars
11k
Token cost
~2.8k tokens
SKILL.md length
1,011 words
Files
6 (incl. references)
Skills in repo
9
Repo updated
First seen
Licence
MIT

At a glance

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…

  • Works in 4 steps: Install → Register the module → Write a router → …
  • The user mentions nestjs-trpc
  • SKILL.md covers The one thing to internalize, Setup workflow, Writing procedures and Middlewares and context, plus 3 more sections
  • Calls npx and npm

What it does

Nestjs Trpc is an agent skill from trycompai/crm. 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…

Its SKILL.md is about 2.8k tokens, which your agent loads only when the skill is triggered. The skill folder holds 6 other files, including reference files (for example `references/api-reference.md`, `references/codegen-and-client.md` and `references/middlewares-and-context.md`).

It sits in Backend & APIs, covering gRPC and Protobuf and Forms and validation. It works with tRPC, NestJS, Rust and Zod. The repository describes itself as: Comp AI CRM is an open source, CRM designed for AI agents. Agentic-first CRM. The licence is MIT.

When your agent uses it

  • The user mentions nestjs-trpc
  • TRPC in a NestJS app
  • @Query decorators
  • Typed API between my Nest backend and frontend

Example prompts

  • “typed API between my Nest backend and frontend”
  • “/nestjs-trpc”

Requirements

  • Node.js

Workflow steps

4 steps, taken from the step headings in SKILL.md.

  1. Install
  2. Register the module
  3. Write a router
  4. Generate the client type

What it can do on your machine

Read from SKILL.md and the folder at commit 6d4793d. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    Shell commands in SKILL.md call:

    • npx
    • npm

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md. Its commands use npx and npm, which can reach the network depending on how they are called.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Nestjs Trpc loads about 2.8k tokens when it runs, and up to ~16k if it reads all its reference files. Until then it costs about 151 tokens; SKILL.md has 1,011 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~151
When it runs · the whole SKILL.md, loaded when a task matches
~2.8k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~16k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from trycompai/crm at commit 6d4793d, republished under its MIT licence (© trycompai). 1,011 words, ~2,836 tokens.

Download SKILL.mdSave it as .claude/skills/nestjs-trpc/SKILL.md (or your agent's skills folder). This skill also uses 5 other files; get the full folder from GitHub.
name
nestjs-trpc
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.
license
MIT
metadata.version
1.0.0
metadata.targets
nestjs-trpc v2.x (verified against 2.13.0)
metadata.docs
https://nestjs-trpc.io/docs

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
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
typescript
// app.module.ts
import { Module } from '@nestjs/common';
import { TRPCModule } from 'nestjs-trpc';
import { UserRouter } from './user.router';
import { UserService } from './user.service';
import { ProtectedMiddleware } from './protected.middleware';
import { AppContext } from './app.context';

@Module({
  imports: [
    TRPCModule.forRoot({
      context: AppContext,
    }),
  ],
  providers: [UserRouter, AppContext, UserService, ProtectedMiddleware],
})
export class AppModule {}

Routers, middlewares, and the context class are all ordinary providers. Listing them in providers is what makes DI work — forgetting a router here is the single most common reason procedures silently don't exist at runtime.

Default mount point is /trpc; override with basePath. Full option table in references/module-config.md.

3. Write a router
typescript
// user.router.ts
import { Inject } from '@nestjs/common';
import { Router, Query, Mutation, UseMiddlewares, Input, Ctx } from 'nestjs-trpc';
import { TRPCError } from '@trpc/server';
import { z } from 'zod';
import { UserService } from './user.service';
import { ProtectedMiddleware } from './protected.middleware';
import { userSchema, type User } from './user.schema';

@Router({ alias: 'users' })
export class UserRouter {
  constructor(@Inject(UserService) private readonly userService: UserService) {}

  @Query({
    input: z.object({ userId: z.string() }),
    output: userSchema,
  })
  @UseMiddlewares(ProtectedMiddleware)
  async getUserById(@Input('userId') userId: string): Promise<User> {
    const user = await this.userService.getUser(userId);

    if (user == null) {
      throw new TRPCError({ message: 'Could not find user.', code: 'NOT_FOUND' });
    }

    return user;
  }
}

Client call site: trpc.users.getUserById.query({ userId }). The alias sets that first segment — without it the class name is used.

4. Generate the client type
shell
npx nestjs-trpc generate      # one-shot
npx nestjs-trpc watch         # regenerate on change during development

Writes server.ts (containing export type AppRouter = typeof appRouter) to ./src/@generated by default; --output <dir> moves it. This is a build step, not a runtime import — the generated file is types only, and your procedures still execute through the Nest-managed router at runtime.

Add it to your scripts so it can't drift:

json
{
  "scripts": {
    "dev": "nestjs-trpc watch & nest start --watch",
    "build": "nestjs-trpc generate && nest build"
  }
}

Run nestjs-trpc generate --dry-run in CI to fail the build when the committed types are stale.

Writing procedures

Three procedure decorators, all taking { input?, output?, meta? }, all optional:

DecoratortRPC equivalent
@Query()publicProcedure.query()
@Mutation()publicProcedure.mutation()
@Subscription()publicProcedure.subscription()

input validates and types the incoming payload. output is optional — omit it and the return type is inferred from the method signature (since v2.11.0). Prefer an explicit output on anything crossing a trust boundary, because it strips fields the client shouldn't see; a leaked password column is the classic version of this bug. Note the example schema above deliberately keeps password in userSchema only to mirror the upstream docs — in real code, define a separate public-facing schema.

Any Standard Schema validator works (Zod, Valibot, ArkType, Yup, Superstruct), but the CLI's schema flattening is built around Zod — stay on Zod unless you have a reason not to.

Parameter decorators pull pieces out of the tRPC opts object:

DecoratorYields
@Input(key?)opts.input, or opts.input[key]
@Ctx()opts.ctx
@Options()the whole opts (typed as ProcedureOptions)
@RawInput()opts.rawInput (pre-validation)
@Type()'query' | 'mutation' | 'subscription'
@Path()the procedure path string

Throw TRPCError from @trpc/server for client-visible failures. Nest's HttpException is not translated into a tRPC error shape, so it surfaces as an opaque 500.

Details, subscription patterns, and router merging: references/routers.md.

Show full SKILL.md (440 more words)Show less

Middlewares and context

Middlewares are @Injectable() classes implementing TRPCMiddleware, applied with @UseMiddlewares(...) on a class (all procedures) or a method (that one only), or globally via globalMiddlewares. Execution order is global → router → procedure → handler.

typescript
@Injectable()
export class ProtectedMiddleware implements TRPCMiddleware {
  constructor(@Inject(UserService) private readonly userService: UserService) {}

  async use(opts: MiddlewareOptions<object>): Promise<MiddlewareResponse> {
    const result = await opts.next({ ctx: { user: await this.userService.current() } });
    return result;
  }
}

Two rules that cause most middleware bugs: always return the result of next() so the chain isn't swallowed, and pass added context through next({ ctx }) rather than mutating opts.ctx in place.

Context is a class implementing TRPCContext with a create(opts) method, registered in providers and passed to forRoot({ context }). It runs once per request and is the right home for the request object, session, and per-request loaders.

Full treatment including typing context across a middleware chain and procedure meta: references/middlewares-and-context.md.

Mirrors NestJS conventions, which is the whole point of the adapter:

src
├── app.module.ts
├── app.context.ts
├── main.ts
├── @generated/          # CLI output — gitignore or commit, but be consistent
└── user/
    ├── user.router.ts       # the "controller" — thin, no business logic
    ├── user.service.ts      # business logic, unit-testable without tRPC
    ├── user.schema.ts       # Zod schemas + inferred types, shared by both
    └── protected.middleware.ts

Keep routers thin. A router method that only validates, delegates to a service, and maps errors stays testable and keeps the CLI's job easy.

Docs errata

The official docs mix v1 and v2 content. These are the ones that will actually break your build:

  • @Ctx(), not @Context(). The routers and middlewares pages show @Context(); the exported decorator is Ctx. (Context as an identifier does exist in the docs' prose as a type name, which is where the confusion comes from.)
  • MiddlewareOptions, not TRPCMiddlewareOptions. The latter is not exported.
  • TRPCMiddleware<TMeta> — the single generic is the meta type, not the context type. The docs' implements TRPCMiddleware<Context> is wrong. Context types are supplied via MiddlewareOptions<TContext, TReturnContext, TMeta> on the use() signature.
  • autoSchemaFile and schemaFileImports are v1 options. They are absent from the v2 TRPCModuleOptions type and will be TypeScript errors, even though the context, client, and integrations pages still show autoSchemaFile. Control output with the CLI's --output flag instead.
  • nestjs-trpc/types is a v1 import path. v1's ts-morph generator wrote helper types (Context, {Middleware}Context) into the package; v2's Rust CLI emits a single server.ts instead. Don't import from nestjs-trpc/types on v2 — declare your context types yourself.
  • @Middlewares() is deprecated in favour of @UseMiddlewares(), to match @UseGuards.
  • The middlewares page's first example has a literal typo (constructror) and a missing async. Don't copy it verbatim.

Reference files

Read these when the task goes past the basics:

  • references/routers.md — procedure and parameter decorators in full, subscriptions/SSE with AbortSignal cleanup, alias merging, error handling, testing routers.
  • references/middlewares-and-context.md — MiddlewareOptions generics, context propagation and typing, meta-driven authorization, global middleware ordering.
  • references/module-config.md — every forRoot option, SSE and JSONL keep-alive settings, onError handlers, custom loggers, transformers.
  • references/codegen-and-client.md — CLI flags, ESM --import-extension, schema-flattening failures, consuming AppRouter from React / Next.js / vanilla clients, AppRouterHost for e2e tests and trpc-ui.
  • references/api-reference.md — exact exported symbols and type signatures transcribed from the shipped .d.ts. Check here before guessing a name.

© trycompai, MIT. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

SKILL.md and 5 other files (references) in .agents/skills/nestjs-trpc of trycompai/crm.

  • SKILL.md
  • references/api-reference.md
  • references/codegen-and-client.md
  • references/middlewares-and-context.md
  • references/module-config.md
  • references/routers.md

Open the folder on GitHubat commit 6d4793d

Compare with similar skills

Nestjs Trpc next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Nestjs Trpc compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Nestjs Trpc this skilltrycompai/crm11k—~2.8kAutomated safety check: PassMIT
Backend Dev Guidelineslangfuse/langfuse35k—~1.9kAutomated safety check: PassCustom licence
Backend Dev Guidelineslitefuse/litefuse1001 repos~5.8kAutomated safety check: PassCustom licence
Trpcpproenca/dot-skills214—~2.8kAutomated safety check: PassMIT
Dev Rulesrust-dd/tako162—~810Automated safety check: PassMIT
SpikardGoldziher/spikard123—~799Automated safety check: PassMIT

Similar skills

  • Backend Dev Guidelines

    langfuse/langfuse

    Build or review Langfuse backend code. An agent skill from langfuse/langfuse.

    35k GitHub stars~1.9k tokensUpdated today
    Backend & APIsAuto-check passed
  • Backend Dev Guidelines

    litefuse/litefuse

    Comprehensive backend development guide for Litefuse's Next.js 14/tRPC/Express/TypeScript monorepo.

    100 GitHub starsUsed in 1 repo~5.8k tokens
    Backend & APIsAuto-check passed
  • Trpc

    pproenca/dot-skills

    Corrects the wrong defaults a model has for tRPC v11 (verified against 11.18.0).

    214 GitHub stars~2.8k tokensUpdated 1 mo ago
    Backend & APIsAuto-check passed
  • Dev Rules

    rust-dd/tako

    General coding-style rules to apply to every project. An agent skill from rust-dd/tako.

    162 GitHub stars~810 tokensUpdated 6 days ago
    Backend & APIsAuto-check passed
  • Spikard

    Goldziher/spikard

    Scaffold Spikard projects and generate code from OpenAPI, AsyncAPI, OpenRPC, GraphQL, and Protobuf schemas using the Spikard CLI or its MCP server.

    123 GitHub stars~799 tokensUpdated 3 days ago
    Backend & APIsAuto-check passed
  • Docs Writing

    rust-dd/tako

    Conventions for writing and maintaining tako documentation pages under website/content/docs/.

    162 GitHub stars~2.8k tokensUpdated 6 days ago
    Backend & APIsAuto-check passed

More from trycompai/crm

All 9 skills in this repo
  • Install Anti Slop

    trycompai/crm

    Install and configure the anti-slop Oxlint plugin in a local TypeScript or JavaScript repository.

    11k GitHub starsUsed in 1 repo~881 tokens
    Auto-check passed
  • Nuqs

    trycompai/crm

    nuqs (type-safe URL query state) best practices for Next.js and other React frameworks.

    11k GitHub starsUsed in 1 repo~1.7k tokens
    Auto-check passed
  • Accessibility engineering for product interfaces, from focus states and keyboard support to ARIA, forms, and screen readers.

    11k GitHub stars~3.1k tokensUpdated 26 days ago
    Auto-check passed
  • Better Colors

    trycompai/crm

    OKLCH color space and color usage for web projects. An agent skill from trycompai/crm.

    11k GitHub stars~1.9k tokensUpdated 26 days ago
    Auto-check passed
  • Better Typography

    trycompai/crm

    Web typography from choosing fonts to spacing, wrapping and accessibility.

    11k GitHub stars~3.8k tokensUpdated 26 days ago
    Auto-check passed
  • Better UI

    trycompai/crm

    Design engineering principles for making interfaces feel polished.

    11k GitHub stars~2.4k tokensUpdated 26 days ago
    Auto-check passed

Categories

Questions about Nestjs Trpc

What does Nestjs Trpc do?

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…. Nestjs Trpc is an agent skill from trycompai/crm.forRoot, injectable middlewares and context, Zod input/output schemas, and the Rust CLI that generates the AppRouter type for clients.

When should I use Nestjs Trpc?

Nestjs Trpc fits situations like: the user mentions nestjs-trpc; TRPC in a NestJS app; @Query decorators; typed API between my Nest backend and frontend.

How do I install Nestjs Trpc in Claude Code?

Run `npx skills add trycompai/crm --skill nestjs-trpc -a claude-code`. Or copy the skill folder (.agents/skills/nestjs-trpc in trycompai/crm) into .claude/skills/nestjs-trpc in your project. Claude Code loads it when a task matches its description.

How do I install Nestjs Trpc in Codex?

Run `npx skills add trycompai/crm --skill nestjs-trpc -a codex`. Or copy the skill folder (.agents/skills/nestjs-trpc in trycompai/crm) into .agents/skills/nestjs-trpc in your project. Codex loads it when a task matches its description.

Can I use Nestjs Trpc in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add trycompai/crm --skill nestjs-trpc -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/nestjs-trpc, .gemini/skills/nestjs-trpc, .github/skills/nestjs-trpc and .opencode/skills/nestjs-trpc in your project.

What does Nestjs Trpc need to run?

Going by SKILL.md and its folder, Nestjs Trpc needs the command-line tools its instructions call (npx and npm). Our summary lists: Node.js.

Does Nestjs Trpc access the network?

SKILL.md contains no URLs. Its commands use npx and npm, which can reach the network depending on how they are called. This is read from the text; nothing was executed.

Is Nestjs Trpc safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Nestjs Trpc use?

Nestjs Trpc is published under the MIT licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Nestjs Trpc use?

About 2.8k tokens (SKILL.md is roughly 11k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 13k tokens, read only when the agent opens those files.

What are the alternatives to Nestjs Trpc?

Skills that share tags, products or a category with Nestjs Trpc: Backend Dev Guidelines (langfuse/langfuse, 35k stars), Backend Dev Guidelines (litefuse/litefuse, 100 stars), Trpc (pproenca/dot-skills, 214 stars) and Dev Rules (rust-dd/tako, 162 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Nestjs Trpc?

trycompai (a GitHub organization) maintains it in trycompai/crm, which has 11,109 GitHub stars. The repository holds 9 skills in this directory. The repository was last updated on September 11, 2026.

Source: trycompai/crm on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.