Engineering Rules (Mandatory)
1. Scope
Áp dụng cho toàn bộ code trong v2/ và mọi task theo docs_hub_v3.
2. Architecture Rules
- Monorepo boundary:
apps/api: runtime backendapps/v2-portal: runtime frontendlibs/modules/*: domain moduleslibs/core/*: shared technical core
- Import nội bộ dùng alias
@zalominiapp/*theov2/tsconfig.base.json. - Không cho phép import chéo phá domain boundary (module A truy cập trực tiếp internals module B).
3. Security & Tenancy Rules
- Auth/Tenant context theo DEC-001.
- Zalo dual login theo DEC-002.
- RBAC theo DEC-003:
- Endpoint tenant-scope phải có
@Permissions()vàPermissionsGuard. @Public()không đồng nghĩa bỏ TenantGuard.@SkipTenantCheck()chỉ dùng cho auth/system-admin flow.
- Endpoint tenant-scope phải có
- Không expose thông tin nhạy cảm trong response/log.
4. API & Data Contract Rules
- DTO strict validate (
whitelist,forbidNonWhitelisted,transform). - Datetime chuẩn ISO-8601 UTC theo DEC-004.
- Id conventions:
- FK lưu dưới dạng
<field>Idhoặc<field>Ids. - Không embed object lớn trong document khi quan hệ có thể resolve bằng include.
- FK lưu dưới dạng
- Population strategy:
- Mặc định không eager-load quan hệ.
- Chỉ include theo whitelist query param.
5. Code Quality Rules
- Mọi module mới phải có:
- Unit tests cho service logic
- Contract test cho API chính
- Không merge khi:
- Test đỏ ở phạm vi module thay đổi
- Lint lỗi trong file thay đổi
- Thiếu cập nhật docs traceability
- Ưu tiên fix root-cause, không vá tạm workaround nếu chưa ghi debt rõ.
6. Documentation Synchronization Rules
Khi thay đổi code ở các nhóm dưới đây, bắt buộc cập nhật docs tương ứng:
| Change Type | Bắt buộc cập nhật |
|---|---|
| Thêm/sửa endpoint | 02_SPECS/core/backend_api.md, 03_TRACEABILITY/API_TRACEABILITY.md, 05_GENERATED/backend_api_manifest.md |
| Thêm/sửa schema/entity | 02_SPECS/core/backend_api.md, 05_GENERATED/backend_entity_manifest.md |
| Thêm/sửa route UI | 02_SPECS/core/portal.md, 05_GENERATED/ui_route_catalog.md, 03_TRACEABILITY/FEATURE_STATUS_MATRIX.md |
| Thêm/sửa quyền | 00_GOVERNANCE/01_DECISION_LOG.md (nếu rule mới), 05_GENERATED/permission_manifest.md |
| Đổi logic kiến trúc | 00_GOVERNANCE/01_DECISION_LOG.md + files spec liên quan |
Manifest generation command (local/CI):
cd v2 && npm run ci:manifest-guard
GitLab enforcement:
- CI job
manifest_guardtrong.gitlab-ci.ymlphải pass trước merge MR. - Branch protection settings theo
04_OPERATIONS/13_BRANCH_PROTECTION_POLICY.md.
7. Branch/PR Hygiene (Recommended)
- 1 PR = 1 feature key hoặc 1 bug key.
- PR description phải có:
- Feature key
- Files changed
- Test evidence
- Docs updated
- Không gộp nhiều module unrelated vào cùng PR.