NestJS Modules, Guards, DTOs and DI Fixes

Build and debug NestJS modules: validated DTOs, deny-by-default auth guards, DI fixes, Prisma/TypeORM wiring, and working tests.

Development / Backendnestjstypescript
by AgentVoltv1.0.0
Free to sign up · every skill included with AgentVolt Pro

Before & after

Same prompt, same agent — the only difference is the skill.

Prompt“Build a NestJS endpoint that validates and creates a user account.”
Beforegeneric AI agent
You'll want to create a controller that handles the HTTP request, a service to handle the business logic, and a DTO to validate the input. NestJS uses decorators and dependency injection, so you'll need to set up the module structure. Add validation decorators to the DTO fields. You might also want to include error handling and consider using a pipe to validate the incoming data. Would you like me to walk through each piece separately?
Afterwith NestJS Modules, Guards, DTOs and DI Fixes
NESTJS USER CREATION ENDPOINT (complete module)

FILE: src/users/create-user.dto.ts
export class CreateUserDto {
  @IsEmail()
  email: string;
  @IsString() @MinLength(8) @MaxLength(64)
  password: string;
  @IsString() @MinLength(2) @MaxLength(50)
  firstName: string;
}

FILE: src/users/users.service.ts
@Injectable()
export class UsersService {
  constructor(private prisma: PrismaService, private hash: HashService) {}
  
  async createUser(dto: CreateUserDto) {
    const existing = await this.prisma.user.findUnique({where: {email: dto.email}});
    if (existing) throw new ConflictException("Email already registered");
    
    const hashed = await this.hash.bcrypt(dto.password);
    return this.prisma.user.create({
      data: {email: dto.email, hashedPassword: hashed, firstName: dto.firstName},
      select: {id: true, email: true, firstName: true, createdAt: true}
    });
  }
}

FILE: src/users/users.controller.ts
@Controller("users")
export class UsersController {
  constructor(private users: UsersService) {}
  
  @Post()
  @HttpCode(201)
  async register(@Body(new ValidationPipe()) dto: CreateUserDto) {
    return this.users.createUser(dto);
  }
}

FILE: src/users/users.module.ts
@Module({
  imports: [PrismaModule],
  controllers: [UsersController],
  providers: [UsersService, HashService]
})
export class UsersModule {}

RESULT: POST /users with CreateUserDto triggers validation, hashes password, checks uniqueness, persists to database, returns sanitized user object (no password hash). Errors: 400 for validation, 409 for duplicate email, 500 for database failure.

About this skill

"Nest can't resolve dependencies of..." again. Or your ValidationPipe ignores nested objects, your password hash leaks into API responses, or your e2e tests pass while skipping the global guards. This skill builds and repairs NestJS code by reasoning from module boundaries and the request lifecycle, so the generated code survives contact with a real app.

What it does

  • Diagnoses DI errors in a fixed triage order: missing export or import, interface tokens, type-only imports, barrel-file cycles, and true module cycles
  • Scaffolds feature modules with class-validator DTOs that handle nested objects, arrays, and string query params correctly
  • Sets up deny-by-default JWT auth with a global guard, a @Public() decorator, and correctly ordered role guards
  • Wires Prisma or TypeORM with transactions, unique-violation mapping to 409, and response DTOs that keep secrets out of payloads
  • Registers pipes, guards, and filters as APP_* providers so e2e tests run the same pipeline as production
  • Reviews pasted Nest code by severity: security, data loss, runtime failure, then maintainability

What you get

Working module files with the exact wiring lines, a unit test plus an e2e test for the riskiest path, and stated assumptions. For pasted errors, you get the root cause and a minimal diff.

Best for

TypeScript backend developers building or maintaining NestJS REST APIs, especially teams fighting recurring DI errors, auth gaps, or flaky e2e setups.

SKILL.md preview

SKILL.md
---
name: nestjs-modules-guards-dtos-di-fixes

… (sign up to view the full skill)
Sign up to view, copy, and install the full skill

More development skills

View all Development skills →