Archive
47
practical posts on NestJS, testing, architecture, and backend delivery.

NestJS Ninja
Backend lessons & architecture notes
TypeScript servers
Practical writing on modules, providers, queues, testing, microservices, and the decisions that keep backend codebases easy to change.
@Module({
imports: [
ConfigModule.forRoot(),
QueueModule,
ObservabilityModule,
],
controllers: [ArticlesController],
providers: [ArticlesService],
})
export class AppModule {}Archive
47
practical posts on NestJS, testing, architecture, and backend delivery.
Coverage
4
years of notes, experiments, and backend implementation write-ups.
Topics
Featured

LangChain v1 inside a NestJS application, built as a real support API: two models behind injection tokens so switching vendor is an environment variable, structured output with Zod, an LCEL drafting chain, cross-provider fallback, and an agent whose tools call your ordinary services. Plus the finding that changed how I write this code: withStructuredOutput parses the reply but does not validate it, so an invalid enum arrives typed and wrong. Every one of the 23 tests runs without an API key.
Latest
An MCP server is how you hand your application to an AI client like Claude or ChatGPT without writing a chatbot. We build one on top of a normal NestJS service using @rekog/mcp-nest, expose tools, resources and prompts with Zod, and call every one of them with curl. Along the way we hit two things the README does not warn you about: your exceptions arrive at the model as "Internal server error", and your guards do not protect tools/list.
Two concurrent requests read the same row, both decide it is safe to write, and one silently overwrites the other. We reproduce that lost update on purpose, then fix it two ways in NestJS and TypeORM: SELECT ... FOR UPDATE inside a transaction, and a single conditional UPDATE guarded by a version column. Proven with real concurrent races against Postgres, not a mock.
How the keys an SSO provider generates actually work, built in NestJS: sign access tokens with a private key, publish the matching public key at /.well-known/jwks.json, verify every request against it, and let an outside service or the browser verify with nothing but the URL. Then hand the trusted claims to the CASL authorization layer.
One GraphQL schema, many NestJS services. We take a code-first GraphQL API and split it into Apollo Federation v2 subgraphs — a users service that owns the User entity, an orders service that extends it — composed by a gateway that plans queries across both without the client ever knowing.
Pipes are the front door of a NestJS request — they transform and validate input before it ever reaches a service. This post covers the ValidationPipe and DTOs, the options that actually matter (whitelist, transform), parsing and custom pipes, a Zod alternative, generating Swagger/OpenAPI docs from the same DTOs, and how to make validation failures come back in the same error shape as the rest of your API.