nestjs-best-practices
NestJS best practices and architecture patterns for building production-ready applications. This skill should be used when writing, reviewing, or refactoring NestJS code to ensure proper patterns for modules, dependency injection, security, and performance.
- License 许可
- MIT
- 最近更新
- 2026-11-15
- Stars
- ★ 4
- Forks
- 2
01 前言 Front Matter
- name
- nestjs-best-practices
- license
- MIT
- metadata
- { "author": "Kadajett", "version": "1.2.0" }
- description
- NestJS best practices and architecture patterns for building production-ready applications. This skill should be used when writing, reviewing, or refactoring NestJS code to ensure proper patterns for modules, dependency injection, security, and performance.
02 资源文件 42
- 参考文档rules/_sections.md2.1 KB
- 参考文档rules/_template.md631 B
- 参考文档rules/api-use-dto-serialization.md4.3 KB
- 参考文档rules/api-use-interceptors.md5.4 KB
- 参考文档rules/api-use-pipes.md5.3 KB
- 参考文档rules/api-versioning.md4.9 KB
- 参考文档rules/arch-avoid-circular-deps.md2.0 KB
- 参考文档rules/arch-feature-modules.md2.3 KB
- 参考文档rules/arch-module-sharing.md3.8 KB
- 参考文档rules/arch-single-responsibility.md2.9 KB
- 参考文档rules/arch-use-events.md3.0 KB
- 参考文档rules/arch-use-repository-pattern.md2.8 KB
- 参考文档rules/db-avoid-n-plus-one.md3.8 KB
- 参考文档rules/db-use-migrations.md3.7 KB
- 参考文档rules/db-use-transactions.md3.9 KB
- 参考文档rules/devops-graceful-shutdown.md5.8 KB
- 参考文档rules/devops-use-config-module.md4.3 KB
- 参考文档rules/devops-use-logging.md5.6 KB
- 参考文档rules/di-avoid-service-locator.md2.9 KB
- 参考文档rules/di-interface-segregation.md5.1 KB
- 参考文档rules/di-liskov-substitution.md7.1 KB
- 参考文档rules/di-prefer-constructor-injection.md2.3 KB
- 参考文档rules/di-scope-awareness.md2.6 KB
- 参考文档rules/di-use-interfaces-tokens.md2.5 KB
- 参考文档rules/error-handle-async-errors.md3.4 KB
- 参考文档rules/error-throw-http-exceptions.md3.1 KB
- 参考文档rules/error-use-exception-filters.md3.6 KB
- 参考文档rules/micro-use-health-checks.md5.8 KB
- 参考文档rules/micro-use-patterns.md5.0 KB
- 参考文档rules/micro-use-queues.md6.1 KB
- 参考文档rules/perf-async-hooks.md2.8 KB
- 参考文档rules/perf-lazy-loading.md3.7 KB
- 参考文档rules/perf-optimize-database.md3.2 KB
- 参考文档rules/perf-use-caching.md3.4 KB
- 参考文档rules/security-auth-jwt.md4.0 KB
- 参考文档rules/security-rate-limiting.md3.2 KB
- 参考文档rules/security-sanitize-output.md3.7 KB
- 参考文档rules/security-use-guards.md3.6 KB
- 参考文档rules/security-validate-all-input.md3.3 KB
- 参考文档rules/test-e2e-supertest.md4.7 KB
- 参考文档rules/test-mock-external-services.md4.5 KB
- 参考文档rules/test-use-testing-module.md4.3 KB
03 SKILL.md 正文
NestJS Best Practices
Comprehensive best practices guide for NestJS applications. Contains 40 rules across 10 categories, prioritized by impact to guide automated refactoring and code generation.
When to Apply
Reference these guidelines when:
- Writing new NestJS modules, controllers, or services
- Implementing authentication and authorization
- Reviewing code for architecture and security issues
- Refactoring existing NestJS codebases
- Optimizing performance or database queries
- Building microservices architectures
Rule Categories by Priority
| Priority | Category | Impact | Prefix |
|---|---|---|---|
| 1 | Architecture | CRITICAL | arch- |
| 2 | Dependency Injection | CRITICAL | di- |
| 3 | Error Handling | HIGH | error- |
| 4 | Security | HIGH | security- |
| 5 | Performance | HIGH | perf- |
| 6 | Testing | MEDIUM-HIGH | test- |
| 7 | Database & ORM | MEDIUM-HIGH | db- |
| 8 | API Design | MEDIUM | api- |
| 9 | Microservices | MEDIUM | micro- |
| 10 | DevOps & Deployment | LOW-MEDIUM | devops- |
Quick Reference
1. Architecture (CRITICAL)
arch-avoid-circular-deps- Avoid circular module dependenciesarch-feature-modules- Organize by feature, not technical layerarch-module-sharing- Proper module exports/imports, avoid duplicate providersarch-single-responsibility- Focused services over "god services"arch-use-repository-pattern- Abstract database logic for testabilityarch-use-events- Event-driven architecture for decoupling
2. Dependency Injection (CRITICAL)
di-avoid-service-locator- Avoid service locator anti-patterndi-interface-segregation- Interface Segregation Principle (ISP)di-liskov-substitution- Liskov Substitution Principle (LSP)di-prefer-constructor-injection- Constructor over property injectiondi-scope-awareness- Understand singleton/request/transient scopesdi-use-interfaces-tokens- Use injection tokens for interfaces
3. Error Handling (HIGH)
error-use-exception-filters- Centralized exception handlingerror-throw-http-exceptions- Use NestJS HTTP exceptionserror-handle-async-errors- Handle async errors properly
4. Security (HIGH)
security-auth-jwt- Secure JWT authenticationsecurity-validate-all-input- Validate with class-validatorsecurity-use-guards- Authentication and authorization guardssecurity-sanitize-output- Prevent XSS attackssecurity-rate-limiting- Implement rate limiting
5. Performance (HIGH)
perf-async-hooks- Proper async lifecycle hooksperf-use-caching- Implement caching strategiesperf-optimize-database- Optimize database queriesperf-lazy-loading- Lazy load modules for faster startup
6. Testing (MEDIUM-HIGH)
test-use-testing-module- Use NestJS testing utilitiestest-e2e-supertest- E2E testing with Supertesttest-mock-external-services- Mock external dependencies
7. Database & ORM (MEDIUM-HIGH)
db-use-transactions- Transaction managementdb-avoid-n-plus-one- Avoid N+1 query problemsdb-use-migrations- Use migrations for schema changes
8. API Design (MEDIUM)
api-use-dto-serialization- DTO and response serializationapi-use-interceptors- Cross-cutting concernsapi-versioning- API versioning strategiesapi-use-pipes- Input transformation with pipes
9. Microservices (MEDIUM)
micro-use-patterns- Message and event patternsmicro-use-health-checks- Health checks for orchestrationmicro-use-queues- Background job processing
10. DevOps & Deployment (LOW-MEDIUM)
devops-use-config-module- Environment configurationdevops-use-logging- Structured loggingdevops-graceful-shutdown- Zero-downtime deployments
How to Use
Read individual rule files for detailed explanations and code examples:
rules/arch-avoid-circular-deps.md
rules/security-validate-all-input.md
rules/_sections.md
Each rule file contains:
- Brief explanation of why it matters
- Incorrect code example with explanation
- Correct code example with explanation
- Additional context and references
Full Compiled Document
For the complete guide with all rules expanded in a single document, see AGENTS.md in the repository.
04 同仓库更多 Skills
zk-proofs
Zero-knowledge proofs and privacy patterns on Stellar. Covers Groth16 verification in smart contracts via BLS12-381 host functions (CAP-0059, available), the BN254 + Poseidon proposals (CAP-0074/0075, status-sensitive), and concrete toolchain walkthroughs for Circom (on-chain verifiable today), Noir, and RISC Zero (attestation pattern until BN254 lands). Use when building privacy-preserving applications, ZK-verifier contracts, or wiring a proving toolchain to Stellar.
tyler-architect
System architect and technical design leader. Use when the user asks to talk to Tyler or requests the architect.
stellar-help
Analyzes current state and user query to answer BMad questions or recommend the next skill(s) to use. Use when user asks for help, bmad help, what to do next, or what to start with in BMad.
stellar-competitive-landscape
Map the competitive landscape for a Stellar project idea. Use when a user says "who are my competitors on Stellar", "competitive analysis Stellar", "what already exists in this space on Stellar", "show me similar Stellar projects", "is anyone else building this on Stellar", or "map the Stellar landscape for X". Queries the 728-project LumenLoop ecosystem database and Electric Capital developer activity to rank competitors by SCF funding history and repo activity.
standards
Stellar standards, ecosystem, and reference. Covers SEPs (Stellar Ecosystem Proposals), CAPs (Core Advancement Proposals), and a quick map for picking the right standard for wallets, anchors, payments, deposits/withdrawals, federation, deep links, and KYC. Also bundles ecosystem references (DeFi protocols, dev tools, wallets, infra, community projects), curated documentation links, and MCP servers (live tools such as Raven). Use when you need to know which SEP applies, or want a starting point for ecosystem integrations, official docs, or live MCP tooling.
smart-contracts
Stellar smart contract development (Rust, soroban-sdk). Entry point with project setup, contract anatomy, and build/deploy workflow, routing to three companion files in this directory - development.md (storage/TTL, authorization, cross-contract calls, tokens, events, errors, upgrades, fees, troubleshooting), testing.md (unit, fuzz, property, fork, mutation, integration), and security.md (vulnerability classes, checklists, tooling, audits). Use when writing, testing, reviewing, securing, debugging, or shipping Stellar smart contracts, including anything the user calls "Soroban" - Soroban contracts, soroban-sdk, Soroban auth/storage/TTL errors, SEP-41 tokens, or SAC integration from contract code.