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 從公開儲存庫中收錄這些內容。

檢舉或申請下架