关于 phase-8-review
phase-8-review 是部署前的代码库审查阶段,面向需要检查架构、规范和代码质量的项目团队。它提供跨阶段一致性、分层架构、重复代码及设计与实现差异的审查清单,并指导重构。
主要功能
- 01检查架构与规范一致性
- 02核对跨阶段交付内容
- 03审查分层与依赖方向
- 04检查重复代码和复杂度
- 05分析设计与实现差异
- 06规划问题修复与重构
适用场景
- 01部署前检查代码库质量
- 02核对代码是否符合项目约定
- 03发现重复逻辑与潜在问题
- 04比较设计文档和实际实现
安装
复制下面的命令,在终端中运行。
$
npx skills add https:/ / github.com/ ww-w-ai/ bkit-claude-code --skill phase-8-review安装后在 Claude Code 中输入/phase-8-review确认已加载。
详细介绍
阶段 8:架构/规范审查
整体代码库质量验证
目的
部署前审查整个代码库。识别架构一致性、规范遵循情况和潜在问题。
本阶段要做的事
- 架构审查:审查结构一致性
- 规范审查:验证是否遵循规则
- 代码质量审查:检查重复、复杂度和潜在缺陷
- 重构:修复发现的问题
交付成果
docs/03-analysis/
├── architecture-review.md # Architecture review
├── convention-review.md # Convention review
└── refactoring-plan.md # Refactoring plan
PDCA 应用
- 计划:定义审查范围/标准
- 设计:设计检查清单
- 执行:开展代码审查
- 检查:分析问题
- 处理:重构并进入阶段 9
分级应用
| 级别 | 应用方式 |
|---|---|
| 入门级 | 可以跳过(简单项目) |
| 动态级 | 必须执行 |
| 企业级 | 必须执行 + 安全审查 |
完整阶段验证矩阵
跨阶段一致性验证
阶段 8 用于验证是否一致地应用了所有阶段的输出和规则。
┌─────────────────────────────────────────────────────────────────┐
│ Cross-Phase Dependency Flow │
├─────────────────────────────────────────────────────────────────┤
│ │
│ Phase 1 (Schema/Terminology) │
│ ↓ Glossary, entity definitions │
│ Phase 2 (Coding Convention) │
│ ↓ Naming rules, environment variable conventions │
│ Phase 3 (Mockup) │
│ ↓ Component structure, Props design │
│ Phase 4 (API) │
│ ↓ RESTful principles, response format, error codes │
│ Phase 5 (Design System) │
│ ↓ Design tokens, component variants │
│ Phase 6 (UI Implementation) │
│ ↓ API client, type sharing, error handling │
│ Phase 7 (SEO/Security) │
│ ↓ Security rules, metadata │
│ Phase 8 (Review) ← Current stage: Full verification │
│ ↓ │
│ Phase 9 (Deployment) │
│ │
└─────────────────────────────────────────────────────────────────┘
各阶段专属验证清单
阶段 1 → 验证:术语/架构一致性
□ Are glossary.md terms consistently used in code?
- Business terms → Code naming matching
- Global standard terms → API response field names matching
□ Do entity definitions match actual types?
□ Do relationship definitions match actual implementation?
阶段 2 → 验证:规范遵循情况
□ Naming rule compliance (PascalCase, camelCase, UPPER_SNAKE_CASE)
□ Folder structure rule compliance
□ Environment variable naming rule compliance (NEXT_PUBLIC_*, DB_*, API_*, etc.)
□ .env.example template completion
□ Environment variable validation logic (lib/env.ts) exists
阶段 4 → 验证:API 一致性
□ RESTful principle compliance
- Resource-based URLs (nouns, plural)
- Correct HTTP method usage
- Status code consistency
□ Response format consistency
- Success: { data, meta? }
- Error: { error: { code, message, details? } }
- Pagination: { data, pagination }
□ Error code standardization (matches ERROR_CODES constant)
阶段 5 → 验证:设计系统一致性
□ Are design tokens defined? (CSS Variables / ThemeData)
□ Do components use tokens? (no hardcoded colors)
□ Are component variants consistent?
□ Dark mode support (if defined)
阶段 6 → 验证:UI-API 集成一致性
□ API client layer structure compliance
- Components → hooks → services → apiClient
- No direct fetch calls
□ Type consistency
- Phase 4 API spec types = Phase 6 client types
□ Error handling consistency
- Global error handler usage
- Error code-specific handling logic
□ State management pattern consistency
阶段 7 → 验证:安全/SEO 应用情况
□ Authentication/authorization middleware applied
□ Input validation (server-side)
□ XSS, CSRF defense
□ No sensitive info exposed to client
□ SEO meta tags applied
阶段 9 → 验证:部署就绪情况
□ Environment variable Secrets registered (based on Phase 2 list)
□ Environment separation (dev/staging/prod)
□ Build successful
□ Environment variable validation script passes
整洁架构验证
分层原则
┌─────────────────────────────────────────────────────────────┐
│ Presentation Layer │
│ (pages, components, hooks - UI concerns) │
├─────────────────────────────────────────────────────────────┤
│ Application Layer │
│ (services, use-cases - business logic) │
├─────────────────────────────────────────────────────────────┤
│ Domain Layer │
│ (entities, types - core domain models) │
├─────────────────────────────────────────────────────────────┤
│ Infrastructure Layer │
│ (api client, db, external services) │
└─────────────────────────────────────────────────────────────┘
Dependency direction: Outside → Inside (Presentation → Domain)
Inner layers must not know about outer layers
各层专属验证清单
表现层(UI)
□ Is there business logic in components?
□ Are there direct API calls? (should go through hooks)
□ Is state management properly separated?
□ Do components have single responsibility?
应用层(服务)
□ Are domain logic and infrastructure logic separated?
□ Are external dependencies abstracted?
□ Is the structure testable?
□ Are use cases clearly defined?
领域层(类型/实体)
□ Are there no external library dependencies?
□ Does it contain only pure business rules?
□ Do types match Phase 1 schema?
基础设施层(API 客户端)
□ Are external service calls abstracted?
□ Is error handling consistent?
□ Is configuration managed via environment variables?
架构审查清单
结构
- 文件夹结构是否符合规范
- 关注点分离是否得当
- 依赖方向是否正确(外部 → 内部)
模式
- 是否使用一致的模式
- 是否存在不必要的抽象
- 封装是否得当
规范审查清单
命名
- 是否遵循阶段 2 定义的规则
- 是否使用有意义的名称
- 是否保持一致
代码风格
- 缩进、引号等是否统一
- 文件长度是否合适
- 函数长度是否合适
代码质量清单
- 是否存在重复代码
- 是否存在高度复杂的函数
- 错误处理是否得当
- 是否确保类型安全
AI 辅助审查
Request code review from Claude:
"Review this project's code.
- Does it follow CONVENTIONS.md rules
- Is there architecture consistency
- Are there potential bugs or improvements"
模板
参见 templates/pipeline/phase-8-review.template.md
下一阶段
阶段 9:部署 → 审查完成后,部署到生产环境
6. 深入代码质量审查
6.1 重复代码检测
检测方法
# 1. Search for similar function names
grep -r "function.*format" src/
grep -r "function.*calculate" src/
grep -r "function.*get.*By" src/
# 2. Search for similar patterns
grep -rn "reduce.*sum" src/
grep -rn "filter.*map" src/
grep -rn "useState.*useEffect" src/
按重复类型处理
| 类型 | 示例 | 解决方案 |
|---|---|---|
| 完全重复 | 相同代码复制粘贴 | 提取为函数 |
| 结构相似 | 逻辑相同,数据不同 | 参数化 |
| 概念相似 | 用途相似但实现不同 | 整合或使用接口 |
重复代码清单
□ Is the same logic in 2+ places?
□ Are there multiple functions with similar names?
□ Is the same data transformation repeated?
□ Are similar UI patterns repeated?
□ Is the same API call pattern repeated?
□ Is similar error handling repeated?
6.2 可复用性评估
评估标准
| 分数 | 标准 | 描述 |
|---|---|---|
| ⭐⭐⭐ | 高 | 可用于其他项目 |
| ⭐⭐ | 中 | 可在同一项目的多个位置使用 |
| ⭐ | 低 | 仅用于特定功能 |
可复用性清单
Check for each function/component:
□ Is it tied to a specific domain?
□ Does it depend on external state?
□ Are parameters generic?
□ Is the return value predictable?
□ Are there side effects?
6.3 可扩展性评估
可扩展性检查
When new requirements come:
□ Can it be added without modifying existing code?
□ Can behavior be changed by configuration only?
□ Is adding new types/cases easy?
□ Can it be extended without adding conditionals?
可扩展性反模式
// ❌ Requires modification for each extension
function process(type: string) {
if (type === 'a') { /* ... */ }
else if (type === 'b') { /* ... */ }
// Add else if for each new type...
}
// ❌ Hardcoded list
const ALLOWED_TYPES = ['a', 'b', 'c']
// ❌ Enumerated switch statements
switch (action.type) {
case 'ADD': // ...
case 'REMOVE': // ...
// Add case for each new action...
}
良好的可扩展性模式
// ✅ Registry pattern
const handlers: Record<string, Handler> = {}
function register(type: string, handler: Handler) {
handlers[type] = handler
}
function process(type: string, data: unknown) {
return handlers[type]?.(data)
}
// ✅ Configuration-based
const CONFIG = {
types: ['a', 'b', 'c'],
handlers: { ... }
}
// ✅ Plugin structure
interface Plugin { execute(data): Result }
const plugins: Plugin[] = []
6.4 面向对象原则检查
SOLID 原则检查清单
S - 单一职责(SRP)
□ Does the class/function change for only one reason?
□ Does the name clearly explain the role?
□ Is "and" in the name? → Needs separation
O - 开闭原则(OCP)
□ Is it open for extension? (new features can be added)
□ Is it closed for modification? (no existing code changes needed)
□ Are interfaces/abstractions used?
L - 里氏替换原则(LSP)
□ Can subtypes replace parent types?
□ Do overridden methods keep the contract?
I - 接口隔离原则(ISP)
□ Is the interface too large?
□ Must unused methods be implemented?
□ Can the interface be split smaller?
D - 依赖倒置原则(DIP)
□ Does it depend on abstractions instead of concrete classes?
□ Are dependencies injected? (DI)
□ Is the structure testable?
6.5 重构优先级
Urgent (Required before deployment):
1. Duplication that can cause bugs
2. Security vulnerabilities
3. Performance bottlenecks
High (As soon as possible):
4. Same logic duplicated in 3+ places
5. Files over 200 lines
6. Nesting deeper than 5 levels
Medium (Next sprint):
7. Structure lacking extensibility
8. Naming inconsistencies
9. Structure difficult to test
Low (Backlog):
10. Style inconsistencies
11. Excessive comments
12. Unused code
7. AI 代码审查请求模板
Please review the code from these perspectives:
1. Duplicate Code
- Are there similar functions/components?
- Is there common logic that can be extracted?
2. Reusability
- Can it be used generically?
- Is it tied to a specific domain?
3. Extensibility
- Can it flexibly respond to new requirements?
- Are there hardcoded parts?
4. SOLID Principles
- Does it follow single responsibility?
- Is it open for extension and closed for modification?
5. Convention Compliance
- Does it follow CONVENTIONS.md rules?
- Is naming consistent?
Please identify parts that need refactoring and their priority.
8. 差距分析(设计与实现)
差距分析报告模板
# Gap Analysis Report
## Analysis Target
- Design document: docs/02-design/{feature}.design.md
- Implementation path: src/features/{feature}/
## Results by Category
### API Endpoints
| Design | Implementation | Status |
|--------|----------------|--------|
| POST /api/users | POST /api/users | ✅ Match |
| GET /api/users/:id | - | ❌ Not implemented |
| - | DELETE /api/users/:id | ⚠️ Missing from design |
### Data Model
| Design Entity | Implementation | Status |
|---------------|----------------|--------|
| User | types/user.ts | ✅ Match |
| UserRole | - | ❌ Not implemented |
### Match Rate
- Total items: 10
- Matches: 7
- Not implemented: 2
- Missing from design: 1
- **Match Rate: 70%**
差距类型与处理措施
| 差距类型 | 含义 | 处理措施 |
|---|---|---|
| ✅ 匹配 | 设计 = 实现 | 无 |
| ❌ 未实现 | 在设计中,但代码中没有 | 实现或更新设计 |
| ⚠️ 设计中缺失 | 在代码中,但设计中没有 | 添加到设计文档 |
| 🔄 不同 | 已存在,但有所不同 | 对齐(以代码为准) |
何时运行差距分析
- 完成功能实现后
- 部署前
- 更新设计文档时
- 代码审查期间
评论
支持 Markdown