Communitygithub.com

架构决策记录

在 Claude Code 会话期间捕获架构决策,并将其结构化为 ADR。自动检测决策时刻,记录背景、备选方案和理由。维护一个 ADR 日志,让未来的开发者能够理解代码库为何如此设计。

架构决策记录 是什么?

架构决策记录 (ADR) 技能旨在解决软件开发中一个普遍痛点:架构决策经常在会议、即时消息或 PR 评论中做出,随后这些上下文信息就会丢失。该技能自动检测决策时刻——例如用户明确要求记录、在重要备选方案之间做选择,或提及关键权衡——然后提示用户生成结构化的 ADR 文档。ADR 遵循 Michael Nygard 的轻量级格式,包含上下文、决策、备选方案(含利弊分析)以及后果(含正面、负面和风险)。该技能支持完整的 ADR 生命周期(提议 → 已接受 → 已弃用/已取代),并维护一个索引(`docs/adr/README.md`)。当用户问“为什么选择 X?”时,该技能会扫描此索引并呈现相关决策。关键警告:除非用户明确确认,否则不会写入任何文件,从而避免创建不需要的目录或文档。该技能与计划者和代码审查者代理集成,以鼓励在架构变更发生时记录它们。

兼容平台✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/everything-claude-code/tree/main/skills/architecture-decision-records

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

架构决策记录 是做什么的?

在编码会话期间捕获架构决策。与其让决策只存在于 Slack 线程、PR 评论或某人的记忆中,不如让本技能生成结构化的 ADR 文档,这些文档与代码共存。

何时激活

  • 用户明确说“让我们记录这个决策”或“把这个做成 ADR”
  • 用户在重要的备选方案之间做选择(框架、库、模式、数据库、API 设计)
  • 用户说“我们决定...”或“我们做 X 而不是 Y 的原因是...”
  • 用户问“为什么我们选择了 X?”(阅读现有 ADR)
  • 在规划阶段,讨论架构权衡时

ADR 格式

使用 Michael Nygard 提出的轻量级 ADR 格式,针对 AI 辅助开发进行了调整:

# ADR-NNNN:[决策标题]

**日期**:YYYY-MM-DD
**状态**:proposed | accepted | deprecated | superseded by ADR-NNNN
**决策者**:[参与决策的人]

## 上下文

促成这个决策或变更的问题是?

[2-5 句话描述情况、约束条件以及各种影响因素]

## 决策

我们提议和/或正在进行的更改是什么?

[1-3 句话清晰陈述决策]

## 考虑的备选方案

### 备选方案 1:[名称]
- **优点**:[好处]
- **缺点**:[弊端]
- **不采纳的原因**:[该方案被拒绝的具体理由]

### 备选方案 2:[名称]
- **优点**:[好处]
- **缺点**:[弊端]
- **不采纳的原因**:[该方案被拒绝的具体理由]

## 后果

这个变更让什么事情变得更容易或更困难?

### 正面影响
- [好处 1]
- [好处 2]

### 负面影响
- [权衡 1]
- [权衡 2]

### 风险
- [风险及其缓解措施]

工作流程

捕获新的 ADR

当检测到决策时刻时:

  1. 初始化(仅首次) — 如果 docs/adr/ 不存在,请在创建目录之前询问用户确认,目录中应包含一个包含索引表头的 README.md(见下方 ADR 索引格式),以及一个供手动使用的空白 template.md。未经明确同意,请勿创建文件。
  2. 识别决策 — 提取正在做出的核心架构选择
  3. 收集上下文 — 是什么问题促成了这个决策?存在哪些约束?
  4. 记录备选方案 — 还考虑了哪些其他选项?为什么被拒绝?
  5. 陈述后果 — 存在哪些权衡?什么事情变得更容易/更困难?
  6. 分配编号 — 扫描 docs/adr/ 中的现有 ADR,然后递增编号
  7. 确认并写入 — 将 ADR 草稿呈现给用户审阅。只有在用户明确批准后,才写入 docs/adr/NNNN-decision-title.md。如果用户拒绝,则丢弃草稿,不写入任何文件。
  8. 更新索引 — 追加到 docs/adr/README.md

阅读现有 ADR

当用户问“为什么我们选择了 X?”时:

  1. 检查 docs/adr/ 是否存在——如果不存在,回复:“该项目中未找到 ADR。您想开始记录架构决策吗?”
  2. 如果存在,扫描 docs/adr/README.md 索引以查找相关条目
  3. 读取匹配的 ADR 文件,并呈现“上下文”和“决策”部分
  4. 如果未找到匹配项,回复:“未找到该决策对应的 ADR。您现在想记录一个吗?”

ADR 目录结构

