> 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)
curl "https://skillshub.wtf/HoangNguyen0403/agent-skills-standard/nestjs-api-standards?format=md"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:
export class ApiErrorResponse { @ApiProperty() statusCode: number; @ApiProperty() message: string; @ApiProperty() error: string; @ApiProperty() timestamp: string; @ApiProperty() path: string; } -
Docs: Apply
@ApiBadRequestResponse({ type: ApiErrorResponse })globally or per controller.
🚫 Anti-Patterns
- Do NOT use standard patterns if specific project rules exist.
- Do NOT ignore error handling or edge cases.
> related_skills --same-repo
> typescript-tooling
Development tools, linting, and build config for TypeScript. Use when configuring ESLint, Prettier, Jest, Vitest, tsconfig, or any TS build tooling. (triggers: tsconfig.json, .eslintrc.*, jest.config.*, package.json, eslint, prettier, jest, vitest, build, compile, lint)
> typescript-security
Secure coding practices for TypeScript. Use when validating input, handling auth tokens, sanitizing data, or managing secrets and sensitive configuration. (triggers: **/*.ts, **/*.tsx, validate, sanitize, xss, injection, auth, password, secret, token)
> typescript-language
Modern TypeScript standards for type safety and maintainability. Use when working with types, interfaces, generics, enums, unions, or tsconfig settings. (triggers: **/*.ts, **/*.tsx, tsconfig.json, type, interface, generic, enum, union, intersection, readonly, const, namespace)
> typescript-best-practices
Idiomatic TypeScript patterns for clean, maintainable code. Use when writing or refactoring TypeScript classes, functions, modules, or async logic. (triggers: **/*.ts, **/*.tsx, class, function, module, import, export, async, promise)