Explanation Documentation Skill
This skill provides patterns for writing effective explanation documents. Explanations are understanding-oriented content for readers who want to know why things work the way they do.
Purpose & Audience
Target readers:
- - Users who want to understand concepts deeply, not just use them
- Architects and technical leads evaluating design decisions
- Team members onboarding to a codebase or system
- Anyone asking "why?" or "how does this work?"
Explanations are for reading away from the keyboard. Unlike tutorials or how-to guides, readers aren't trying to accomplish a task while reading. They're building mental models.
Explanations are NOT:
- - Tutorials (which teach through hands-on doing)
- How-To guides (which accomplish specific goals)
- Reference docs (which look up precise details)
Explanation Document Template
Use this structure for all explanation documents:
CODEBLOCK0
Writing Principles
Focus on Understanding, Not Doing
Explanations answer "why?" and "how does it work?" rather than "how do I?"
| Explanation (good) | How-To (wrong context) |
|---|
| "The cache uses LRU eviction because memory is limited and recent items are more likely to be accessed again." | "To configure the cache, set the maxSize parameter." |
| "Authentication tokens expire to limit the damage if they're compromised." |
"Refresh your token by calling the
/refresh endpoint." |
Use Analogies and Mental Models
Connect unfamiliar concepts to things readers already know.
CODEBLOCK1
Explain the "Why" Behind Design Decisions
Don't just describe what exists - explain why it exists that way.
CODEBLOCK2
Discuss Trade-offs Honestly
Every design choice has costs. Acknowledging them builds trust and helps readers make informed decisions.
CODEBLOCK3
Structure for Reflection, Not Action
Explanations are read linearly, away from the keyboard. Structure them like essays, not manuals.
- - Use flowing prose more than bullet points
- Build concepts progressively - each section prepares for the next
- Allow for depth - it's okay if sections are longer than in how-to guides
- Include context that would be distracting in task-focused docs
Connect to the Bigger Picture
Show how this concept relates to other parts of the system or to broader industry patterns.
CODEBLOCK4
Components for Explanations
Diagrams and Visuals
Explanations benefit heavily from visual aids:
CODEBLOCK5 mermaid
graph LR
A[Client] --> B[Load Balancer]
B --> C[API Gateway]
C --> D[Service A]
C --> E[Service B]
D --> F[(Database)]
E --> F
CODEBLOCK6
Comparison Tables
Tables work well for comparing approaches:
CODEBLOCK7
Callouts for Key Insights
CODEBLOCK8
Expandable Sections for Depth
Use expandables for tangential but valuable details:
CODEBLOCK9
Example Explanation Document
CODEBLOCK10
Checklist for Explanations
Before publishing, verify:
- - [ ] Title indicates this explains a concept (not a how-to)
- [ ] Introduction sets expectations for what reader will understand
- [ ] Background section provides context and history
- [ ] Core concepts explained with analogies or mental models
- [ ] Design decisions include rationale, not just facts
- [ ] Trade-offs discussed honestly
- [ ] Alternatives mentioned and compared
- [ ] Implications for different concerns addressed
- [ ] Related concepts linked
- [ ] Written for reading away from keyboard (no tasks to follow)
- [ ] Progressive structure builds understanding step by step
When to Use Explanation vs Other Doc Types
| Reader's Question | Doc Type | Focus |
|---|
| "How do I do X?" | How-To Guide | Steps to accomplish a goal |
| "Teach me about X" |
Tutorial | Learning through guided doing |
| "What is the API for X?" | Reference | Precise technical details |
| "Why does X work this way?" |
Explanation | Understanding and context |
| "What are the trade-offs of X?" |
Explanation | Design rationale |
| "How does X relate to Y?" |
Explanation | Conceptual connections |
Explanation Signals
Write an explanation when users:
- - Ask "why" questions
- Need to make architectural decisions
- Are evaluating whether something fits their use case
- Want to understand design philosophy
- Need context before diving into implementation
Not an Explanation
If users need to accomplish something while reading, it's not an explanation:
- - "How to configure caching" - How-To Guide
- "Cache API reference" - Reference Doc
- "Build a caching layer tutorial" - Tutorial
- "How caching works and why we use LRU" - Explanation
Related Skills
- - docs-style: Core writing conventions and components
- howto-docs: How-To guide patterns for task-oriented content
- reference-docs: Reference documentation patterns for lookups
- tutorial-docs: Tutorial patterns for learning-oriented content
解释文档技能
本技能提供编写有效解释文档的模式。解释文档是面向理解的内容,适合想要了解事物运作原理及其原因的读者。
目的与受众
目标读者:
- - 希望深入理解概念而不仅仅是使用它们的用户
- 评估设计决策的架构师和技术负责人
- 正在熟悉代码库或系统的新团队成员
- 任何提出为什么?或这是如何工作的?的人
解释文档适合在离开键盘时阅读。 与教程或操作指南不同,读者在阅读时并不试图完成任务。他们正在构建心智模型。
解释文档不是:
- - 教程(通过动手实践来教学)
- 操作指南(完成特定目标)
- 参考文档(查找精确细节)
解释文档模板
所有解释文档使用此结构:
markdown
title: [概念/系统名称] 详解
description: 了解[概念]如何工作以及为何如此设计
理解[概念]
简要介绍(2-3句话):本文档解释的内容及其重要性。设定读者阅读后将理解什么的期望。
概述
概念的高层总结。它是什么?它解决什么问题?这部分应能在没有深厚技术知识的情况下理解。
背景与上下文
问题
什么情况或挑战导致了这种设计?用户或开发者在哪些方面遇到了困难?
历史背景
我们是如何走到这一步的?之前是什么?这有助于读者理解为什么替代方案被拒绝,或者为什么存在某些约束。
工作原理
核心概念
解释基本思想。使用类比来连接读者已经理解的概念。
在解释复杂关系或流程时,使用图表或视觉辅助工具。
机制
逐步说明系统实际如何运作。这是概念性的,而非程序性的——解释发生了什么而不是要做什么。
关键组件
分解主要部分及其交互方式。对于每个组件:
设计决策与权衡
为什么采用这种方法?
解释关键设计选择背后的原因。哪些目标驱动了这些决策?
所做的权衡
每个设计都涉及权衡。明确说明:
- - 优先考虑了哪些方面
- 牺牲了哪些方面
- 在什么条件下这种设计表现出色或存在困难
约束与假设
哪些约束塑造了设计?它依赖于哪些假设?
考虑的替代方案
[替代方案 1]
简要描述一种替代方案。为什么没有被选择?在什么情况下它可能更好?
[替代方案 2]
另一种替代方案。比较替代方案有助于读者理解设计空间。
影响与后果
这种设计对以下方面意味着什么:
相关概念
写作原则
聚焦理解,而非操作
解释文档回答为什么?和它是如何工作的?而不是我该怎么做?
| 解释(好的) | 操作指南(错误语境) |
|---|
| 缓存使用LRU淘汰策略,因为内存有限且最近使用的项目更可能被再次访问。 | 要配置缓存,请设置maxSize参数。 |
| 身份验证令牌设置过期时间,以限制被泄露时的损害。 |
通过调用/refresh端点刷新您的令牌。 |
使用类比和心智模型
将不熟悉的概念连接到读者已知的事物。
markdown
可以把消息队列想象成邮局。消息(信件)由发送者投递,并保存到收件人取走为止。邮局不关心内容——它只确保可靠投递。
消息队列实现了FIFO缓冲区,具有可配置的持久化和至少一次投递语义。
解释设计决策背后的为什么
不要只描述存在什么——要解释为什么以这种方式存在。
markdown
我们选择最终一致性而非强一致性,因为我们的读密集型工作负载(100:1的读写比)从低延迟中获益更多,而非即时一致性。大多数用户从未注意到短暂的延迟。
系统使用最终一致性,传播窗口为500毫秒。
诚实地讨论权衡
每个设计选择都有代价。承认它们可以建立信任,并帮助读者做出明智的决策。
markdown
权衡
这种架构优化了写入吞吐量,代价是:
- - 读取延迟:查询可能需要访问多个分区
- 复杂性:开发者必须理解分区键
- 成本:由于反规范化导致更多存储
这种权衡适用于我们的用例(高容量事件采集),但可能不适合读密集型分析工作负载。
为反思而非行动而构建
解释文档是线性阅读的,离开键盘。像文章一样构建,而不是手册。
- - 使用流畅的散文,而不是过多的项目符号
- 逐步构建概念——每个部分为下一个部分做准备
- 允许深度——部分内容比操作指南长是可以的
- 包含上下文——这些在任务导向的文档中会分散注意力
连接更广阔的图景
展示这个概念如何与系统的其他部分或更广泛的行业模式相关联。
markdown
相关概念
我们的事件溯源方法是我们更广泛的CQRS(命令查询职责分离)架构的一部分。理解事件溯源有助于解释:
- - 为什么我们的读模型是最终一致的
- 我们如何免费实现审计日志
- 为什么事件重放是我们测试策略的核心
有关CQRS的更多信息,请参阅理解我们的架构。
解释文档的组件
图表和视觉元素
解释文档从视觉辅助工具中获益良多:
markdown
系统架构
下图显示了请求如何在系统中流动:
mermaid
graph LR
A[客户端] --> B[负载均衡器]
B --> C[API网关]
C --> D[服务A]
C --> E[服务B]
D --> F[(数据库)]
E --> F
负载均衡器将流量分配到API网关实例...
比较表格
表格适合比较不同方法:
markdown
方法比较
| 方面 | 单体架构 | 微服务 |
|---|
| 部署 | 单一单元,更简单 | 独立,更复杂 |
| 扩展 |
垂直扩展 | 按服务水平扩展 |
| 团队自主性 | 较低 | 较高 |
| 运维开销 | 较低 | 较高 |
我们选择微服务是因为团队自主性对我们100+工程师的组织至关重要...
关键见解的标注
markdown
这是一个常见的混淆点:最终一致性中的最终并不意味着可能——它意味着不是立即,但保证最终会一致。
这种设计假设网络分区很少发生。在网络不可靠的环境中,考虑更强的保证。
可展开的深度内容
使用可展开部分来包含旁支但有价值的细节:
markdown
我们最初的实现使用Redis进行缓存。2023年,我们迁移到自定义解决方案,因为...
这个背景解释了为什么一些旧代码引用Redis模式,尽管我们不再直接使用它。
解释文档示例
markdown
title: 理解我们的身份验证系统
description: 了解身份验证在我们的平台中如何工作以及我们为何如此设计
理解我们的身份验证系统
本文档解释我们的身份验证系统如何工作及其设计背后的理由。阅读后,您将理解从登录到API访问的流程,以及我们为何做出所选的架构决策。
概述
我们的身份验证系统使用短期的访问令牌和长期的刷新令牌。这种模式有时称为令牌轮换,通过限制暴露同时避免频繁重新认证,在安全性和用户体验之间取得平衡。
背景与上下文
问题
现代Web应用面临相互竞争的需求:安全团队希望频繁轮换凭证,而用户期望无缝体验,无需不断登录。传统的基于会话的身份验证需要服务器端状态,使水平扩展复杂化。
历史背景
我们最初使用存储在Redis中的服务器端会话。随着扩展到多个区域,会话同步成为瓶颈。JWT令牌成为无状态身份验证的行业标准,我们在2022年采用了它。
工作原理
核心概念
访问令牌就像会议的一日通行证。它们允许在有限时间内进入,并在每个门口(API端点)被检查。如果有人偷了您的一日通行证,他们只能在到期前使用它。
刷新令牌就像您用来获取一日通行证的注册确认函。您不会随身携带它,但可以在通行证到期时用它获取新的通行证。
身份验证流程
当用户登录时:
- 1. 他们向身份验证服务提供凭证
- 如果有效,他们将收到一个访问令牌(15分钟过期)和一个刷新令牌(7天过期)
- 访问