nest-trpc-native: Full NestJS Power + tRPC Type Safety with Zero Runtime Overhead

5
calendar_todayschedule2 min read

Hey NestJS + tRPC community!

I’m excited to release nest-trpc-native v0.3.0 — a decorator-first, native-feeling tRPC integration for NestJS.

No adapter glue code in your app layer. No compromise on NestJS features.

You write tRPC routers like Nest classes, with full support for dependency injection, guards, interceptors, pipes, filters, request-scoped providers, and end-to-end type safety.

nest-trpc-native router sample

Why this matters

Most tRPC + NestJS approaches push you toward one side:

  • Keep all NestJS lifecycle features, but lose clean tRPC developer experience, or
  • Keep pure tRPC style, but lose NestJS enhancers and request-scoped DI.

nest-trpc-native is designed so you can have both.

Core Features

  • @Router('users') + @Query(), @Mutation(), @Subscription()
  • Full support for @UseGuards(), @UseInterceptors(), @UsePipes(ValidationPipe), @UseFilters()
  • @Input() and @TrpcContext() for parameter extraction
  • Auto-generated router types (autoSchemaFile: 'src/@generated/server.ts')
  • Works with Express and Fastify
  • Zod or classic class-validator validation
  • Zero runtime dependencies in nest-trpc-native itself (host app controls Nest/tRPC peers)
  • Monorepo-friendly sample layout
  • Microservice transport pattern demonstrated in a focused sample

Architecture

Router Example (NestJS style)

@Router('users')
@UseGuards(AuthGuard)
export class UsersRouter {
  constructor(private readonly usersService: UsersService) {}

  @Query({ input: FindOneSchema, output: UserSchema.nullable() })
  @UsePipes(new ValidationPipe({ transform: true }))
  findOne(
    @Input() input: { id: number },
    @TrpcContext('requestId') requestId: string,
  ) {
    return this.usersService.findById(input.id);
  }

  @Mutation({ input: CreateUserSchema, output: UserSchema })
  create(@Input() input: { name: string; email: string }) {
    return this.usersService.create(input);
  }
}

Client side stays fully type-safe:

const user = await trpc.users.findOne.query({ id: 123 });
// autocomplete + compile-time safety

Installation

npm install nest-trpc-native @trpc/server
npm install @nestjs/common @nestjs/core reflect-metadata rxjs
# optional:
npm install zod

Then register the module:

TrpcModule.forRoot({
  path: '/trpc',
  autoSchemaFile: 'src/@generated/server.ts',
})

Samples You Can Run Now

  • sample/00-showcase: full integration baseline (guards, interceptors, pipes, filters, request scope, Express/Fastify, typed clients, subscriptions)
  • sample/11-microservice-transport: tRPC edge gateway + Nest microservice transport (TCP)

From repo root:

npm run showcase

Docs, Repo, and NPM

Docs: https://rodrigobnogueira.github.io/nest-trpc-native/docs/introduction
Repo: https://github.com/rodrigobnogueira/nest-trpc-native
NPM: https://www.npmjs.com/package/nest-trpc-native

Try it, break it, open issues, and share feedback.

Thanks!

🔥 Join developers growing publicly
Share your knowledge, build in public, and grow your developer presence with a global community.

More Posts

TypeScript Complexity Has Finally Reached the Point of Total Absurdity

Karol Modelskiverified - Apr 23

The Zero-Net-Loss Fleet & The Mercenary Squad: A Live AI Economy

DEVPlank - Aug 4

Tuesday Coding Tip 02 - Template with type-specific API

Jakub Neruda - Mar 10

Merancang Backend Bisnis ISP: API Pelanggan, Paket Internet, Invoice, dan Tiket Support

Masbadar - Mar 13

React Native Quote Audit - USA

kajolshah - Mar 2
chevron_left
123 Points5 Badges
Brasília / Brazil
1Posts
0Comments

Related Jobs

View all jobs →

Commenters (This Week)

3 comments
1 comment
1 comment

Contribute meaningful comments to climb the leaderboard and earn badges!