[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M74X8XSNMWZ74XRT63X0CYY1":3,"skill-same:01M74X8XSNMWZ74XRT63X0CYY1":46},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":25,"commitSha":26,"skillDirectory":27,"forksCount":14,"repositoryHtmlUrl":28,"repositoryHomepageUrl":6,"ownerHtmlUrl":29,"ownerBlogUrl":6,"ownerDescription":30,"updatedAt":31,"install":32,"resources":45},"01M74X8XSNMWZ74XRT63X0CYY1","nestjs-patterns",null,"NestJS architecture patterns for modules, controllers, providers, DTO validation, guards, interceptors, config, and production-grade TypeScript backends.","DS-PROYECTO-ARROW-MAZE\u002Farrowmaze-frontend","DS-PROYECTO-ARROW-MAZE","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F284100063?v=4","01M74X8A9F5638W98PBEJ2BY4C","ARROW-MAZE-EQ01","01M74X8AA6RGDRE1TMHBH95A7M",0,"MIT","https:\u002F\u002Fgithub.com\u002FDS-PROYECTO-ARROW-MAZE\u002Farrowmaze-frontend\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fnestjs-patterns\u002FSKILL.md",[],[],"2026-11-12 13:55:43",false,"---\nname: nestjs-patterns\ndescription: NestJS architecture patterns for modules, controllers, providers, DTO validation, guards, interceptors, config, and production-grade TypeScript backends.\norigin: ECC\n---\n\n# NestJS Development Patterns\n\nProduction-grade NestJS patterns for modular TypeScript backends.\n\n## When to Activate\n\n- Building NestJS APIs or services\n- Structuring modules, controllers, and providers\n- Adding DTO validation, guards, interceptors, or exception filters\n- Configuring environment-aware settings and database integrations\n- Testing NestJS units or HTTP endpoints\n\n## Project Structure\n\nHexagonal architecture (Ports & Adapters): the domain has zero framework dependencies; application defines use cases and ports; infrastructure wires everything together.\n\n```text\nprisma\u002F                              ← Prisma lives at the project root, NOT inside src\u002F\n├── schema.prisma                    ← datasource (Supabase Postgres), generator, models\n├── migrations\u002F                      ← versioned migrations (prisma migrate)\n└── seed.ts                          ← optional seed script\n\nsrc\u002F\n├── app.module.ts\n├── main.ts\n│\n├── domain\u002F                          ← pure TypeScript, no NestJS\u002FPrisma imports\n│   ├── entities\u002F                    ← aggregates & entities (NOT Prisma models)\n│   ├── value-objects\u002F               ← value objects with validating factories\n│   ├── events\u002F                      ← domain events raised by aggregates\n│   ├── repositories\u002F                ← repository interfaces (driven ports)\n│   └── services\u002F                    ← stateless domain logic (optional; for rules\n│                                       that don't belong to a single aggregate)\n│\n├── application\u002F                     ← depends on domain only\n│   ├── use-cases\u002F                   ← one class per use case (implement the use-case contract)\n│   ├── dtos\u002F                        ← input\u002Foutput contracts\n│   ├── ports\u002F                       ← driven-side interfaces (hash, token, events,\n│   │                                  unit-of-work, read-model queries, …)\n│   ├── mappers\u002F                     ← domain ↔ DTO conversion\n│   └── decorators\u002F                  ← AOP use-case decorators (logging, metrics) that\n│                                       wrap the use-case contract — NOT NestJS HTTP interceptors\n│\n└── infrastructure\u002F                  ← framework + third-party glue\n    ├── adapters\u002F\n    │   ├── http\u002F                    ← driving adapters (NestJS HTTP)\n    │   │   ├── controllers\u002F\n    │   │   ├── guards\u002F\n    │   │   ├── filters\u002F\n    │   │   ├── interceptors\u002F        ← NestJS HTTP interceptors (distinct from application\u002Fdecorators\u002F)\n    │   │   └── pipes\u002F\n    │   ├── persistence\u002F             ← driven adapters backed by Prisma\n    │   │   ├── prisma\u002F              ← PrismaService (extends PrismaClient) + module\n    │   │   ├── repositories\u002F        ← implement domain repo interfaces via Prisma (return aggregates)\n    │   │   ├── mappers\u002F             ← Prisma row ↔ domain aggregate conversion\n    │   │   ├── queries\u002F             ← read-model adapters (Prisma\u002Fraw SQL → response DTOs)\n    │   │   └── unit-of-work\u002F        ← transaction boundary wrapping prisma.$transaction\n    │   ├── security\u002F                ← driven adapters for auth ports (hashing, token signing)\n    │   └── events\u002F                  ← driven adapter that publishes domain events\n    ├── config\u002F\n    │   ├── configuration.ts\n    │   └── validation.ts\n    └── modules\u002F                     ← NestJS module wiring\n```\n\n- `domain\u002F` must never import from `application\u002F`, `infrastructure\u002F`, NestJS, or Prisma. Domain entities are hand-written aggregates, **not** the types Prisma generates.\n- `application\u002F` imports only from `domain\u002F`. Use cases depend on repository and port interfaces, not implementations.\n- `infrastructure\u002F` is the only layer that imports NestJS decorators and the Prisma client.\n- The Prisma schema and migrations live in a root-level `prisma\u002F` folder (Prisma's convention), separate from `src\u002F`. The generated client is the default `@prisma\u002Fclient`.\n- Controllers live in `infrastructure\u002Fadapters\u002Fhttp\u002F` — they are adapters, not domain logic.\n- Repository implementations in `infrastructure\u002Fadapters\u002Fpersistence\u002Frepositories\u002F` implement the interfaces from `domain\u002Frepositories\u002F` using the injected `PrismaService`, and use `persistence\u002Fmappers\u002F` to translate Prisma rows ↔ domain aggregates (so Prisma types never leak past this layer).\n- One adapter folder per port category: `persistence\u002F` (prisma client, repositories, mappers, queries, unit-of-work), `security\u002F` (hash, token), `events\u002F` (publisher). Add more as new ports appear.\n- **Two different \"interceptor\" concepts:** application-level AOP decorators that wrap the use-case contract live in `application\u002Fdecorators\u002F`; NestJS request\u002Fresponse interceptors live in `infrastructure\u002Fadapters\u002Fhttp\u002Finterceptors\u002F`. Don't conflate them.\n- Read-model queries (e.g. ranking\u002Fleaderboard) return DTOs and live in `persistence\u002Fqueries\u002F`, separate from aggregate-returning `repositories\u002F`.\n\n## Bootstrap and Global Validation\n\n```ts\nasync function bootstrap() {\n  const app = await NestFactory.create(AppModule, { bufferLogs: true });\n\n  app.useGlobalPipes(\n    new ValidationPipe({\n      whitelist: true,\n      forbidNonWhitelisted: true,\n      transform: true,\n      transformOptions: { enableImplicitConversion: true },\n    }),\n  );\n\n  app.useGlobalInterceptors(new ClassSerializerInterceptor(app.get(Reflector)));\n  app.useGlobalFilters(new HttpExceptionFilter());\n\n  await app.listen(process.env.PORT ?? 3000);\n}\nbootstrap();\n```\n\n- Always enable `whitelist` and `forbidNonWhitelisted` on public APIs.\n- Prefer one global validation pipe instead of repeating validation config per route.\n\n## Modules, Controllers, and Providers\n\nEach feature is wired in `infrastructure\u002Fmodules\u002F`. The controller delegates to an application use case; the use case depends on a domain repository interface that the infrastructure repository implements.\n\n```ts\n\u002F\u002F infrastructure\u002Fmodules\u002Fusers.module.ts\n@Module({\n  imports: [PrismaModule],\n  controllers: [UsersController],\n  providers: [\n    CreateUserUseCase,\n    { provide: USER_REPOSITORY, useClass: PrismaUserRepository },\n  ],\n})\nexport class UsersModule {}\n\n\u002F\u002F infrastructure\u002Fadapters\u002Fhttp\u002Fcontrollers\u002Fusers.controller.ts\n@Controller('users')\nexport class UsersController {\n  constructor(private readonly createUser: CreateUserUseCase) {}\n\n  @Post()\n  create(@Body() dto: CreateUserDto) {\n    return this.createUser.execute(dto);\n  }\n\n  @Get(':id')\n  getById(@Param('id', ParseUUIDPipe) id: string) {\n    return this.createUser.getById(id);\n  }\n}\n\n\u002F\u002F application\u002Fuse-cases\u002Fcreate-user.use-case.ts\n@Injectable()\nexport class CreateUserUseCase {\n  constructor(\n    @Inject(USER_REPOSITORY) private readonly userRepo: IUserRepository,\n  ) {}\n\n  async execute(dto: CreateUserDto): Promise\u003CUserResponseDto> {\n    const user = User.create(dto);          \u002F\u002F domain entity factory\n    await this.userRepo.save(user);\n    return UserMapper.toResponse(user);\n  }\n}\n\n\u002F\u002F domain\u002Frepositories\u002Fuser.repository.interface.ts  (port)\nexport const USER_REPOSITORY = Symbol('USER_REPOSITORY');\nexport interface IUserRepository {\n  save(user: User): Promise\u003Cvoid>;\n  findById(id: string): Promise\u003CUser | null>;\n}\n\n\u002F\u002F infrastructure\u002Fadapters\u002Fpersistence\u002Fprisma\u002Fprisma.service.ts\n@Injectable()\nexport class PrismaService extends PrismaClient implements OnModuleInit {\n  async onModuleInit() {\n    await this.$connect();\n  }\n}\n\n\u002F\u002F infrastructure\u002Fadapters\u002Fpersistence\u002Frepositories\u002Fprisma-user.repository.ts\n@Injectable()\nexport class PrismaUserRepository implements IUserRepository {\n  constructor(private readonly prisma: PrismaService) {}\n\n  async save(user: User): Promise\u003Cvoid> {\n    const row = UserPrismaMapper.toPersistence(user);\n    await this.prisma.user.upsert({ where: { id: row.id }, create: row, update: row });\n  }\n\n  async findById(id: string): Promise\u003CUser | null> {\n    const row = await this.prisma.user.findUnique({ where: { id } });\n    return row ? UserPrismaMapper.toDomain(row) : null;\n  }\n}\n```\n\n- Controllers are thin HTTP adapters: parse input, call one use case, return the result.\n- Use cases own business flow; they speak domain language and depend on interfaces, not concrete repos.\n- Inject repository implementations via a Symbol token so use cases never import infrastructure.\n- The repository receives `PrismaService` and maps Prisma rows to domain aggregates with a persistence mapper — Prisma types stay inside `persistence\u002F`.\n\n## DTOs and Validation\n\nDTOs live in `application\u002Fdtos\u002F` — they are the contract between the HTTP adapter and the use case. Domain entities must never be returned directly from controllers.\n\n```ts\n\u002F\u002F application\u002Fdtos\u002Fcreate-user.dto.ts\nexport class CreateUserDto {\n  @IsEmail()\n  email!: string;\n\n  @IsString()\n  @Length(2, 80)\n  name!: string;\n\n  @IsOptional()\n  @IsEnum(UserRole)\n  role?: UserRole;\n}\n\n\u002F\u002F application\u002Fmappers\u002Fuser.mapper.ts\nexport class UserMapper {\n  static toResponse(user: User): UserResponseDto {\n    return { id: user.id, email: user.email, name: user.name };\n  }\n}\n```\n\n- Validate every request DTO with `class-validator` at the HTTP adapter boundary.\n- Use mappers in `application\u002Fmappers\u002F` to convert domain entities to response DTOs.\n- Avoid leaking internal fields such as password hashes, tokens, or audit columns.\n\n## Auth, Guards, and Request Context\n\n```ts\n@UseGuards(JwtAuthGuard, RolesGuard)\n@Roles('admin')\n@Get('admin\u002Freport')\ngetAdminReport(@Req() req: AuthenticatedRequest) {\n  return this.reportService.getForUser(req.user.id);\n}\n```\n\n- Keep auth strategies and guards module-local unless they are truly shared.\n- Encode coarse access rules in guards, then do resource-specific authorization in services.\n- Prefer explicit request types for authenticated request objects.\n\n## Exception Filters and Error Shape\n\n```ts\n@Catch()\nexport class HttpExceptionFilter implements ExceptionFilter {\n  catch(exception: unknown, host: ArgumentsHost) {\n    const response = host.switchToHttp().getResponse\u003CResponse>();\n    const request = host.switchToHttp().getRequest\u003CRequest>();\n\n    if (exception instanceof HttpException) {\n      return response.status(exception.getStatus()).json({\n        path: request.url,\n        error: exception.getResponse(),\n      });\n    }\n\n    return response.status(500).json({\n      path: request.url,\n      error: 'Internal server error',\n    });\n  }\n}\n```\n\n- Keep one consistent error envelope across the API.\n- Throw framework exceptions for expected client errors; log and wrap unexpected failures centrally.\n\n## Config and Environment Validation\n\n```ts\nConfigModule.forRoot({\n  isGlobal: true,\n  load: [configuration],\n  validate: validateEnv,\n});\n```\n\n- Validate env at boot, not lazily at first request.\n- Keep config access behind typed helpers or config services.\n- Split dev\u002Fstaging\u002Fprod concerns in config factories instead of branching throughout feature code.\n\n## Persistence and Transactions (Prisma)\n\n- Define repository interfaces (ports) in `domain\u002Frepositories\u002F` — no Prisma types, only domain entities.\n- Implement those interfaces in `infrastructure\u002Fadapters\u002Fpersistence\u002Frepositories\u002F` using the injected `PrismaService` — this is the only place `@prisma\u002Fclient` imports are allowed.\n- Keep the Prisma schema and migrations in the root-level `prisma\u002F` folder. Run `prisma generate` on install and `prisma migrate` for schema changes; never hand-edit generated client code.\n- Map Prisma rows to domain aggregates in `persistence\u002Fmappers\u002F` so generated Prisma model types never leak into `domain\u002F` or `application\u002F`.\n- Wrap multi-step writes in `prisma.$transaction(...)` behind the `IUnidadDeTrabajo`\u002Funit-of-work port (`persistence\u002Funit-of-work\u002F`); use cases coordinate the transaction, controllers never do.\n- Expose a `PrismaModule` that provides and exports `PrismaService` so feature modules can inject it.\n\n## Testing\n\n```ts\ndescribe('UsersController', () => {\n  let app: INestApplication;\n\n  beforeAll(async () => {\n    const moduleRef = await Test.createTestingModule({\n      imports: [UsersModule],\n    }).compile();\n\n    app = moduleRef.createNestApplication();\n    app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }));\n    await app.init();\n  });\n});\n```\n\n- Unit test providers in isolation with mocked dependencies.\n- Add request-level tests for guards, validation pipes, and exception filters.\n- Reuse the same global pipes\u002Ffilters in tests that you use in production.\n\n## Production Defaults\n\n- Enable structured logging and request correlation ids.\n- Terminate on invalid env\u002Fconfig instead of booting partially.\n- Prefer async provider initialization for DB\u002Fcache clients with explicit health checks.\n- Keep background jobs and event consumers in their own modules, not inside HTTP controllers.\n- Make rate limiting, auth, and audit logging explicit for public endpoints.\n","# NestJS Development Patterns\n\nProduction-grade NestJS patterns for modular TypeScript backends.\n\n## When to Activate\n\n- Building NestJS APIs or services\n- Structuring modules, controllers, and providers\n- Adding DTO validation, guards, interceptors, or exception filters\n- Configuring environment-aware settings and database integrations\n- Testing NestJS units or HTTP endpoints\n\n## Project Structure\n\nHexagonal architecture (Ports & Adapters): the domain has zero framework dependencies; application defines use cases and ports; infrastructure wires everything together.\n\n```text\nprisma\u002F                              ← Prisma lives at the project root, NOT inside src\u002F\n├── schema.prisma                    ← datasource (Supabase Postgres), generator, models\n├── migrations\u002F                      ← versioned migrations (prisma migrate)\n└── seed.ts                          ← optional seed script\n\nsrc\u002F\n├── app.module.ts\n├── main.ts\n│\n├── domain\u002F                          ← pure TypeScript, no NestJS\u002FPrisma imports\n│   ├── entities\u002F                    ← aggregates & entities (NOT Prisma models)\n│   ├── value-objects\u002F               ← value objects with validating factories\n│   ├── events\u002F                      ← domain events raised by aggregates\n│   ├── repositories\u002F                ← repository interfaces (driven ports)\n│   └── services\u002F                    ← stateless domain logic (optional; for rules\n│                                       that don't belong to a single aggregate)\n│\n├── application\u002F                     ← depends on domain only\n│   ├── use-cases\u002F                   ← one class per use case (implement the use-case contract)\n│   ├── dtos\u002F                        ← input\u002Foutput contracts\n│   ├── ports\u002F                       ← driven-side interfaces (hash, token, events,\n│   │                                  unit-of-work, read-model queries, …)\n│   ├── mappers\u002F                     ← domain ↔ DTO conversion\n│   └── decorators\u002F                  ← AOP use-case decorators (logging, metrics) that\n│                                       wrap the use-case contract — NOT NestJS HTTP interceptors\n│\n└── infrastructure\u002F                  ← framework + third-party glue\n    ├── adapters\u002F\n    │   ├── http\u002F                    ← driving adapters (NestJS HTTP)\n    │   │   ├── controllers\u002F\n    │   │   ├── guards\u002F\n    │   │   ├── filters\u002F\n    │   │   ├── interceptors\u002F        ← NestJS HTTP interceptors (distinct from application\u002Fdecorators\u002F)\n    │   │   └── pipes\u002F\n    │   ├── persistence\u002F             ← driven adapters backed by Prisma\n    │   │   ├── prisma\u002F              ← PrismaService (extends PrismaClient) + module\n    │   │   ├── repositories\u002F        ← implement domain repo interfaces via Prisma (return aggregates)\n    │   │   ├── mappers\u002F             ← Prisma row ↔ domain aggregate conversion\n    │   │   ├── queries\u002F             ← read-model adapters (Prisma\u002Fraw SQL → response DTOs)\n    │   │   └── unit-of-work\u002F        ← transaction boundary wrapping prisma.$transaction\n    │   ├── security\u002F                ← driven adapters for auth ports (hashing, token signing)\n    │   └── events\u002F                  ← driven adapter that publishes domain events\n    ├── config\u002F\n    │   ├── configuration.ts\n    │   └── validation.ts\n    └── modules\u002F                     ← NestJS module wiring\n```\n\n- `domain\u002F` must never import from `application\u002F`, `infrastructure\u002F`, NestJS, or Prisma. Domain entities are hand-written aggregates, **not** the types Prisma generates.\n- `application\u002F` imports only from `domain\u002F`. Use cases depend on repository and port interfaces, not implementations.\n- `infrastructure\u002F` is the only layer that imports NestJS decorators and the Prisma client.\n- The Prisma schema and migrations live in a root-level `prisma\u002F` folder (Prisma's convention), separate from `src\u002F`. The generated client is the default `@prisma\u002Fclient`.\n- Controllers live in `infrastructure\u002Fadapters\u002Fhttp\u002F` — they are adapters, not domain logic.\n- Repository implementations in `infrastructure\u002Fadapters\u002Fpersistence\u002Frepositories\u002F` implement the interfaces from `domain\u002Frepositories\u002F` using the injected `PrismaService`, and use `persistence\u002Fmappers\u002F` to translate Prisma rows ↔ domain aggregates (so Prisma types never leak past this layer).\n- One adapter folder per port category: `persistence\u002F` (prisma client, repositories, mappers, queries, unit-of-work), `security\u002F` (hash, token), `events\u002F` (publisher). Add more as new ports appear.\n- **Two different \"interceptor\" concepts:** application-level AOP decorators that wrap the use-case contract live in `application\u002Fdecorators\u002F`; NestJS request\u002Fresponse interceptors live in `infrastructure\u002Fadapters\u002Fhttp\u002Finterceptors\u002F`. Don't conflate them.\n- Read-model queries (e.g. ranking\u002Fleaderboard) return DTOs and live in `persistence\u002Fqueries\u002F`, separate from aggregate-returning `repositories\u002F`.\n\n## Bootstrap and Global Validation\n\n```ts\nasync function bootstrap() {\n  const app = await NestFactory.create(AppModule, { bufferLogs: true });\n\n  app.useGlobalPipes(\n    new ValidationPipe({\n      whitelist: true,\n      forbidNonWhitelisted: true,\n      transform: true,\n      transformOptions: { enableImplicitConversion: true },\n    }),\n  );\n\n  app.useGlobalInterceptors(new ClassSerializerInterceptor(app.get(Reflector)));\n  app.useGlobalFilters(new HttpExceptionFilter());\n\n  await app.listen(process.env.PORT ?? 3000);\n}\nbootstrap();\n```\n\n- Always enable `whitelist` and `forbidNonWhitelisted` on public APIs.\n- Prefer one global validation pipe instead of repeating validation config per route.\n\n## Modules, Controllers, and Providers\n\nEach feature is wired in `infrastructure\u002Fmodules\u002F`. The controller delegates to an application use case; the use case depends on a domain repository interface that the infrastructure repository implements.\n\n```ts\n\u002F\u002F infrastructure\u002Fmodules\u002Fusers.module.ts\n@Module({\n  imports: [PrismaModule],\n  controllers: [UsersController],\n  providers: [\n    CreateUserUseCase,\n    { provide: USER_REPOSITORY, useClass: PrismaUserRepository },\n  ],\n})\nexport class UsersModule {}\n\n\u002F\u002F infrastructure\u002Fadapters\u002Fhttp\u002Fcontrollers\u002Fusers.controller.ts\n@Controller('users')\nexport class UsersController {\n  constructor(private readonly createUser: CreateUserUseCase) {}\n\n  @Post()\n  create(@Body() dto: CreateUserDto) {\n    return this.createUser.execute(dto);\n  }\n\n  @Get(':id')\n  getById(@Param('id', ParseUUIDPipe) id: string) {\n    return this.createUser.getById(id);\n  }\n}\n\n\u002F\u002F application\u002Fuse-cases\u002Fcreate-user.use-case.ts\n@Injectable()\nexport class CreateUserUseCase {\n  constructor(\n    @Inject(USER_REPOSITORY) private readonly userRepo: IUserRepository,\n  ) {}\n\n  async execute(dto: CreateUserDto): Promise\u003CUserResponseDto> {\n    const user = User.create(dto);          \u002F\u002F domain entity factory\n    await this.userRepo.save(user);\n    return UserMapper.toResponse(user);\n  }\n}\n\n\u002F\u002F domain\u002Frepositories\u002Fuser.repository.interface.ts  (port)\nexport const USER_REPOSITORY = Symbol('USER_REPOSITORY');\nexport interface IUserRepository {\n  save(user: User): Promise\u003Cvoid>;\n  findById(id: string): Promise\u003CUser | null>;\n}\n\n\u002F\u002F infrastructure\u002Fadapters\u002Fpersistence\u002Fprisma\u002Fprisma.service.ts\n@Injectable()\nexport class PrismaService extends PrismaClient implements OnModuleInit {\n  async onModuleInit() {\n    await this.$connect();\n  }\n}\n\n\u002F\u002F infrastructure\u002Fadapters\u002Fpersistence\u002Frepositories\u002Fprisma-user.repository.ts\n@Injectable()\nexport class PrismaUserRepository implements IUserRepository {\n  constructor(private readonly prisma: PrismaService) {}\n\n  async save(user: User): Promise\u003Cvoid> {\n    const row = UserPrismaMapper.toPersistence(user);\n    await this.prisma.user.upsert({ where: { id: row.id }, create: row, update: row });\n  }\n\n  async findById(id: string): Promise\u003CUser | null> {\n    const row = await this.prisma.user.findUnique({ where: { id } });\n    return row ? UserPrismaMapper.toDomain(row) : null;\n  }\n}\n```\n\n- Controllers are thin HTTP adapters: parse input, call one use case, return the result.\n- Use cases own business flow; they speak domain language and depend on interfaces, not concrete repos.\n- Inject repository implementations via a Symbol token so use cases never import infrastructure.\n- The repository receives `PrismaService` and maps Prisma rows to domain aggregates with a persistence mapper — Prisma types stay inside `persistence\u002F`.\n\n## DTOs and Validation\n\nDTOs live in `application\u002Fdtos\u002F` — they are the contract between the HTTP adapter and the use case. Domain entities must never be returned directly from controllers.\n\n```ts\n\u002F\u002F application\u002Fdtos\u002Fcreate-user.dto.ts\nexport class CreateUserDto {\n  @IsEmail()\n  email!: string;\n\n  @IsString()\n  @Length(2, 80)\n  name!: string;\n\n  @IsOptional()\n  @IsEnum(UserRole)\n  role?: UserRole;\n}\n\n\u002F\u002F application\u002Fmappers\u002Fuser.mapper.ts\nexport class UserMapper {\n  static toResponse(user: User): UserResponseDto {\n    return { id: user.id, email: user.email, name: user.name };\n  }\n}\n```\n\n- Validate every request DTO with `class-validator` at the HTTP adapter boundary.\n- Use mappers in `application\u002Fmappers\u002F` to convert domain entities to response DTOs.\n- Avoid leaking internal fields such as password hashes, tokens, or audit columns.\n\n## Auth, Guards, and Request Context\n\n```ts\n@UseGuards(JwtAuthGuard, RolesGuard)\n@Roles('admin')\n@Get('admin\u002Freport')\ngetAdminReport(@Req() req: AuthenticatedRequest) {\n  return this.reportService.getForUser(req.user.id);\n}\n```\n\n- Keep auth strategies and guards module-local unless they are truly shared.\n- Encode coarse access rules in guards, then do resource-specific authorization in services.\n- Prefer explicit request types for authenticated request objects.\n\n## Exception Filters and Error Shape\n\n```ts\n@Catch()\nexport class HttpExceptionFilter implements ExceptionFilter {\n  catch(exception: unknown, host: ArgumentsHost) {\n    const response = host.switchToHttp().getResponse\u003CResponse>();\n    const request = host.switchToHttp().getRequest\u003CRequest>();\n\n    if (exception instanceof HttpException) {\n      return response.status(exception.getStatus()).json({\n        path: request.url,\n        error: exception.getResponse(),\n      });\n    }\n\n    return response.status(500).json({\n      path: request.url,\n      error: 'Internal server error',\n    });\n  }\n}\n```\n\n- Keep one consistent error envelope across the API.\n- Throw framework exceptions for expected client errors; log and wrap unexpected failures centrally.\n\n## Config and Environment Validation\n\n```ts\nConfigModule.forRoot({\n  isGlobal: true,\n  load: [configuration],\n  validate: validateEnv,\n});\n```\n\n- Validate env at boot, not lazily at first request.\n- Keep config access behind typed helpers or config services.\n- Split dev\u002Fstaging\u002Fprod concerns in config factories instead of branching throughout feature code.\n\n## Persistence and Transactions (Prisma)\n\n- Define repository interfaces (ports) in `domain\u002Frepositories\u002F` — no Prisma types, only domain entities.\n- Implement those interfaces in `infrastructure\u002Fadapters\u002Fpersistence\u002Frepositories\u002F` using the injected `PrismaService` — this is the only place `@prisma\u002Fclient` imports are allowed.\n- Keep the Prisma schema and migrations in the root-level `prisma\u002F` folder. Run `prisma generate` on install and `prisma migrate` for schema changes; never hand-edit generated client code.\n- Map Prisma rows to domain aggregates in `persistence\u002Fmappers\u002F` so generated Prisma model types never leak into `domain\u002F` or `application\u002F`.\n- Wrap multi-step writes in `prisma.$transaction(...)` behind the `IUnidadDeTrabajo`\u002Funit-of-work port (`persistence\u002Funit-of-work\u002F`); use cases coordinate the transaction, controllers never do.\n- Expose a `PrismaModule` that provides and exports `PrismaService` so feature modules can inject it.\n\n## Testing\n\n```ts\ndescribe('UsersController', () => {\n  let app: INestApplication;\n\n  beforeAll(async () => {\n    const moduleRef = await Test.createTestingModule({\n      imports: [UsersModule],\n    }).compile();\n\n    app = moduleRef.createNestApplication();\n    app.useGlobalPipes(new ValidationPipe({ whitelist: true, transform: true }));\n    await app.init();\n  });\n});\n```\n\n- Unit test providers in isolation with mocked dependencies.\n- Add request-level tests for guards, validation pipes, and exception filters.\n- Reuse the same global pipes\u002Ffilters in tests that you use in production.\n\n## Production Defaults\n\n- Enable structured logging and request correlation ids.\n- Terminate on invalid env\u002Fconfig instead of booting partially.\n- Prefer async provider initialization for DB\u002Fcache clients with explicit health checks.\n- Keep background jobs and event consumers in their own modules, not inside HTTP controllers.\n- Make rate limiting, auth, and audit logging explicit for public endpoints.\n",{"name":5,"origin":24,"description":7},"ECC","main","efd18d74b40a4e07b83c264b9dd4784b0f2f0546",".agents\u002Fskills\u002Fnestjs-patterns","https:\u002F\u002Fgithub.com\u002FDS-PROYECTO-ARROW-MAZE\u002Farrowmaze-frontend","https:\u002F\u002Fgithub.com\u002FDS-PROYECTO-ARROW-MAZE","Contiene el desarrollo de un clon funcional del juego casual \"Arrow Maze — Escape Puzzle\",  como proyecto semestral para la asignatura Desarrollo de Software.","2026-07-19 11:55:07",{"source":8,"skillName":5,"commands":33,"prompt":43,"zipAvailable":44},[34,37,40],{"tool":35,"command":36},"npx","npx skills add DS-PROYECTO-ARROW-MAZE\u002Farrowmaze-frontend --skill nestjs-patterns",{"tool":38,"command":39},"bunx","bunx skills add DS-PROYECTO-ARROW-MAZE\u002Farrowmaze-frontend --skill nestjs-patterns",{"tool":41,"command":42},"pnpm","pnpm dlx skills add DS-PROYECTO-ARROW-MAZE\u002Farrowmaze-frontend --skill nestjs-patterns","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FDS-PROYECTO-ARROW-MAZE\u002Farrowmaze-frontend\u002Fblob\u002Fmain\u002F.agents\u002Fskills\u002Fnestjs-patterns\u002FSKILL.md",true,[],[47,54,61,68,75,80],{"skillNo":48,"name":49,"nameZh":6,"description":50,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":51,"categories":52,"keywords":53,"publishedAt":19},"01M74X9ZAFBWMXQJRPHW7D5D8V","zoom-out","Tell the agent to zoom out and give broader context or a higher-level perspective. Use when you're unfamiliar with a section of code or need to understand how it fits into the bigger picture.","https:\u002F\u002Fgithub.com\u002FDS-PROYECTO-ARROW-MAZE\u002Farrowmaze-frontend\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fzoom-out\u002FSKILL.md",[],[],{"skillNo":55,"name":56,"nameZh":6,"description":57,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":58,"categories":59,"keywords":60,"publishedAt":19},"01M74X9XSNYXAYY6WHX0GZWXM8","write-a-skill","Create new agent skills with proper structure, progressive disclosure, and bundled resources. Use when user wants to create, write, or build a new skill.","https:\u002F\u002Fgithub.com\u002FDS-PROYECTO-ARROW-MAZE\u002Farrowmaze-frontend\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fwrite-a-skill\u002FSKILL.md",[],[],{"skillNo":62,"name":63,"nameZh":6,"description":64,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":65,"categories":66,"keywords":67,"publishedAt":19},"01M74X9WHQZNCASPRM3FWJKD1J","teach","Teach the user a new skill or concept, within this workspace.","https:\u002F\u002Fgithub.com\u002FDS-PROYECTO-ARROW-MAZE\u002Farrowmaze-frontend\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fteach\u002FSKILL.md",[],[],{"skillNo":69,"name":70,"nameZh":6,"description":71,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":72,"categories":73,"keywords":74,"publishedAt":19},"01M74X9T1XWW6GQ9XSRGS3PK11","tdd-strict","Enforce strict Test-Driven Development (TDD) cycle. Use whenever writing new features, fixing bugs, or implementing use cases.","https:\u002F\u002Fgithub.com\u002FDS-PROYECTO-ARROW-MAZE\u002Farrowmaze-frontend\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Ftdd-strict\u002FSKILL.md",[],[],{"skillNo":76,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":77,"categories":78,"keywords":79,"publishedAt":19},"01M74X9QHRX6V1DMM1YSNTRE3S","https:\u002F\u002Fgithub.com\u002FDS-PROYECTO-ARROW-MAZE\u002Farrowmaze-frontend\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fnestjs-patterns\u002FSKILL.md",[],[],{"skillNo":81,"name":82,"nameZh":6,"description":83,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":84,"categories":85,"keywords":86,"publishedAt":19},"01M74X9NZJXQ59GAP70V87S6W5","handoff","Compact the current conversation into a handoff document for another agent to pick up.","https:\u002F\u002Fgithub.com\u002FDS-PROYECTO-ARROW-MAZE\u002Farrowmaze-frontend\u002Fblob\u002Fmain\u002F.claude\u002Fskills\u002Fhandoff\u002FSKILL.md",[],[]]