docs/
└── adr/
    ├── README.md              ← 所有 ADR 的索引
    ├── 0001-use-nextjs.md
    ├── 0002-postgres-over-mongo.md
    ├── 0003-rest-over-graphql.md
    └── template.md            ← 供手动使用的空白模板

ADR 索引格式

# 架构决策记录

| ADR | 标题 | 状态 | 日期 |
|-----|------|------|------|
| [0001](0001-use-nextjs.md) | 使用 Next.js 作为前端框架 | accepted | 2026-01-15 |
| [0002](0002-postgres-over-mongo.md) | 使用 PostgreSQL 而非 MongoDB 作为主数据存储 | accepted | 2026-01-20 |
| [0003](0003-rest-over-graphql.md) | 使用 REST API 而非 GraphQL | accepted | 2026-02-01 |

决策检测信号

观察对话中表明架构决策的以下模式:

显式信号

  • “我们选择 X”
  • “我们应该用 X 而不是 Y”
  • “这个权衡是值得的,因为...”
  • “把这个记录为 ADR”

隐式信号(建议记录 ADR —— 未经用户确认请勿自动创建)

  • 比较两个框架或库并达成结论
  • 做出数据库模式设计选择并给出理由
  • 选择架构模式(单体 vs 微服务,REST vs GraphQL)
  • 决定身份验证/授权策略
  • 在评估备选方案后选择部署基础设施

如何写好 ADR

应该做

  • 具体明确 — 写“使用 Prisma ORM”而不是“使用 ORM”
  • 记录原因 — 理由比结果更重要
  • 包含被拒绝的备选方案 — 未来的开发者需要知道考虑了哪些选项
  • 诚实地陈述后果 — 每个决策都有权衡
  • 保持简洁 — 一个 ADR 应在 2 分钟内读完
  • 使用现在时 — 写“我们使用 X”而不是“我们将使用 X”

不应该做

  • 记录琐碎决策 — 变量命名或格式选择不需要 ADR
  • 写长篇大论 — 如果上下文部分超过 10 行,就是太长了
  • 省略备选方案 — “我们只是选了它”不是有效的理由
  • 不注明就补录 — 如果记录过去的决策,请注明原始日期
  • 让 ADR 过时 — 被取代的决策应引用其替代者

ADR 生命周期

proposed → accepted → [deprecated | superseded by ADR-NNNN]
  • proposed:决策正在讨论中,尚未确定
  • accepted:决策已生效并正在被遵循
  • deprecated:决策已不再相关(例如,功能已移除)
  • superseded:新的 ADR 取代了此 ADR(始终链接取代者)

值得记录的决策类别

类别示例
技术选择框架、语言、数据库、云提供商
架构模式单体 vs 微服务、事件驱动、CQRS
API 设计REST vs GraphQL、版本控制策略、身份验证机制
数据建模模式设计、规范化决策、缓存策略
基础设施部署模型、CI/CD 流水线、监控栈
安全身份验证策略、加密方法、密钥管理
测试测试框架、覆盖率目标、E2E 与集成测试的平衡
流程分支策略、审查流程、发布节奏

与其他技能的集成

  • 计划者代理:当计划者提出架构变更时,建议创建 ADR
  • 代码审查者代理:标记那些引入了架构变更但没有相应 ADR 的 PR

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

affaan-m/everything-claude-code

End-to-end marketing campaign planning and execution. Covers audience research, positioning, campaign angle definition, landing page copy, email sequences, social posts, ad copy, short-form video scripts, and content calendars. Use as the orchestration layer for multi-channel product launches. Use when planning or executing a multi-channel product launch, or producing landing page, email, social, or ad copy.

affaan-m/everything-claude-code

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/everything-claude-code-conventions

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use when the user asks to build web components, pages, or applications and the visual direction matters as much as the code quality.

affaan-m/gget

gget CLI and Python workflow for quick genomic database queries, sequence lookup, BLAST-style searches, enrichment checks, and reproducible bioinformatics evidence logs.

affaan-m/literature-review

Systematic literature-review workflow for academic, biomedical, technical, and scientific topics, including search planning, source screening, synthesis, citation checks, and evidence logging.

affaan-m/motion-ui

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

affaan-m/project-guidelines-example

Example project-specific skill template based on a real production application.

affaan-m/pubmed-database

Direct PubMed and NCBI E-utilities search workflows for biomedical literature, MeSH queries, PMID lookup, citation retrieval, and API-backed literature monitoring.

affaan-m/scholar-evaluation

Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.

affaan-m/uspto-database

USPTO patent and trademark data workflow for official record lookup, PatentSearch queries, TSDR checks, assignment data, and reproducible IP research logs.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

相关技能