Nestjs api standards
Skill ComeOnOliver/skillshub/skills/HoangNguyen0403/agent-skills-standard/nestjs-api-standards
Response wrapping, pagination, and error standardization. Use when standardizing API response envelopes, pagination, or error formats in NestJS. (triggers: **/*.controller.ts, **/*.dto.ts, ApiResponse, Pagination, TransformInterceptor)From its SKILL.md
npx -y skills add ComeOnOliver/skillshub --skill nestjs-api-standardsAssembled from the repository path, not quoted from the project. Check it against their README if it does not work.
SKILL.md
2.2 KB, 434 tokens by cl100k_base, as published. Nobody here has run it
NestJS API Standards & Common Patterns
Priority: P1 (OPERATIONAL)
Standardized API response patterns and common NestJS conventions.
Generic Response Wrapper
- Concept: Standardize all successful API responses.
- Implementation: Use
TransformInterceptorto wrap data in{ statusCode, data, meta }.
Response Mapping (Critical)
- [Rule] Zero-Entity Exposure: Controllers MUST NOT return raw ORM entities. Every endpoint must map its result to a dedicated Response DTO (e.g.,
plainToInstance(UserResponseDto, user)) to prevent accidental exposure of internal fields or circular dependencies.
Deep Validation (Critical)
- [Rule] Nested Validation: When a DTO property is an object or an array of objects, you MUST use
@ValidateNested()along with@Type(() => TargetDto)fromclass-transformerto ensure deep validation.
Pagination Standards (Pro)
- DTOs: Use strict
PageOptionsDto(page/take/order) andPageDto<T>(data/meta). - Swagger Logic: Generics require
ApiExtraModelsand schema path resolution. - Reference: See Pagination Wrapper Implementation for the complete
ApiPaginatedResponsedecorator code.
Custom Error Response
- Standard Error Object: Define
ApiErrorResponsewithstatusCode,message,error,timestamp,path. See Error Response Class. - Docs: Apply
@ApiBadRequestResponse({ type: ApiErrorResponse })globally or per controller.
Anti-Patterns
- No raw entity returns: Always map to a Response DTO; raw entities leak internal fields.
- No unvalidated nested DTOs: Use
@ValidateNested()+@Type()for all nested object properties. - No generic 200 docs: Apply
@ApiResponse({ status, type })with exact types per endpoint.
References
What ships with it
Read from the repository
Just SKILL.md. No reference files, no scripts.