AgentSkillsCN

nestjs-mongodb-api

提供NestJS与MongoDB API的脚手架搭建与架构指导。该功能将在以下场景中自动触发: - 当您新建NestJS模块、服务、控制器或功能时; - 当您处理Mongoose模式、模型或MongoDB查询时; - 当您在NestJS中实施仓储模式时; - 当您为NestJS项目设计清晰的架构分层时; - 当您配置NestJS项目中的全局守卫、拦截器或管道时; - 当您审查NestJS代码的架构与结构时。

SKILL.md
--- frontmatter
name: nestjs-mongodb-api
description: |
  NestJS + MongoDB API scaffolding and architectural guidance. Automatically invoked when:
  - Generating a new NestJS module, service, controller, or feature
  - Working with Mongoose schemas, models, or MongoDB queries
  - Implementing repository pattern in NestJS
  - Designing clean architecture layers for a NestJS project
  - Setting up NestJS project configuration, guards, interceptors, or pipes
  - Reviewing NestJS code architecture and structure
allowed-tools: Read, Write, Edit, Bash, Glob, Grep

NestJS + MongoDB API Skill

This skill provides scaffolding templates, architectural patterns, and best practices for building production-grade NestJS REST APIs with MongoDB and Mongoose.

Quick Scaffolding Commands

When asked to generate a new module or feature, follow these steps:

  1. Read references/architecture.md for the clean architecture layer structure
  2. Read references/naming-conventions.md for file and class naming rules
  3. Use scripts/scaffold-module.sh to generate the folder skeleton
  4. Fill in each file using the templates in references/templates.md

Tech Stack

  • Framework: NestJS 10+
  • Database: MongoDB 7+
  • ODM: Mongoose 8+ via @nestjs/mongoose
  • Validation: class-validator + class-transformer
  • API Docs: Swagger via @nestjs/swagger
  • Config: @nestjs/config with Joi validation

Key References

  • references/architecture.md — Clean architecture layer breakdown
  • references/naming-conventions.md — File, class, and variable naming rules
  • references/templates.md — Code templates for all layer files

Standard File Creation Checklist

For every new feature <Feature>, create:

code
src/
├── domain/
│   ├── entities/<feature>.entity.ts
│   ├── repositories/i-<feature>.repository.ts
│   └── exceptions/<feature>.exceptions.ts
├── application/
│   ├── use-cases/create-<feature>.use-case.ts
│   ├── use-cases/find-<feature>.use-case.ts
│   ├── use-cases/update-<feature>.use-case.ts
│   ├── use-cases/delete-<feature>.use-case.ts
│   └── dtos/<feature>.dto.ts
├── infrastructure/
│   └── database/
│       ├── schemas/<feature>.schema.ts
│       ├── repositories/mongoose-<feature>.repository.ts
│       └── mappers/<feature>.mapper.ts
├── presentation/
│   └── controllers/<feature>.controller.ts
└── <feature>.module.ts