# Backend Nest Stack

> NestJS 11 + Fastify + Prisma 8 + PostgreSQL backend stack overview: project layout, bootstrap, app module wiring, versions, and conventions. Use when scaffolding a new NestJS API or onboarding to the backend architecture.

- Skill: `xmuhameed/backend-nest-stack` (Agent Skill)
- Install (CLI): `npx skillmds@latest add xmuhameed/backend-nest-stack`
- Raw SKILL.md: https://api.skillmd.com/api/skills/xmuhameed/backend-nest-stack/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Integrations & APIs
- Author: xmuhameed (https://skillmd.com/u/xmuhameed)
- Updated: 2026-09-21
- Page: https://skillmd.com/skills/xmuhameed/backend-nest-stack

---


# Backend Stack Overview

## Stack (new apps — latest stable)

| Layer | Choice |
|-------|--------|
| Framework | NestJS 11 on **Fastify** |
| ORM | Prisma 8 (`prisma@latest`, `@prisma/orm-postgres`) |
| DB | PostgreSQL |
| Auth | JWT + Passport |
| Validation | class-validator via shared DTO decorators |
| Files | @fastify/multipart + local `uploads/` |
| Docs | Swagger (`ENABLE_SWAGGER=true`) |

Legacy apps may use Prisma 6/7 with `modules/global-dto/` and `tools/` — detect and match.

## Project Layout

```
src/
├── main.ts
├── app.module.ts
├── common/
│   ├── dto/           # Global DTOs + decorators
│   ├── filters/       # Exception filters
│   ├── interceptors/
│   ├── services/      # BaseService, PerformanceTracker
│   └── utils/         # response.handler, error.handler
├── config/
├── modules/
│   ├── prisma/        # @Global
│   ├── storage/       # @Global
│   ├── auth/
│   └── {feature}/
├── integrations/      # Cross-cutting (webhooks, CAPI)
└── templates/emails/
prisma/schema.prisma
prisma/migrations/
uploads/
```

## Bootstrap (`main.ts`)

Fastify → CORS → ValidationPipe → multipart → static files → Helmet → CSRF → listen

## App Module

`ConfigModule`, `ThrottlerGuard`, `EventEmitterModule`, `ScheduleModule`, global filters once in `app.module.ts` only.

## Conventions

- Action-first routes: `get-all-X`, `create-X`, `update-X`, `delete-X`
- HTTP 200 for most endpoints
- Response: `{ status: 'success', data }` or `{ status, count, data }`
- Bilingual fields: `name_en` / `name_ar`
- Soft delete: `deleted DateTime?`
- Tabs, single quotes, 120 width; `strict: true` for new apps

## Related Skills

| Task | Skill |
|------|-------|
| New module | `@backend-nest/create-module` |
| DTOs | `@backend-nest/global-dtos` |
| Files | `@backend-nest/file-upload` |
| Errors | `@backend-nest/error-handling` |
| Auth | `@backend-nest/auth` |
| Database | `@backend-nest/prisma-database` |

