npx agentspec-cli install 9d271d18-c78e-4804-8dd7-cbc52ee58f34 --framework ClaudeCode→ .claude/skills/Home Tour Configuration/SKILL.md
**DTO Refactoring Manual**
**Purpose:** This manual provides guidelines for refactoring and improving Data Transfer Objects DTOs) in a NestJS application.
**Goals:**
* Improve code readability and maintainability
* Follow NestJS best practices
* Enhance code consistency and flexibility
**Refactoring Steps:**
### 1. Consistent Naming Conventions
* Use `PascalCase` for class and interface names (e.g., `UserCreateDto` instead of `userCreateDto`).
* Use `camelCase` for property names (e.g., `userName` instead of `username`).
### 2. Validate Decorators
* Use `@ValidateNested()` instead of `@Validate()` when validating nested objects.
* Consider using `@ApiModelProperty()` to add documentation for each property.
### 3. Use Interfaces for DTOs
* Instead of using classes for DTOs, use interfaces. This approach is more lightweight and flexible.
* Use the `@nestjs/mapped-types` package to create mapped types for your DTOs.
### 4. Simplify Constructor Logic
* Instead of using constructors with multiple arguments, use a single object argument and estructuring it.
* Use the `class-transformer` package to automatically convert JSON data to DTO objects.
### 5. Remove Unnecessary Dependencies
* Remove unnecessary imports and dependencies from DTOs.
### 6. Consistent Use of Decorators
* Use `@IsOptional()` consistently throughout the DTOs to indicate optional properties.
* Use `@IsEnum()` consistently throughout the DTOs to indicate enum values.
### 7. Use NestJS Built-in Validators
* Use NestJS built-in validators (e.g., `@IsString()`, `@IsEnum()`) instead of custom implementations.
* Configure validator options globally whenever possible.
### 8. Remove Redundant Imports
* Remove unused imports from DTOs.
### 9. Optional and Not Empty Validators
* When using `@IsOptional()` and `@IsNotEmpty()` together, `@IsOptional()` takes precedence. This means that if the property is not provided, it won't be validated, but if it is provided, the u/IsNotEmpty()` decorator will ensure it's not an empty string.
**Example Refactored DTO:**
```typescript
import { IsString, IsEnum, IsOptional } from 'class-validator';
import { EnumExample } from './enum-example.enum';
export interface ExampleDto {
u/IsString()
name: string;
@IsOptional()
@IsEnum(EnumExample)
status?: EnumExample;
@IsOptional()
@IsDate()
createdAt?: Date;
}
``` Built on the Agent Skills standard
TypeScript General Guidelines
Cursor IDE rules and conventions for AI-assisted development.
by AgentHub Crawler
TypeScript Best Practices
Cursor IDE rules and conventions for AI-assisted development.
by AgentHub Crawler
refactor
Surgical code refactoring to improve maintainability without changing behavior. Covers extracting functions, renaming variables, breaking down god functions, improving type safety, eliminating code smells, and applying design patterns. Less drastic than repo-rebuilder; use for gradual improvements.
by AgentHub Crawler
Sign in to leave a comment.
Tech Stack
SYSTEM: # Code Quality Guidelines
by AgentHub Crawler