adr-code-traceability

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

ADR Code Traceability

ADR代码可追溯性

Add Architecture Decision Record references to code for decision traceability. Provides language-specific patterns and placement guidelines.
在代码中添加架构决策记录(ADR)引用,以实现决策可追溯性。本文提供了特定语言的模式和放置指南。

When to Use This Skill

何时使用此技能

  • Creating new files as part of an ADR implementation
  • Documenting non-obvious implementation choices
  • User mentions "ADR traceability", "code reference", "document decision"
  • Adding decision context to code during
    /itp:go
    Phase 1
  • 在实现ADR的过程中创建新文件时
  • 记录非显而易见的实现选择时
  • 用户提及“ADR可追溯性”、“代码引用”、“记录决策”时
  • /itp:go
    第一阶段为代码添加决策上下文时

Quick Reference

快速参考

Reference Format

引用格式

ADR: {adr-id}
Path Derivation:
ADR: 2025-12-01-my-feature
/docs/adr/2025-12-01-my-feature.md
ADR: {adr-id}
路径推导
ADR: 2025-12-01-my-feature
/docs/adr/2025-12-01-my-feature.md

Language Patterns (Summary)

语言模式(摘要)

LanguageNew File HeaderInline Comment
Python
"""...\n\nADR: {adr-id}\n"""
# ADR: {adr-id} - reason
TypeScript
/** ... \n * @see ADR: {adr-id} */
// ADR: {adr-id} - reason
Rust
//! ...\n//! ADR: {adr-id}
// ADR: {adr-id} - reason
Go
// Package ... \n// ADR: {adr-id}
// ADR: {adr-id} - reason
See Language Patterns for complete examples.

语言新文件头部格式行内注释格式
Python
"""...\n\nADR: {adr-id}\n"""
# ADR: {adr-id} - reason
TypeScript
/** ... \n * @see ADR: {adr-id} */
// ADR: {adr-id} - reason
Rust
//! ...\n//! ADR: {adr-id}
// ADR: {adr-id} - reason
Go
// Package ... \n// ADR: {adr-id}
// ADR: {adr-id} - reason
查看语言模式获取完整示例。

Placement Decision Tree

放置决策树

Is this a NEW file created by the ADR?
├── Yes → Add reference in file header
└── No → Is the change non-obvious?
    ├── Yes → Add inline comment with reason
    └── No → Skip ADR reference
See Placement Guidelines for detailed guidance.

这是由ADR创建的新文件吗?
├── 是 → 在文件头部添加引用
└── 否 → 该更改是否非显而易见?
    ├── 是 → 添加带有原因的行内注释
    └── 否 → 跳过ADR引用
查看放置指南获取详细说明。

Examples

示例

New File (Python)

新文件(Python)

python
"""
Redis cache adapter for session management.

ADR: 2025-12-01-redis-session-cache
"""

class RedisSessionCache:
    ...
python
"""
Redis cache adapter for session management.

ADR: 2025-12-01-redis-session-cache
"""

class RedisSessionCache:
    ...

Inline Comment (TypeScript)

行内注释(TypeScript)

typescript
// ADR: 2025-12-01-rate-limiting - Using token bucket over sliding window
// for better burst handling in our use case
const rateLimiter = new TokenBucketLimiter({ rate: 100, burst: 20 });

typescript
// ADR: 2025-12-01-rate-limiting - Using token bucket over sliding window
// for better burst handling in our use case
const rateLimiter = new TokenBucketLimiter({ rate: 100, burst: 20 });

Do NOT Add References For

请勿添加引用的场景

  • Every line touched (only where traceability adds value)
  • Trivial changes (formatting, typo fixes)
  • Standard patterns (well-known idioms)
  • Test files (unless test approach is an ADR decision)

  • 每一行修改都添加(仅在可追溯性能带来价值时添加)
  • 微小更改(格式调整、拼写修正)
  • 标准模式(众所周知的惯用写法)
  • 测试文件(除非测试方法是ADR决策的一部分)

Reference Documentation

参考文档

  • Language Patterns - Python, TS, Rust, Go patterns
  • Placement Guidelines - When and where to add

  • 语言模式 - Python、TS、Rust、Go模式
  • 放置指南 - 添加的时机和位置

Troubleshooting

故障排除

IssueCauseSolution
ADR not foundWrong path formatUse relative path from repo root
Reference not showingComment syntax wrongCheck language-specific comment format
Too many referencesOver-documentingOnly add where traceability adds value
Outdated ADR linkADR was renamedUpdate path to match current ADR filename
Hook reminder annoyingNo ADR for this changeAdd inline ADR comment or create new ADR
问题原因解决方案
找不到ADR路径格式错误使用相对于仓库根目录的路径
引用未显示注释语法错误检查特定语言的注释格式
引用过多过度文档化仅在可追溯性能带来价值时添加
ADR链接过时ADR已重命名更新路径以匹配当前ADR文件名
Hook提醒烦人此更改没有对应的ADR添加行内ADR注释或创建新的ADR