nestjs-patterns

src/modules/users/ ├── users.module.ts ├── users.controller.ts ├── users.service.ts ├── dto/ │ ├── create-user.dto.ts │ └── update-user.dto.ts ├── entities/ │ └── user.entity.ts └── guards/ └── user-owner.guard.ts

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "nestjs-patterns" with this command: npx skills add sabahattinkalkan/antigravity-fullstack-hq/sabahattinkalkan-antigravity-fullstack-hq-nestjs-patterns

NestJS Patterns

Module Structure

src/modules/users/ ├── users.module.ts ├── users.controller.ts ├── users.service.ts ├── dto/ │ ├── create-user.dto.ts │ └── update-user.dto.ts ├── entities/ │ └── user.entity.ts └── guards/ └── user-owner.guard.ts

Key Patterns

Module Definition

@Module({ imports: [PrismaModule], controllers: [UsersController], providers: [UsersService], exports: [UsersService], }) export class UsersModule {}

DTOs with Validation

import { IsEmail, IsString, MinLength } from 'class-validator'

export class CreateUserDto { @IsEmail() email: string

@IsString() @MinLength(8) password: string }

Service Pattern

@Injectable() export class UsersService { constructor(private readonly prisma: PrismaService) {}

async create(dto: CreateUserDto) { return this.prisma.user.create({ data: dto }) }

async findOne(id: string) { const user = await this.prisma.user.findUnique({ where: { id } }) if (!user) throw new NotFoundException() return user } }

Controller Pattern

@Controller('users') export class UsersController { constructor(private readonly usersService: UsersService) {}

@Post() @HttpCode(HttpStatus.CREATED) create(@Body() dto: CreateUserDto) { return this.usersService.create(dto) }

@Get(':id') @UseGuards(JwtAuthGuard) findOne(@Param('id') id: string) { return this.usersService.findOne(id) } }

Guards

@Injectable() export class JwtAuthGuard extends AuthGuard('jwt') {}

@Injectable() export class ResourceOwnerGuard implements CanActivate { canActivate(context: ExecutionContext): boolean { const request = context.switchToHttp().getRequest() return request.user.id === request.params.id } }

Custom Decorators

export const CurrentUser = createParamDecorator( (data: string, ctx: ExecutionContext) => { const request = ctx.switchToHttp().getRequest() return data ? request.user?.[data] : request.user }, )

// Usage: @CurrentUser() user or @CurrentUser('id') id

Forbidden Patterns

  • Business logic in controllers

  • Returning sensitive data (passwords)

  • No validation on inputs

  • Hardcoded secrets

  • Skipping error handling

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

General

prompt-engineering

No summary provided by upstream source.

Repository SourceNeeds Review
General

nextjs-app-router

No summary provided by upstream source.

Repository SourceNeeds Review
General

Workspace Trash

Soft-delete protection for workspace files. Intercept file deletions and move them to a recoverable trash instead of permanent removal. Use when deleting, re...

Registry SourceRecently Updated
General

Deploy Public

Private-to-public repo sync. Copies everything except ai/ to the public mirror. Creates PR, merges, syncs releases.

Registry SourceRecently Updated