# TypeScript API service: NestJS + Postgres + Prisma
URL: https://wwadd.dev/stacks/nestjs-postgres-prisma-api
Last verified: 2026-09-28

A standalone TypeScript API that several clients depend on — mobile apps, partners, other services — with a validated contract and generated docs.

## When to use it
- Several clients call the API: your mobile apps, partner integrations, or other services
- The team writes TypeScript and there's no Python-specific work pulling the backend elsewhere
- You need a stable contract: validation on every request and published API docs
- The codebase will grow across several developers and domains

## How the pieces fit
NestJS organizes the service into modules — controllers for HTTP, providers for business logic — wired by dependency injection, so each domain (billing, users, webhooks) stays separate as the API grows. Validation pipes check every request against DTO classes before a handler runs, and the Swagger module turns those same classes into OpenAPI docs that partners and client generators use. Guards put authentication, per-route authorization, and rate limiting in one place. Prisma gives typed Postgres access and versioned migrations. NestJS runs on Express by default and can switch to a Fastify adapter when throughput matters.

## The tech and its role
- [NestJS](https://wwadd.dev/tools/nestjs): Modules, controllers, dependency injection, guards
- [Postgres](https://wwadd.dev/tools/postgresql): Primary datastore
- [Prisma](https://wwadd.dev/tools/prisma): Typed queries and migrations
- [OpenAPI (@nestjs/swagger)](https://wwadd.dev/tools/nestjs): API docs generated from DTO classes
- class-validator: Request validation on every route
- [Docker](https://wwadd.dev/tools/docker): Consistent builds for container hosts

## Real-world examples
- Hoppscotch: Open-source API development platform: its backend is a NestJS app on Postgres with Prisma, serving GraphQL through Apollo alongside REST controllers documented with Swagger, with class-validator and Passport-based auth. (source: https://github.com/hoppscotch/hoppscotch/tree/main/packages/hoppscotch-backend)
- Cal.com API v2: Cal.com's public API runs as a separate NestJS service on the same Postgres and Prisma data, with Swagger docs, rate limiting through @nestjs/throttler, and Passport-based auth. (source: https://github.com/calcom/cal.com/tree/main/apps/api/v2)

## Skip if
Skip if the API is small or has a single client — a lighter framework such as Fastify or Hono, or route handlers next to your web app, costs far less ceremony.

## Testing and shipping
- [Change database schemas in compatible stages](https://wwadd.dev/moves/testing-shipping/compatible-schema-migrations)
- [Prove a backup can restore](https://wwadd.dev/moves/testing-shipping/verify-backup-restore)

