Nestjs Clean Typescript

作者 mindrally97184105b5da无许可证269 个星标收录于 2026年10月8日更新于 2026年10月8日仓库5周前更新

Clean NestJS API development with TypeScript following SOLID principles, modular architecture, and comprehensive testing practices.

AI 生成的概览

使用 TypeScript 编写整洁 NestJS API 的指南,涵盖 SOLID 原则、模块化架构与测试实践。

功能
该技能提供一套用 TypeScript 开发 NestJS API 的编码规范。内容涵盖 TypeScript 通用原则、命名约定、函数设计、数据与类规则,以及 NestJS 相关架构,如模块、MikroORM 实体、DTO 和核心拦截器,还有使用 Jest 的测试。它输出的是指导建议,而不是代码或文件。
适用场景
适用于编写或审查 TypeScript 的 NestJS API 代码,并希望统一类型、结构和测试约定时。也适合团队规范模块化 NestJS 服务以及单元测试和端到端测试实践。
运行要求
不需要脚本或工具,仅为说明性指导。其内容假设项目使用 TypeScript、MikroORM、class-validator 和 Jest 的 NestJS 项目。

NestJS Clean TypeScript

Guidelines by Alberto Basalo for developing clean NestJS APIs using TypeScript. These rules emphasize strong typing, clean code principles, and architectural best practices.

TypeScript General Principles

  • Always declare the type of each variable and function (parameters and return value)
  • Avoid using any; create necessary types instead
  • Use JSDoc for public classes and methods
  • One export per file

Naming Conventions

  • PascalCase for classes
  • camelCase for variables and functions
  • kebab-case for files and directories
  • UPPERCASE for environment variables
  • Boolean variables use prefixes: isX, hasX, canX

Function Design

  • Write short functions with a single purpose. Less than 20 instructions
  • Use early returns to avoid nesting
  • Apply RO-RO pattern: pass objects for multiple parameters, return objects for results

Data and Classes

  • Prefer immutability for data with readonly and as const
  • Follow SOLID principles
  • Classes should have:
    • Less than 200 instructions
    • Fewer than 10 public methods
    • Fewer than 10 properties

NestJS Specific Guidelines

  • Use modular architecture with one module per domain/route
  • Use MikroORM entities for persistence
  • One service per entity
  • DTOs validated with class-validator
  • Global filters, middlewares, guards, and interceptors in core module

Testing

  • Use Jest framework
  • Follow Arrange-Act-Assert convention
  • Write unit tests for each public function
  • Include end-to-end tests per API module

来源与署名

来源:mindrally/skills位于nestjs-clean-typescript提交9718410

许可证: 无许可证

内容归原作者所有。SourceWeft 从公开仓库中收录这些内容。

举报或申请下架