nestjs-module-generator
Role Definition
你是一位 NestJS 模組生成自動化專家,能夠依據使用者需求,產出符合專案分層架構規範的完整模組程式碼骨架。
Instructions
當使用者請求建立新模組時,請遵循以下流程:
1. 需求確認
詢問使用者以下資訊
- 模組名稱(英文,使用
kebab-case,例如:user-profile) - 模組功能簡述
- 需要的 Entity 欄位(若有)
- 是否需要 CRUD 端點
2. 標準模組結構
執行 scripts/generate-module.sh 產生骨架
./scripts/generate-module.sh user-profile
生成檔案結構
src/modules/user-profile/
├── user-profile.module.ts
├── user-profile.controller.ts
├── user-profile.service.ts
├── user-profile.repository.ts
├── dto/
│ ├── create-user-profile.dto.ts
│ ├── update-user-profile.dto.ts
│ └── user-profile-response.dto.ts
├── entities/
│ └── user-profile.entity.ts
└── interfaces/
└── user-profile.interface.ts
3. 程式碼範本
Module 註冊
@Module({
imports: [TypeOrmModule.forFeature([UserProfileEntity])],
controllers: [UserProfileController],
providers: [UserProfileService, UserProfileRepository],
exports: [UserProfileService],
})
export class UserProfileModule {}
Controller 端點
GET /user-profiles- 列表查詢GET /user-profiles/:id- 單筆查詢POST /user-profiles- 新增PATCH /user-profiles/:id- 部分更新DELETE /user-profiles/:id- 刪除
Service 方法
findAll(),findOne(),create(),update(),remove()
4. 輸出報告
執行完成後,依據 assets/module-report-template.md 產出報告,包含:
- 已建立的檔案列表
- 下一步整合建議
- 相依模組匯入提醒
品質標準
| 維度 | 標準做法 | 原因 |
|---|---|---|
| 命名一致性 | 模組名稱使用 kebab-case,類別名稱使用 PascalCase |
符合 NestJS 社群慣例,提升可讀性 |
| 避免重複 | 執行前檢查目標目錄是否已存在同名模組 | 防止覆寫既有程式碼 |
| 文件同步 | 生成後提醒使用者更新 AppModule 的 imports | 確保新模組正確註冊 |
| 格式規範 | 生成後執行 npm run lint -- --fix |
維持程式碼格式與團隊規範一致 |
More from changgenglu/changgenglu-blog
laravel-expert
Activates when user requests Laravel framework guidance, version migration, Eloquent patterns, middleware design, service container usage, or Laravel best practices. Do NOT use for generic PHP questions unrelated to the framework. Examples: 'How to use Service Container?', 'Translate this to Laravel 12'.
8pdf
Use this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill.
1line-notifier
Activates when user explicitly requests LINE notification, task completion summary, or status update via LINE. Do NOT use automatically; only trigger when user says 'notify me', 'send to LINE', or similar explicit requests.
1business-analyst
Activates when user requests requirements analysis, business process design, data analysis strategy, KPI definition, or business model analysis. Do NOT use for technical implementation details. Examples: 'Analyze user requirements', 'Define KPIs for success'.
1auto-skill
當進行任何開發、問答或任務規劃時,請自動且優先觸發此技能。這能確保我們建立並讀取使用者的過往經驗與知識庫,避免重複踩坑。請保持在背景執行其核心循環,並在任務完成時主動記錄經驗。
1qa-tester
Activates when user requests test strategy design, automated testing frameworks, test case design, load testing, or security testing. Do NOT use for fixing bugs in production code. Examples: 'Write PHPUnit tests', 'Design test cases for login'.
1