design

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Design

设计文档

Workflow

工作流程

  1. Read the request, repository instructions, relevant code, and linked material.
  2. Identify choices that would change behavior, interfaces, data, errors, security, operations, or tests.
  3. Ask blocking questions before drafting. Ask only when the answer would change the design, and recommend an answer. Record non-blocking questions and a recommended default under Open questions.
  4. Write
    docs/<feature-slug>/design.md
    using the numbered shape below. Keep it short and in order. Omit only sections that do not apply.
  5. Run the review pass. Fix what you can. List the rest under Open questions.
  6. Stop with the proposed design ready for review. Do not plan or implement it.
  1. 阅读需求、仓库说明、相关代码及关联材料。
  2. 识别会改变行为、接口、数据、错误处理、安全、运维或测试的决策点。
  3. 撰写前提出阻塞性问题。仅当问题的答案会改变设计时才提问,并给出建议答案。将非阻塞性问题及建议默认方案记录在「待解决问题」部分。
  4. 使用下方编号结构编写
    docs/<feature-slug>/design.md
    。保持内容简洁并按顺序排列。仅省略不适用的章节。
  5. 进行审核检查。修复可解决的问题,其余问题列在「待解决问题」下。
  6. 完成待审核的拟议设计后停止工作。请勿进行规划或实现。

Document shape

文档结构

markdown
undefined
markdown
undefined

<Title>

<标题>

Status: Proposed for review
状态: 待审核提议

1. Executive summary

1. 执行摘要

Say what is wrong today, who feels the problem, what will change, how we plan to fix it, and the main downside. Use simple words. Do not list sections or implementation details.
说明当前存在的问题、受影响人群、将发生的变更、解决方案计划以及主要弊端。使用简洁语言,不要罗列章节或实现细节。

2. Context and scope

2. 背景与范围

Describe the current behavior, why it is insufficient, what changes once this ships, and the boundary of this design.
描述当前行为、其不足之处、上线后的变化以及本设计的边界。

3. System context

3. 系统上下文

Show where the change fits in the current system. Name the parts and outside systems it touches and the boundaries it must preserve. Include a small diagram when it makes those relationships clearer.
展示变更在当前系统中的定位。列出涉及的内部组件和外部系统,以及必须保留的边界。若能更清晰地展示关系,可添加小型示意图。

4. Proposed design

4. 拟议设计

How it works

工作原理

Walk one real case from start to finish. Name the thing that arrives, what handles it, what gets written down, and what the user sees.
从头到尾描述一个真实案例。说明输入内容、处理组件、记录的数据以及用户所见结果。

Components and responsibilities

组件与职责

For each changed part, state what it owns, what it depends on, and what it does not own.
针对每个变更的组件,说明其负责的内容、依赖项以及不负责的内容。

Decisions

决策记录

For each real choice, say what you chose, what you rejected, and what the choice costs. Use one short paragraph. Skip choices nobody would question.
针对每个关键决策,说明选择方案、否决方案以及该决策的成本。使用简短段落,无需记录无争议的决策。

5. Invariants and requirements

5. 不变量与需求

Invariants

不变量

List rules that must always hold as
INV-1
,
INV-2
, and so on. A reviewer checks the code against these rules, so keep them short and testable.
列出必须始终遵循的规则,编号为
INV-1
INV-2
等。审核者将对照这些规则检查代码,因此需保持规则简短且可测试。

Requirements

需求

  • Observable behavior and constraints.
  • 可观测的行为与约束条件。

6. Interfaces and data

6. 接口与数据

APIs, commands, events, schemas, config, compatibility, or migration.
API、命令、事件、 schema、配置、兼容性或迁移方案。

Naming and identity

命名与标识

How every stored name or ID is created, what happens when that fails, and what happens if its source changes after data exists.
说明每个存储名称或ID的生成方式、生成失败时的处理逻辑,以及数据源在数据生成后发生变化时的处理方式。

7. Failure behavior and lifecycle

7. 故障行为与生命周期

Say what can fail, what state follows, whether the system retries, and how it recovers. Cover startup, config or state changes, work in flight, shutdown, and what happens when several things fail together.
说明可能发生的故障、故障后的状态、系统是否重试以及恢复方式。涵盖启动、配置或状态变更、处理中任务、关闭,以及多故障同时发生时的情况。

8. Security, privacy, and operations

8. 安全、隐私与运维

State the trust boundary, authorization checks, sensitive data handling, and operational impact. Name shared limits such as rate limits, connections, disk, memory, or cost. Say what happens at each limit.
说明信任边界、授权检查、敏感数据处理方式及运维影响。列出共享限制,如速率限制、连接数、磁盘、内存或成本,并说明达到限制时的处理逻辑。

9. Acceptance criteria

9. 验收标准

  • AC-1
    : Testable condition that proves the work is complete.
  • AC-1
    : 可测试的条件,用于证明工作已完成。

10. Test approach

10. 测试方法

How each
INV-n
and
AC-n
will be proved. Cite the IDs.
说明如何验证每个
INV-n
AC-n
,需引用对应编号。

11. Risks and tradeoffs

11. 风险与权衡

  • Risk and mitigation.
  • 风险及缓解措施。

12. Open questions

12. 待解决问题

  • Question, and whether it blocks starting work.
  • 问题,以及是否会阻碍工作启动。

13. Out of scope

13. 超出范围

  • Related work this design does not include.
undefined
  • 本设计未涵盖的相关工作。
undefined

Writing rules

写作规则

  • Start with the simplest useful explanation. Write for a new teammate, not someone who already knows the project.
  • Prose is the default. Use bullets only for real lists, such as config fields, acceptance criteria, risks, and out of scope.
  • A bullet cannot carry a decision by itself. Write the reason next to it in a sentence.
  • Use plain words. Say "the process crashed" instead of "an availability event occurred". Prefer short sentences.
  • Define a term the first time you use it, or do not use it.
  • Keep current architecture and proposed behavior distinct. Link to
    ARCHITECTURE.md
    when it exists and say exactly which current boundary changes.
  • Give each changed component a positive and negative boundary: what it owns and what it does not own.
  • Use numbered top-level sections so reviewers can refer to stable parts of the design.
  • Once another artifact cites an
    INV-n
    or
    AC-n
    , keep that ID attached to the same rule. Do not renumber or reuse existing IDs. Give additions the next unused ID.
  • Use diagrams only when they make system context, dependency direction, data flow, or lifecycle materially clearer.
  • Prefer one clear recommendation over a list of options.
  • Record rejected options only when the tradeoff matters later.
  • Do not repeat the same fact in several sections with different wording.
  • Do not use em dashes.
  • 从最简单易懂的解释开始。为新团队成员撰写,而非熟悉项目的人员。
  • 默认使用散文式表述。仅在需要列出真实条目时使用项目符号,如配置字段、验收标准、风险及超出范围的内容。
  • 项目符号不能单独承载决策内容,需在旁边用句子说明原因。
  • 使用平实语言。例如,说“进程崩溃”而非“发生可用性事件”。优先使用短句。
  • 首次使用术语时需定义,否则不要使用。
  • 明确区分当前架构与拟议行为。若存在
    ARCHITECTURE.md
    ,请链接至该文档并明确说明哪些现有边界会发生变化。
  • 为每个变更的组件明确正向和负向边界:负责的内容与不负责的内容。
  • 使用编号的顶级章节,以便审核者能引用设计文档的固定部分。
  • 一旦其他文档引用了
    INV-n
    AC-n
    ,需保持该编号与对应规则绑定。不要重新编号或复用现有编号,新增规则使用下一个未使用的编号。
  • 仅当示意图能显著清晰地展示系统上下文、依赖方向、数据流或生命周期时才使用。
  • 优先给出清晰的建议,而非罗列选项。
  • 仅当权衡对后续工作有影响时,才记录否决的选项。
  • 不要在多个章节用不同措辞重复相同事实。
  • 不要使用破折号。

Review pass

审核检查

Reread the draft once and check each category. Fix any gap you can resolve from the available evidence.
  1. Executive summary. Can a new teammate understand the problem, outcome, approach, and main downside without reading the rest of the document?
  2. Architecture fit. Does the design show the current system boundary, the boundary being changed, and the owner of each new responsibility?
  3. Names and identity. Where does every stored identifier come from? What happens when it is missing, unclear, or changes after data exists?
  4. Failure and recovery. What creates a bad state? Does the system retry, how long does it wait between attempts, and can it recover without a restart? What happens when everything is bad at startup?
  5. Security and privacy. Where is identity established, authorization enforced, untrusted input validated, and sensitive data exposed or retained?
  6. Shared resources. What limited resource does the feature use? State the budget and what happens at the limit.
  7. Timing and fairness. Replace words such as "eventually" and "will not starve" with a bound someone can test.
  8. Lifecycle. Cover config reload, enable and disable behavior, work already in flight, and shutdown.
  9. Undefined terms. Define words that carry a specific meaning in the design.
  10. Either/or acceptance criteria. Do not allow both sides of "recovers or retains" to pass. Choose one observable behavior.
Put anything you cannot resolve under Open questions and state whether it blocks task breakdown.
重新阅读草稿并检查以下每个类别。根据现有信息修复可解决的空白。
  1. 执行摘要:新团队成员无需阅读文档其余部分,能否理解问题、结果、方案及主要弊端?
  2. 架构适配:设计是否展示了当前系统边界、将变更的边界以及每个新职责的归属?
  3. 命名与标识:每个存储的标识符来自何处?缺失、模糊或数据源在数据生成后发生变化时如何处理?
  4. 故障与恢复:什么会导致不良状态?系统是否重试、重试间隔多久、无需重启能否恢复?启动时所有组件都异常时会发生什么?
  5. 安全与隐私:身份验证、授权检查、不可信输入验证的位置,以及敏感数据的暴露或保留方式?
  6. 共享资源:该功能使用哪些有限资源?说明预算及达到限制时的处理逻辑。
  7. 时序与公平性:将“最终”“不会饥饿”等词汇替换为可测试的约束条件。
  8. 生命周期:涵盖配置重载、行为启用与禁用、处理中任务及关闭场景。
  9. 未定义术语:定义设计中具有特定含义的词汇。
  10. 二选一验收标准:不要允许“恢复或保留”两种情况都通过。选择一种可观测的行为。
将无法解决的问题列在「待解决问题」下,并说明是否会阻碍任务拆分。