nestjs-best-practices
Skill13 starsChanged 11 months agoMITView on GitHub
NestJS best practices and patterns for building scalable, maintainable backend applications. This skill should be used when writing, reviewing, or refactoring NestJS code to ensure proper architecture, security, performance, and code quality. Triggers on tasks involving NestJS modules, controllers, services, guards, pipes, middleware, Prisma database operations, authentication, or any NestJS-specific patterns.
6 other projects use a version of this, 4 of them edited.
Adopted by
Most recently taken up by
- ever-works/ever-worksedited, first seen Jul 19, 2026
- jgamaraalv/delivery-looptheir own version, first seen Jul 4, 2026
- ngothanhtung/claude-code-nestjsedited, first seen Jun 30, 2026
- xirothedev/skillstheir own version, first seen May 23, 2026
- Aver005/agent-skillsedited, first seen Feb 14, 2026
- Kadajett/agent-nestjs-skillsedited, first seen Jan 30, 2026
Other versions6 projects use a version of this.
Word for word · 0
None found.
Edited · 4
- Kadajett/agent-nestjs-skills★ 28610% same
- ever-works/ever-works★ 15711% same
- Aver005/agent-skills★ 211% same
- ngothanhtung/claude-code-nestjs★ 111% same
Wrote their own version · 2
- jgamaraalv/delivery-loop★ 4same name
- xirothedev/skills★ 2same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository3 other files it gives its agents.
- AGENTS.mdAGENTS.md
- skills/nestjs-best-practices/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
The file
We split this skill into the rules it gives an agent
2 rules. 1 is common, 1 is distinctive, and 0 are very specific to this project.
1
Common
Most of the 5 edited versions we read keep these.
1
Distinctive
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Common: line 113
Read individual rule files for detailed explanations and code examples:
- Distinctive: line 134
All rules are optimized for AI agents with:
“Common” is measured: kept by at least 6 in 10 of the 5 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
NestJS Best Practices
Comprehensive guide for building production-ready NestJS applications. Contains 26 rules across 13 categories, covering security, architecture, performance, validation, database operations, authentication, and advanced patterns.
When to Apply
Reference these guidelines when:
- Writing new NestJS modules, controllers, or services
- Implementing authentication and authorization
- Setting up Prisma database operations
- Creating DTOs and validation pipes
- Adding middleware or guards
- Implementing error handling and logging
- Reviewing NestJS code for best practices
- Refactoring existing NestJS applications
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
| 1 | Security | CRITICAL | security- |
| 2 | Performance | HIGH | performance- |
| 3 | Architecture | HIGH | architecture- |
| 4 | Error Handling | HIGH | error-handling- |
| 5 | Validation | CRITICAL | validation- |
| 6 | Database | CRITICAL | database- |
| 7 | Authentication | CRITICAL | auth- |
| 8 | API | MEDIUM | api- |
| 9 | Configuration | CRITICAL | config- |
| 10 | Testing | MEDIUM | testing- |
| 11 | Deployment | MEDIUM | deployment- |
| 12 | Middleware | MEDIUM | middleware- |
| 13 | Advanced | HIGH | advanced- |
Quick Reference
1. Security (CRITICAL)
security-cors-whitelist- Enable CORS with whitelist origins onlysecurity-dependency-audit- Regular dependency security audits with bunsecurity-helmet-headers- Use Helmet middleware for security headers
2. Performance (HIGH)
performance-redis-caching- Cache frequently used data with Redis
3. Architecture (HIGH)
architecture-short-functions- Keep functions short and single purposearchitecture-feature-modules- Organize code by feature modulesarchitecture-no-dead-code- Remove unused code and dependenciesarchitecture-thin-controllers- Single responsibility - separate controller and servicearchitecture-naming-conventions- Use consistent naming conventionsarchitecture-event-driven- Use event-driven architecture for loose coupling
4. Error Handling (HIGH)
error-handling-exception-filter- Enable global exception filtererror-handling-structured-logging- Implement proper logging strategy
5. Validation (CRITICAL)
validation-custom-pipes- Create custom pipes for query parameter transformationvalidation-dto-validation- Validate all inputs with DTOs and ValidationPipe
6. Database (CRITICAL)
database-parameterized-queries- Use parameterized queries to prevent SQL injection (Prisma v7)
7. Authentication (CRITICAL)
auth-password-hashing- Use Bun's built-in Crypto for secure password hashing (argon2/bcrypt)auth-route-guards- Use guards for route protection
8. API (MEDIUM)
api-cursor-pagination- Use cursor-based pagination for large datasetsapi-swagger-docs- Generate Swagger/OpenAPI documentation
9. Configuration (CRITICAL)
config-no-secrets- Never hardcode secrets - use environment variables
10. Testing (MEDIUM)
testing-unit-tests- Write comprehensive unit tests
11. Deployment (MEDIUM)
deployment-health-checks- Implement health check endpoints
12. Middleware (MEDIUM)
middleware-compression- Enable compression middleware for responsesmiddleware-rate-limiting- Implement rate limiting for all routes
13. Advanced (HIGH)
advanced-lazy-loading- Lazy load non-critical modulesadvanced-scheduled-tasks- Use @nestjs/schedule for cron jobs and scheduled tasks
How to Use
Read individual rule files for detailed explanations and code examples:
rules/security-cors-whitelist.md
rules/auth-route-guards.md
rules/validation-dto-validation.md
rules/_sections.mdEach rule file contains:
- "For AI Agents" section with step-by-step implementation instructions
- Quick Reference Checklist for code review
- ❌ WRONG vs ✅ CORRECT patterns with file locations
- Installation commands using
bun add - Comprehensive code examples for NestJS + Prisma
- Security and performance considerations
Key Patterns
Agent-Friendly Format
All rules are optimized for AI agents with:
- Explicit file locations (e.g.,
src/users/users.service.ts) - Step-by-step "For AI Agents" sections
- ✅ CORRECT vs ❌ WRONG pattern comparisons
- Quick Reference Checklists
- Clear installation instructions
Technology Stack
- Framework: NestJS with Express/Fastify adapter
- Runtime: Bun (native crypto, scheduling)
- Database: Prisma v7 (sql template tag, interactive transactions)
- Validation: class-validator + class-transformer
- Security: Helmet, CORS whitelisting, rate limiting
- Scheduling: @nestjs/schedule with cron/interval decorators
- Events: EventEmitter2 for loose coupling
Full Compiled Document
For the complete guide with all rules expanded: AGENTS.md
Build Commands
cd packages/nestjs-best-practices-build
bun install
bun run build # Generate AGENTS.md
bun run validate # Validate rule files
bun run dev # Build and validateStatistics
- 13 sections covering all aspects of NestJS development
- 26 rules prioritized by impact (CRITICAL, HIGH, MEDIUM)
- Prisma v7 compatible database patterns
- Bun runtime native features (Crypto.hashPassword, @nestjs/schedule)
- Agent-optimized for automated code generation and review
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

