ADR 格式
ADR 格式
Section titled “ADR 格式”ADR 放在 docs/adr/ 目录下,并按顺序编号:0001-slug.md、0002-slug.md 等。
延后创建 docs/adr/ 目录:只有需要记录第一个 ADR 时才创建。
# {决策的简短标题}
{用 1 到 3 句话说明背景、作出的决定,以及原因。}就这些。ADR 可以只有一个段落。记录下作出了决定以及作出决定的原因,才是它的价值,不必填满各个章节。
只有在确实有帮助时才添加。大多数 ADR 用不上这些章节。
- 状态 frontmatter(
proposed | accepted | deprecated | superseded by ADR-NNNN):适用于可能重新审视的决定 - 考虑过的选项:只有在值得记住被否决的替代方案时才添加
- 后果:只有在需要指出不明显的下游影响时才添加
扫描 docs/adr/,找到已有的最大编号,再加一。
何时提出 ADR
Section titled “何时提出 ADR”以下三项必须同时满足:
- 难以撤销:以后改变主意的成本不低
- 缺少背景就会令人意外:未来的读者看到代码时会纳闷:“为什么偏偏要这么做?”
- 源于真实取舍:确实存在不同选项,而你基于具体原因选择了其中一个
如果一个决定很容易撤销,就跳过记录:直接撤销即可。如果它不令人意外,就没人会追问原因。如果没有真正的替代方案,也就没什么可记录的,除了“我们选择了显而易见的做法”。
哪些情况符合条件
Section titled “哪些情况符合条件”- 架构形态。“我们采用 monorepo。”“写模型采用事件溯源,读模型投影到 Postgres。”
- 上下文之间的集成模式。“Ordering 和 Billing 通过领域事件通信,而不是同步 HTTP。”
- **会造成锁定的技术选择。**数据库、消息总线、身份验证提供商、部署目标。不必记录每个库,只记录那些替换起来要花一个季度的选择。
- 边界和范围决策。“Customer 数据归 Customer 上下文所有;其他上下文只通过 ID 引用它。”明确说明不做什么,和说明要做什么同样有价值。
- 有意偏离显而易见的做法。“我们手写 SQL,不用 ORM,因为 X。”凡是合理的读者可能会以为你会采用相反做法的情况,都值得记录。这样可以避免后续工程师把有意为之的决定“修正”掉。
- 代码中看不出来的约束。“由于合规要求,我们不能使用 AWS。”“由于合作方 API 合同,响应时间必须低于 200ms。”
- **否决理由不明显的替代方案。**如果你考虑过 GraphQL,最后因一些微妙的原因选择了 REST,就把它记下来;否则六个月后肯定又有人会提议用 GraphQL。
原文链接和 commit
Section titled “原文链接和 commit”英文 ADR-FORMAT.md
# ADR Format
ADRs live in `docs/adr/` and use sequential numbering: `0001-slug.md`, `0002-slug.md`, etc.
Create the `docs/adr/` directory lazily: only when the first ADR is needed.
## Template
```md# {Short title of the decision}
{1-3 sentences: what's the context, what did we decide, and why.}```
That's it. An ADR can be a single paragraph. The value is in recording *that* a decision was made and *why*, not in filling out sections.
## Optional sections
Only include these when they add genuine value. Most ADRs won't need them.
- **Status** frontmatter (`proposed | accepted | deprecated | superseded by ADR-NNNN`): useful when decisions are revisited- **Considered Options**: only when the rejected alternatives are worth remembering- **Consequences**: only when non-obvious downstream effects need to be called out
## Numbering
Scan `docs/adr/` for the highest existing number and increment by one.
## When to offer an ADR
All three of these must be true:
1. **Hard to reverse**: the cost of changing your mind later is meaningful2. **Surprising without context**: a future reader will look at the code and wonder "why on earth did they do it this way?"3. **The result of a real trade-off**: there were genuine alternatives and you picked one for specific reasons
If a decision is easy to reverse, skip it: you'll just reverse it. If it's not surprising, nobody will wonder why. If there was no real alternative, there's nothing to record beyond "we did the obvious thing."
### What qualifies
- **Architectural shape.** "We're using a monorepo." "The write model is event-sourced, the read model is projected into Postgres."- **Integration patterns between contexts.** "Ordering and Billing communicate via domain events, not synchronous HTTP."- **Technology choices that carry lock-in.** Database, message bus, auth provider, deployment target. Not every library: just the ones that would take a quarter to swap out.- **Boundary and scope decisions.** "Customer data is owned by the Customer context; other contexts reference it by ID only." The explicit no-s are as valuable as the yes-s.- **Deliberate deviations from the obvious path.** "We're using manual SQL instead of an ORM because X." Anything where a reasonable reader would assume the opposite. These stop the next engineer from "fixing" something that was deliberate.- **Constraints not visible in the code.** "We can't use AWS because of compliance requirements." "Response times must be under 200ms because of the partner API contract."- **Rejected alternatives when the rejection is non-obvious.** If you considered GraphQL and picked REST for subtle reasons, record it; otherwise someone will suggest GraphQL again in six months.非官方学习站,与 Matt Pocock 和 AI Hero 没有隶属关系。本站不提供可安装的中文技能包。
技能原文采用 MIT 许可。Copyright (c) 2026 Matt Pocock