Skip to content

About

gRPC microservices with NestJS: proto-first chat contract, auth guard, DTO validation filter and gRPC end-to-end tests.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Repository files navigation

Microservices NestJS

A gRPC service in NestJS where the contract comes first — src/proto/chat.proto is the source of truth, and both the server and the client in this repo are generated against it.

What is in it

src/proto/chat.proto                 the contract
src/grpc-server/                     @GrpcMethod controllers implementing it
src/grpc-client/                     a typed client consuming the same proto
src/auth/auth.guard.ts               guard applied before a handler runs
src/chat.dto.ts                      class-validator DTOs
src/validation.exception-filter.ts   turns validation failures into proper gRPC errors
test/grpc.e2e-spec.ts                end-to-end over a real gRPC channel

Decisions worth noting

  • Server and client in one repo, on purpose. Consuming your own contract is the fastest way to find out it is wrong — the client is the first integration test.
  • Validation at the boundary. class-validator DTOs plus a dedicated exception filter, because a gRPC service that returns UNKNOWN on bad input is unusable for whoever calls it.
  • Auth as a guard, not a helper call. auth.guard.ts runs before the handler, so no method can forget it.
  • E2E against a real channel (test/grpc.e2e-spec.ts), not a mocked transport — proto mismatches only show up over the wire.

Stack

NestJS 9 · @nestjs/microservices · @grpc/grpc-js · @grpc/proto-loader · class-validator + class-transformer · RxJS · Jest

Run it

pnpm install
pnpm start:dev          # watch mode
pnpm test               # unit
pnpm test:e2e           # gRPC end-to-end

Status

Complete as a reference: a working gRPC server and client, guarded and validated, with tests. Not a product — the domain is deliberately a chat stub so the plumbing stays visible.

About

gRPC microservices with NestJS: proto-first chat contract, auth guard, DTO validation filter and gRPC end-to-end tests.

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages