devdocs-system-design

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

系统设计

System Design

基于需求文档创建或更新系统设计文档,支持初始设计和增量设计两种模式。
Create or update system design documents based on requirement documents, supporting both initial design and incremental design modes.

语言规则

Language Rules

  • 支持中英文提问
  • 统一中文回复
  • 使用中文生成文档
  • Supports questions in both Chinese and English
  • Provide unified English responses
  • Generate documents in English

触发条件

Trigger Conditions

初始设计模式

Initial Design Mode

  • 用户已完成需求文档,项目无系统设计
  • 用户要求系统/技术设计
  • 用户需要架构或 API 设计
  • User has completed requirement documents, and there is no system design for the project
  • User requests system/technical design
  • User needs architecture or API design

增量设计模式

Incremental Design Mode

  • 新功能加入后需要设计变更(来自
    /devdocs-feature
  • 优化建议确认后需要设计调整(来自
    /devdocs-insights
  • 技术改进需要架构调整
  • 用户要求更新/修改现有设计
  • Design changes are required after new features are added (from
    /devdocs-feature
    )
  • Design adjustments are required after optimization suggestions are confirmed (from
    /devdocs-insights
    )
  • Architecture adjustments are required for technical improvements
  • User requests to update/modify existing design

前置条件

Preconditions

  • 需求文档:
    docs/devdocs/01-requirements.md
  • 如不存在,建议先运行
    /devdocs-requirements
  • Requirement document:
    docs/devdocs/01-requirements.md
  • If it does not exist, it is recommended to run
    /devdocs-requirements
    first

设计模式检测

Design Mode Detection

启动时自动检测
检查 02-system-design.md 是否存在
      ├── 不存在 → 初始设计模式
      └── 存在 → 增量设计模式
      检查是否有新增需求(F-XXX)未覆盖
            ├── 有 → 提示增量设计
            └── 无 → 询问用户意图
Automatic detection on startup
Check if 02-system-design.md exists
      ├── Does not exist → Initial Design Mode
      └── Exists → Incremental Design Mode
      Check if there are unimplemented new requirements (F-XXX)
            ├── Yes → Prompt for incremental design
            └── No → Ask user's intention

工作流程

Workflow

初始设计流程

Initial Design Workflow

1. 读取需求 → 加载 01-requirements.md
2. 询问偏好 → 技术栈、平台、集成需求
3. 探索代码 → 了解现有架构
4. 创建设计 → 生成系统设计文档
5. 验证覆盖 → 检查所有 F-XXX 都有对应模块/接口
6. 用户确认 → 获得批准后定稿
1. Read Requirements → Load 01-requirements.md
2. Ask Preferences → Tech stack, platform, integration requirements
3. Explore Code → Understand existing architecture
4. Create Design → Generate system design document
5. Verify Coverage → Check that all F-XXX have corresponding modules/interfaces
6. User Confirmation → Finalize after approval

增量设计流程

Incremental Design Workflow

1. 读取现有设计 → 加载 02-system-design*.md
2. 识别变更来源
      ├── 新功能需求(F-XXX)
      ├── 优化建议(INS-XXX)
      └── 技术改进
3. 影响分析
      ├── 识别受影响的模块
      ├── 识别受影响的接口
      └── 识别受影响的数据模型
4. 兼容性评估
      ├── 接口变更是否向后兼容?
      ├── 数据模型变更是否需要迁移?
      └── 是否有破坏性变更?
5. 设计变更
      ├── 新增模块/接口/数据模型
      ├── 修改现有设计
      └── 标注变更版本
6. 生成变更记录 → 追加到设计文档
7. 用户确认 → 获得批准后更新文档
1. Read Existing Design → Load 02-system-design*.md
2. Identify Change Sources
      ├── New feature requirements (F-XXX)
      ├── Optimization suggestions (INS-XXX)
      └── Technical improvements
3. Impact Analysis
      ├── Identify affected modules
      ├── Identify affected interfaces
      └── Identify affected data models
4. Compatibility Assessment
      ├── Are interface changes backward compatible?
      ├── Do data model changes require migration?
      └── Are there breaking changes?
5. Design Changes
      ├── Add new modules/interfaces/data models
      ├── Modify existing design
      └── Mark change version
6. Generate Change Record → Append to design document
7. User Confirmation → Update document after approval

设计前必问

Mandatory Questions Before Design

必须使用 AskUserQuestion 询问用户
  1. 技术栈偏好
    • 是否有偏好的技术栈?
    • 选项:指定技术栈 / 无偏好(将根据需求推荐)
  2. 目标平台
    • 目标平台是什么?
    • 选项:Web / Mobile (iOS/Android) / Desktop / Server / 跨平台
  3. 部署环境
    • 部署在哪里?
    • 选项:云服务 (AWS/GCP/Azure) / 私有化 / 混合
  4. 现有系统集成
    • 是否需要与现有系统集成?
    • 选项:否 / 是(指定系统、API、数据库)
如用户无偏好,则根据需求设计最优方案。
Must use AskUserQuestion to ask the user:
  1. Tech Stack Preference
    • Do you have a preferred tech stack?
    • Options: Specify tech stack / No preference (will recommend based on requirements)
  2. Target Platform
    • What is the target platform?
    • Options: Web / Mobile (iOS/Android) / Desktop / Server / Cross-platform
  3. Deployment Environment
    • Where will it be deployed?
    • Options: Cloud service (AWS/GCP/Azure) / On-premises / Hybrid
  4. Existing System Integration
    • Is integration with existing systems required?
    • Options: No / Yes (specify system, API, database)
If the user has no preference, design the optimal solution based on requirements.

增量设计

Incremental Design

影响分析

Impact Analysis

增量设计前必须进行影响分析:
markdown
undefined
Impact analysis must be performed before incremental design:
markdown
undefined

影响分析:<变更名称>

Impact Analysis: <Change Name>

变更来源:F-XXX / INS-XXX / 技术改进 变更日期:YYYY-MM-DD
Change Source: F-XXX / INS-XXX / Technical Improvement Change Date: YYYY-MM-DD

受影响的模块

Affected Modules

模块影响类型说明
UserService修改新增方法
resetPassword()
AuthModule新增新增密码重置模块
EmailService无变化复用现有邮件服务
ModuleImpact TypeDescription
UserServiceModifyAdd new method
resetPassword()
AuthModuleAddAdd password reset module
EmailServiceNo ChangeReuse existing email service

受影响的接口

Affected Interfaces

接口变更类型向后兼容说明
POST /api/auth/reset-password新增新接口
GET /api/user/:id修改返回值新增字段
POST /api/auth/login修改参数结构变更
InterfaceChange TypeBackward CompatibleDescription
POST /api/auth/reset-passwordAddNew interface
GET /api/user/:idModifyAdd new field to return value
POST /api/auth/loginModifyParameter structure changed

受影响的数据模型

Affected Data Models

实体变更类型需要迁移说明
User修改新增
resetToken
字段
PasswordResetLog新增新表
undefined
EntityChange TypeNeeds MigrationDescription
UserModifyAdd
resetToken
field
PasswordResetLogAddNew table
undefined

兼容性评估

Compatibility Assessment

变更类型向后兼容判断处理方式
新增接口✅ 兼容直接添加
新增字段(可选)✅ 兼容直接添加
新增字段(必填)❌ 不兼容需要迁移计划
修改字段类型❌ 不兼容需要迁移计划
删除字段/接口❌ 不兼容需要废弃周期
修改接口参数⚠️ 视情况评估影响范围
破坏性变更处理
  1. 标注废弃(Deprecated)
  2. 设置废弃周期(如 2 个版本)
  3. 提供迁移指南
  4. 在变更记录中说明
Change TypeBackward Compatibility JudgmentHandling Method
New interface✅ CompatibleAdd directly
Add optional field✅ CompatibleAdd directly
Add required field❌ IncompatibleNeed migration plan
Modify field type❌ IncompatibleNeed migration plan
Delete field/interface❌ IncompatibleNeed deprecation period
Modify interface parameters⚠️ DependsEvaluate impact scope
Breaking Change Handling:
  1. Mark as Deprecated
  2. Set deprecation period (e.g., 2 versions)
  3. Provide migration guide
  4. Explain in change records

设计变更记录

Design Change Records

增量设计完成后,在设计文档末尾追加变更记录:
markdown
---
After completing incremental design, append change records at the end of the design document:
markdown
---

设计变更记录

Design Change Records

v1.2.0 (2024-01-20)

v1.2.0 (2024-01-20)

变更来源:F-005 密码重置功能, INS-003 登录安全优化
新增模块
  • PasswordResetModule
    - 密码重置模块(关联 F-005)
修改模块
  • AuthModule
    - 新增密码重置入口
新增接口
  • IPasswordResetService.sendResetEmail()
    - 发送重置邮件
  • IPasswordResetService.resetPassword()
    - 执行密码重置
新增 API
  • POST /api/auth/forgot-password
    - 请求密码重置
  • POST /api/auth/reset-password
    - 执行密码重置
数据模型变更
  • User
    新增字段:
    resetToken
    ,
    resetTokenExpiry
  • 新增实体:
    PasswordResetLog
破坏性变更:无
迁移说明
  • 执行数据库迁移脚本
    migrations/001-add-reset-token.sql

Change Source: F-005 Password Reset Feature, INS-003 Login Security Optimization
Added Modules:
  • PasswordResetModule
    - Password reset module (associated with F-005)
Modified Modules:
  • AuthModule
    - Added password reset entry
Added Interfaces:
  • IPasswordResetService.sendResetEmail()
    - Send reset email
  • IPasswordResetService.resetPassword()
    - Execute password reset
Added APIs:
  • POST /api/auth/forgot-password
    - Request password reset
  • POST /api/auth/reset-password
    - Execute password reset
Data Model Changes:
  • User
    added fields:
    resetToken
    ,
    resetTokenExpiry
  • Added entity:
    PasswordResetLog
Breaking Changes: None
Migration Instructions:
  • Execute database migration script
    migrations/001-add-reset-token.sql

v1.1.0 (2024-01-10)

v1.1.0 (2024-01-10)

...
undefined
...
undefined

增量设计检查清单

Incremental Design Checklist

  • 已识别所有受影响的模块
  • 已识别所有受影响的接口
  • 已识别所有受影响的数据模型
  • 已评估向后兼容性
  • 破坏性变更已标注处理方式
  • 已生成变更记录
  • 新增内容已标注关联需求(F-XXX / INS-XXX)
  • Identified all affected modules
  • Identified all affected interfaces
  • Identified all affected data models
  • Assessed backward compatibility
  • Marked handling methods for breaking changes
  • Generated change records
  • Marked associated requirements (F-XXX / INS-XXX) for new content

输出文件

Output Files

主文件
docs/devdocs/02-system-design.md
Main File:
docs/devdocs/02-system-design.md

文档拆分规则

Document Splitting Rules

当满足以下条件时,应拆分文档:
  • 文档超过 300 行
  • 模块数量超过 5 个
  • API 接口超过 10 个
拆分方式
docs/devdocs/
├── 02-system-design.md          # 主文档:架构概览、技术选型、模块划分
├── 02-system-design-api.md      # API 设计:接口定义、请求响应示例
└── 02-system-design-data.md     # 数据模型:实体定义、ER 图、索引策略
拆分内容分配
文件包含章节
02-system-design.md1-7: 平台、架构、技术选型、模块、接口签名、模式、代码结构
02-system-design-api.md9-10: 完整 API 设计、状态流转
02-system-design-data.md8, 11-13: 数据模型、异常处理、扩展性、需求追溯
详细模板参见 templates/design-template.md
Split the document when any of the following conditions are met:
  • Document exceeds 300 lines
  • Number of modules exceeds 5
  • Number of API interfaces exceeds 10
Splitting Method:
docs/devdocs/
├── 02-system-design.md          # Main document: Architecture overview, tech selection, module division
├── 02-system-design-api.md      # API Design: Interface definitions, request/response examples
└── 02-system-design-data.md     # Data Model: Entity definitions, ER diagrams, indexing strategies
Splitting Content Allocation:
FileIncluded Chapters
02-system-design.md1-7: Platform, architecture, tech selection, modules, interface signatures, patterns, code structure
02-system-design-api.md9-10: Complete API design, state transitions
02-system-design-data.md8, 11-13: Data models, exception handling, extensibility, requirement traceability
Refer to templates/design-template.md for detailed templates.

设计原则

Design Principles

MTE 原则

MTE Principles

系统设计必须遵循 MTE 原则
原则说明检查点
Maintainability可维护性模块职责单一、依赖清晰、易于理解和修改
Testability可测试性核心逻辑可单元测试、依赖可 Mock、边界清晰(参考
/testing-guide
Extensibility可扩展性预留扩展点、接口抽象、开闭原则
System design must follow the MTE Principles:
PrincipleDescriptionCheckpoint
MaintainabilityMaintainabilitySingle responsibility for modules, clear dependencies, easy to understand and modify
TestabilityTestabilityCore logic can be unit tested, dependencies can be Mocked, clear boundaries (refer to
/testing-guide
)
ExtensibilityExtensibilityReserved extension points, interface abstraction, open/closed principle

设计模式选择

Design Pattern Selection

根据场景选择合适的设计模式,只在必要时使用
场景推荐模式适用情况
对象创建Factory / Builder复杂对象构建、多种类型创建
行为扩展Strategy / Template算法可替换、流程固定步骤可变
结构组织Facade / Adapter简化复杂接口、适配第三方库
状态管理State / Observer状态驱动行为、事件通知
数据访问Repository / DAO数据层抽象、查询封装
Select appropriate design patterns based on scenarios, only use when necessary:
ScenarioRecommended PatternApplicable Situation
Object CreationFactory / BuilderComplex object construction, multiple type creation
Behavior ExtensionStrategy / TemplateReplaceable algorithms, fixed process with variable steps
Structure OrganizationFacade / AdapterSimplify complex interfaces, adapt third-party libraries
State ManagementState / ObserverState-driven behavior, event notification
Data AccessRepository / DAOData layer abstraction, query encapsulation

设计层次

Design Layers

┌─────────────────────────────────────┐
│             接口层                   │  ← API/Controller(薄层,无业务逻辑)
├─────────────────────────────────────┤
│             服务层                   │  ← 业务逻辑(核心,可测试)
├─────────────────────────────────────┤
│             领域层                   │  ← 领域模型(实体、值对象)
├─────────────────────────────────────┤
│           基础设施层                 │  ← 数据访问、外部服务(可替换)
└─────────────────────────────────────┘
┌─────────────────────────────────────┐
│             Interface Layer         │  ← API/Controller (thin layer, no business logic)
├─────────────────────────────────────┤
│             Service Layer           │  ← Business logic (core, testable)
├─────────────────────────────────────┤
│             Domain Layer            │  ← Domain models (entities, value objects)
├─────────────────────────────────────┤
│           Infrastructure Layer      │  ← Data access, external services (replaceable)
└─────────────────────────────────────┘

文档结构

Document Structure

  1. 目标平台 - 平台、版本要求、部署环境
  2. 架构概览 - 高层架构图(Mermaid
  3. 技术选型 - 技术选择及理由
  4. 模块设计 - 模块职责与依赖,标注关联功能点 (F-XXX)
  5. 核心接口 - 面向接口 (仅签名): 关键接口和方法签名(严禁包含具体实现逻辑),标注关联 F-XXX
  6. 设计模式 - 应用的模式及理由
  7. 代码结构 - 目录结构设计
  8. 数据模型 - 实体定义与关系
  9. API 设计 - 接口端点及请求/响应示例,标注关联 F-XXX, AC-XXX
  10. 状态流转 - 关键业务流程的状态机
  11. 异常处理 - 错误码与处理策略
  12. 日志设计 - 日志级别、关键日志点、追溯 ID
  13. 扩展性 - 扩展点与未来考量
  14. 需求追溯 - 功能点与模块/接口的映射关系,覆盖检查清单
  1. Target Platform - Platform, version requirements, deployment environment
  2. Architecture Overview - High-level architecture diagram (Mermaid)
  3. Tech Selection - Tech choices and reasons
  4. Module Design - Module responsibilities and dependencies, mark associated feature points (F-XXX)
  5. Core Interfaces - Interface-oriented (only signatures): Key interfaces and method signatures (strictly no implementation logic), mark associated F-XXX
  6. Design Patterns - Applied patterns and reasons
  7. Code Structure - Directory structure design
  8. Data Model - Entity definitions and relationships
  9. API Design - Interface endpoints and request/response examples, mark associated F-XXX, AC-XXX
  10. State Transitions - State machines for key business processes
  11. Exception Handling - Error codes and handling strategies
  12. Log Design - Log levels, key log points, trace ID
  13. Extensibility - Extension points and future considerations
  14. Requirement Traceability - Mapping between feature points and modules/interfaces, coverage checklist

核心接口设计

Core Interface Design

设计文档中应体现核心接口定义(只定义签名,不写实现),并标注关联功能点:
markdown
undefined
Core interface definitions should be reflected in the design document (only define signatures, no implementation), and mark associated feature points:
markdown
undefined

核心接口

Core Interfaces

IUserService(关联:F-001 用户注册, F-002 用户登录)

IUserService (Associated: F-001 User Registration, F-002 User Login)

方法参数返回值关联说明
createUser
CreateUserDTO
User
F-001, AC-001创建用户
validateEmail
string
boolean
F-001, AC-002验证邮箱
login
LoginDTO
AuthToken
F-002, AC-006用户登录
MethodParameterReturn ValueAssociatedDescription
createUser
CreateUserDTO
User
F-001, AC-001Create user
validateEmail
string
boolean
F-001, AC-002Validate email
login
LoginDTO
AuthToken
F-002, AC-006User login

IUserRepository

IUserRepository

方法参数返回值说明
save
User
User
保存用户
findById
string
User | null
根据ID查询
findByEmail
string
User | null
根据邮箱查询
undefined
MethodParameterReturn ValueDescription
save
User
User
Save user
findById
string
User | null
Query by ID
findByEmail
string
User | null
Query by email
undefined

代码结构设计

Code Structure Design

markdown
undefined
markdown
undefined

目录结构

Directory Structure

src/ ├── api/ # 接口层 │ ├── controllers/ # 控制器(路由处理) │ ├── middlewares/ # 中间件(认证、日志等) │ └── validators/ # 请求验证 ├── services/ # 服务层 │ ├── interfaces/ # 服务接口定义 │ └── impl/ # 服务实现 ├── domain/ # 领域层 │ ├── entities/ # 实体 │ ├── value-objects/ # 值对象 │ └── events/ # 领域事件 ├── infrastructure/ # 基础设施层 │ ├── repositories/ # 数据仓储实现 │ ├── external/ # 外部服务适配 │ └── config/ # 配置 └── shared/ # 共享 ├── types/ # 类型定义 ├── utils/ # 工具函数 └── constants/ # 常量
undefined
src/ ├── api/ # Interface layer │ ├── controllers/ # Controllers (route handling) │ ├── middlewares/ # Middlewares (authentication, logging, etc.) │ └── validators/ # Request validation ├── services/ # Service layer │ ├── interfaces/ # Service interface definitions │ └── impl/ # Service implementations ├── domain/ # Domain layer │ ├── entities/ # Entities │ ├── value-objects/ # Value objects │ └── events/ # Domain events ├── infrastructure/ # Infrastructure layer │ ├── repositories/ # Data repository implementations │ ├── external/ # External service adapters │ └── config/ # Configuration └── shared/ # Shared ├── types/ # Type definitions ├── utils/ # Utility functions └── constants/ # Constants
undefined

日志设计

Log Design

日志是调试和问题排查的关键工具,特别是对于手动测试和 E2E 测试场景。
Logs are critical tools for debugging and troubleshooting, especially for manual testing and E2E testing scenarios.

日志级别

Log Levels

级别用途示例场景
ERROR需要立即处理的错误数据库连接失败、支付失败、关键服务不可用
WARN潜在问题但不影响核心功能重试成功、降级处理、资源接近阈值
INFO关键业务操作用户登录、订单创建、状态变更
DEBUG调试信息函数入参、中间状态、性能指标
LevelPurposeExample Scenario
ERRORErrors requiring immediate handlingDatabase connection failure, payment failure, critical service unavailability
WARNPotential issues that do not affect core functionsRetry success, degradation handling, resource approaching threshold
INFOKey business operationsUser login, order creation, state change
DEBUGDebug informationFunction input parameters, intermediate states, performance metrics

关键日志点

Key Log Points

设计文档中应列出关键操作的日志点:
markdown
| 操作 | 日志级别 | 日志内容 | 关联编号 |
|------|----------|----------|----------|
| 用户登录成功 | INFO | `[F-002] User login: userId={}, ip={}` | F-002, AC-006 |
| 用户登录失败 | WARN | `[F-002] Login failed: userId={}, reason={}` | F-002, AC-007 |
| 密码验证失败 | WARN | `[F-002] Password mismatch: userId={}` | AC-007 |
| 数据库异常 | ERROR | `[INFRA] DB error: {}, query={}` | - |
| 订单创建 | INFO | `[F-003] Order created: orderId={}, userId={}` | F-003 |
Key operation log points should be listed in the design document:
markdown
| Operation | Log Level | Log Content | Associated ID |
|------|----------|----------|----------|
| User login success | INFO | `[F-002] User login: userId={}, ip={}` | F-002, AC-006 |
| User login failure | WARN | `[F-002] Login failed: userId={}, reason={}` | F-002, AC-007 |
| Password verification failure | WARN | `[F-002] Password mismatch: userId={}` | AC-007 |
| Database exception | ERROR | `[INFRA] DB error: {}, query={}` | - |
| Order creation | INFO | `[F-003] Order created: orderId={}, userId={}` | F-003 |

日志格式

Log Format

[时间] [级别] [追溯ID] [模块] 消息 {结构化数据}
示例
2024-01-26 10:30:15 INFO [req-abc123] [UserService] User created {"userId": "u001", "email": "user@example.com"}
2024-01-26 10:30:16 ERROR [req-abc123] [EmailService] Failed to send verification email {"userId": "u001", "error": "SMTP timeout"}
[Timestamp] [Level] [Trace ID] [Module] Message {Structured Data}
Example:
2024-01-26 10:30:15 INFO [req-abc123] [UserService] User created {"userId": "u001", "email": "user@example.com"}
2024-01-26 10:30:16 ERROR [req-abc123] [EmailService] Failed to send verification email {"userId": "u001", "error": "SMTP timeout"}

追溯 ID (Correlation ID)

Trace ID (Correlation ID)

属性说明
生成时机每个请求入口生成唯一 ID
传递方式通过 Context/Header 贯穿整个调用链
命名约定
traceId
correlationId
格式UUID 或
req-{timestamp}-{random}
用途
  • E2E 测试失败时,通过
    traceId
    查询完整日志链
  • 分布式系统中跨服务追踪
  • 问题排查时关联所有相关日志
AttributeDescription
Generation TimingGenerate a unique ID at each request entry
Transmission MethodPass through the entire call chain via Context/Header
Naming Convention
traceId
or
correlationId
FormatUUID or
req-{timestamp}-{random}
Purposes:
  • Query the complete log chain via
    traceId
    when E2E tests fail
  • Cross-service tracing in distributed systems
  • Correlate all relevant logs during troubleshooting

E2E 测试日志策略

E2E Test Log Strategy

场景日志策略说明
测试通过仅保留 ERROR/WARN减少日志量
测试失败保留完整日志(含 DEBUG)便于排查
手动复现启用 DEBUG 级别最大化信息
失败分析流程
1. 获取失败测试的 traceId
2. 查询该 traceId 的完整日志链
3. 定位首个 ERROR/异常点
4. 分析上下文日志
ScenarioLog StrategyDescription
Test passedOnly retain ERROR/WARN logsReduce log volume
Test failedRetain complete logs (including DEBUG)Facilitate troubleshooting
Manual reproductionEnable DEBUG levelMaximize information
Failure Analysis Process:
1. Obtain the traceId of the failed test
2. Query the complete log chain for this traceId
3. Locate the first ERROR/exception point
4. Analyze contextual logs

日志设计约束

Log Design Constraints

  • 关键业务操作必须有 INFO 级别日志
  • 错误必须有 ERROR 级别日志,包含上下文
  • 日志必须包含追溯 ID
  • 日志必须标注关联的功能点编号
  • 敏感信息(密码、Token)不得出现在日志中
  • 日志格式必须支持结构化解析
  • Key business operations must have INFO-level logs
  • Errors must have ERROR-level logs with context
  • Logs must include trace ID
  • Logs must mark associated feature point IDs
  • Sensitive information (passwords, tokens) must not appear in logs
  • Log format must support structured parsing

约束

Constraints

基础约束

Basic Constraints

  • 必须先询问用户技术栈偏好和目标平台
  • 技术选型必须说明理由
  • 如用户无偏好,根据需求选择最优方案
  • 必须指定目标平台和最低版本要求
  • API 设计必须包含请求/响应示例
  • 数据模型必须考虑索引和查询模式
  • 必须识别与现有系统的集成点
  • 优先使用项目现有技术栈
  • Must first ask the user about tech stack preferences and target platform
  • Tech selection must explain reasons
  • If the user has no preference, select the optimal solution based on requirements
  • Must specify target platform and minimum version requirements
  • API design must include request/response examples
  • Data models must consider indexing and query patterns
  • Must identify integration points with existing systems
  • Prioritize using the project's existing tech stack

MTE 原则约束

MTE Principle Constraints

  • 每个模块职责单一,不超过一个变化原因
  • 核心业务逻辑必须可单元测试(无外部依赖或依赖可 Mock,详见
    /testing-guide
  • 预留合理扩展点,但不为假设需求设计
  • 依赖方向:外层依赖内层,内层不依赖外层
  • 接口优于实现:依赖抽象,不依赖具体实现
  • Each module has a single responsibility, no more than one reason for change
  • Core business logic must be unit testable (no external dependencies or dependencies can be Mocked, see
    /testing-guide
    for details)
  • Reserve reasonable extension points, but do not design for hypothetical requirements
  • Dependency direction: Outer layers depend on inner layers, inner layers do not depend on outer layers
  • Interfaces are preferred over implementations: Depend on abstractions, not concrete implementations

设计模式约束

Design Pattern Constraints

  • 只在解决实际问题时使用设计模式,不为使用而使用
  • 使用的设计模式必须说明解决什么问题
  • 优先选择简单方案,复杂方案需要说明理由
  • 相同问题在项目中使用一致的模式
  • Only use design patterns to solve actual problems, not for the sake of using them
  • Design patterns used must explain the problem they solve
  • Prioritize simple solutions, complex solutions need to explain reasons
  • Use consistent patterns for the same problem in the project

避免过度设计

Avoid Over-Design

  • 不为"未来可能"的需求设计,只为当前需求设计
  • 不创建只有一个实现的接口(除非为了可测试性)
  • 不过早抽象,等到有 3 个以上相似场景再抽象
  • 配置优于硬编码,但不为所有内容添加配置
  • Do not design for "possible future" requirements, only for current requirements
  • Do not create interfaces with only one implementation (unless for testability)
  • Do not abstract too early, wait until there are 3 or more similar scenarios before abstracting
  • Configuration is preferred over hardcoding, but do not add configuration for everything

安全约束

Security Constraints

  • 敏感数据(密码、Token)不明文存储
  • 需要认证的 API 已标注
  • 用户输入有验证(防注入)
  • 敏感操作有日志记录
  • Sensitive data (passwords, tokens) must not be stored in plaintext
  • APIs requiring authentication must be marked
  • User input must be validated (injection prevention)
  • Sensitive operations must have log records

增量设计约束

Incremental Design Constraints

  • 增量设计前必须进行影响分析
  • 必须评估向后兼容性
  • 破坏性变更必须标注处理方式
  • 必须生成设计变更记录
  • 新增内容必须标注关联需求(F-XXX / INS-XXX)
  • 修改现有接口必须说明兼容性
  • 数据模型变更必须说明迁移方案
  • Impact analysis must be performed before incremental design
  • Backward compatibility must be evaluated
  • Breaking changes must be marked with handling methods
  • Design change records must be generated
  • New content must mark associated requirements (F-XXX / INS-XXX)
  • Modifications to existing interfaces must explain compatibility
  • Data model changes must explain migration plans

Skill 协作

Skill Collaboration

场景协作 Skill说明
新功能设计变更
/devdocs-feature
新功能触发增量设计
优化建议设计变更
/devdocs-insights
洞察确认后触发增量设计
可测试性设计
/testing-guide
确保核心逻辑可单元测试
代码质量
/code-quality
MTE 原则指导设计
UI 架构
/ui-orchestrator
路由到专业的外部 UI/UX Skill
接口自动提取
/devdocs-retrofit
从现有代码逆向提取接口定义并同步到设计文档
ScenarioCollaboration SkillDescription
New feature design change
/devdocs-feature
New features trigger incremental design
Optimization suggestion design change
/devdocs-insights
Incremental design is triggered after insights are confirmed
Testability design
/testing-guide
Ensure core logic is unit testable
Code quality
/code-quality
Guide design with MTE principles
UI architecture
/ui-orchestrator
Route to professional external UI/UX Skill
Automatic interface extraction
/devdocs-retrofit
Reverse extract interface definitions from existing code and sync to design documents

下一步

Next Steps

初始设计后

After Initial Design

用户确认系统设计后,建议运行
/devdocs-test-cases
进入测试用例设计阶段。
After the user confirms the system design, it is recommended to run
/devdocs-test-cases
to enter the test case design phase.

增量设计后

After Incremental Design

  1. 如有新增功能点 → 运行
    /devdocs-test-cases
    补充测试用例
  2. 如有数据模型变更 → 准备数据库迁移脚本
  3. 如有破坏性变更 → 通知相关依赖方
  1. If there are new feature points → Run
    /devdocs-test-cases
    to supplement test cases
  2. If there are data model changes → Prepare database migration scripts
  3. If there are breaking changes → Notify relevant dependent parties