- 重构LanguageUtils为LanguageService,实现ILanguageService接口 - 移除自定义验证管道和装饰器,使用标准NestJS验证 - 集成框架ValidatorService进行业务验证 - 简化目录结构,移除不必要的子目录 - 支持模块化语言包加载(common、user、order等) - 统一API响应格式(code、msg、data、timestamp) - 添加ValidationExceptionFilter处理多语言验证错误 - 完善多语言示例和文档
4.2 KiB
4.2 KiB
WWJCloud Migration Tooling Rules
Purpose: Standardize PHP→NestJS migration for AI-friendly, repeatable generation. Tools only; do not hand-edit generated outputs.
— Scope & Principles —
- NestJS compliance: Follow official module/controller/service/entity/DTO patterns; DI-first; guards/pipes/interceptors.
- Core-only: Generators write strictly under
src/core/{module}/.... Do NOT create/modifysrc/common,src/vendor, orsrc/config. - Business-first: Migrate PHP business logic (services/controllers/models/validators). Replace PHP infra calls with
src/common/*capabilities. - Java-structure reference: Organize per module with
controllers/,services/,entity/,dto/; controllers orchestrate, services hold business, entities map DB only.
— Contracts & Compatibility —
- Database alignment: Table/column/index/types must match PHP 100%. No new/renamed/removed fields.
- Method alignment: Service method names map 1:1 with PHP. Do not invent names.
- Routing: Keep
/adminapiand/apiprefixes and controller segmentation consistent with PHP. - Validation: Map PHP validators to DTO + class-validator/pipes. Behaviorally equivalent.
— Naming & Paths —
- Files: kebab-case filenames
- Controllers:
*.controller.ts - Services:
*.service.ts - Entities:
*.entity.ts
- Controllers:
- Classes: PascalCase.
- Aliases (tsconfig):
@wwjCommon/*,@wwjCore/*,@wwjVendor/*,@/*.
— Infrastructure Mapping —
- Replace PHP infra with Common layer:
- Guards:
@wwjCommon/guards/*(e.g.,jwt-auth.guard,roles.guard,optional-auth.guard) - Decorators:
@wwjCommon/decorators/*(e.g.,roles.decorator,public.decorator) - Exceptions:
@wwjCommon/exceptions/business.exception - Pipes:
@wwjCommon/validation/pipes/*(e.g.,parse-diy-form.pipe,json-transform.pipe) - Cache/Queue/DB utilities under
@wwjCommon/* - Do not reference
@wwjCore/*for infra.
- Guards:
— Module Generation —
- Generate
src/core/{module}/{module}.module.tsregistering discovered controllers/services. - Entities: detect
*.entity.ts; optionally includeTypeOrmModule.forFeature([...])(feature flag). - Filter non-business directories by default (whitelist/blacklist). Avoid generating modules for technical directories like
job/,queue/,workerman/,lang/, etc.
— Generation Stages (feature flags) —
- Commands: disabled by default (we do not use
nest-commander). - Jobs/Listeners: configurable; ensure no duplicate suffixes (avoid
JobJob/ListenerListener). - Routes: no separate route files (NestJS uses decorators).
— Idempotency & Safety —
- Re-runnable: Same inputs → same outputs. Overwrite files in place; create missing directories; never delete parent folders.
- Dry-run mode: Output plan without writing files; provide diff-like summary.
- Logging: Summarize counts for modules/controllers/services/entities/validators, skipped items, and errors.
— Security & Multitenancy —
- Guards: apply standard guards in controllers; enforce role checks and optional auth where applicable.
- Tenant isolation: preserve
site_idsemantics; avoid exposing sensitive fields in responses.
— Quality Gates —
- After generation (tool-side), optionally run TypeScript compile and ESLint checks. Fail fast and report.
- Remove duplicate imports; standardize import order; ensure resolved alias paths.
— Temporary Artifacts —
- All temporary scripts/docs/reports stay in
tools/. Clean up when done. Never write temp files outsidetools/.
— Enforcement —
- “Only fix tools, not generated files.” If outputs are wrong, update tools and re-run.
— Versioning & Extensibility —
- Keep infra replacement map versioned and extensible to support future modules and AI evolution.
— Quick Checklist —
- Files are kebab-case; classes are PascalCase
- Controllers only orchestrate/validate; services hold business logic
- Entities map DB 1:1 with PHP schema
- All infra imports use
@wwjCommon/* /adminapiand/apicontrollers generated correctly- Modules register found controllers/services; optional TypeORM feature import
- Commands disabled; jobs/listeners gated; no duplicate suffixes
- Safe write, idempotent, dry-run available; logs emitted