Codebase Documenter
Overview
This skill enables creating comprehensive, beginner-friendly documentation for codebases. It provides structured templates and best practices for writing READMEs, architecture guides, code comments, and API documentation that help new users quickly understand and contribute to projects.
Core Principles for Beginner-Friendly Documentation
When documenting code for new users, follow these fundamental principles:
- 1. Start with the "Why" - Explain the purpose before diving into implementation details
- Use Progressive Disclosure - Present information in layers from simple to complex
- Provide Context - Explain not just what the code does, but why it exists
- Include Examples - Show concrete usage examples for every concept
- Assume No Prior Knowledge - Define terms and avoid jargon when possible
- Visual Aids - Use diagrams, flowcharts, and file tree structures
- Quick Wins - Help users get something running within 5 minutes
Documentation Types and When to Use Them
1. README Documentation
When to create: For project root directories, major feature modules, or standalone components.
Structure to follow:
CODEBLOCK0
Best practices:
- - Lead with the project's value proposition
- Include setup instructions that actually work (test them!)
- Provide a visual overview of the project structure
- Link to deeper documentation for advanced topics
- Keep the root README focused on getting started
2. Architecture Documentation
When to create: For projects with multiple modules, complex data flows, or non-obvious design decisions.
Structure to follow:
CODEBLOCK1
Best practices:
- - Use diagrams to show system components and relationships
- Explain the "why" behind architectural decisions
- Document both the happy path and error handling
- Identify boundaries between modules
- Include visual file tree structures with annotations
3. Code Comments
When to create: For complex logic, non-obvious algorithms, or code that requires context.
Annotation patterns:
Function/Method Documentation:
CODEBLOCK2
Complex Logic Documentation:
CODEBLOCK3
Best practices:
- - Explain "why" not "what" - the code shows what it does
- Document edge cases and business logic
- Add examples for complex functions
- Explain parameters that aren't self-explanatory
- Note any gotchas or counterintuitive behavior
4. API Documentation
When to create: For any HTTP endpoints, SDK methods, or public interfaces.
Structure to follow:
CODEBLOCK4
Best practices:
- - Provide working curl examples
- Show both success and error responses
- Explain authentication clearly
- Document rate limits and constraints
- Include troubleshooting for common issues
Documentation Workflow
Step 1: Analyze the Codebase
Before writing documentation:
- 1. Identify entry points - Main files, index files, app initialization
- Map dependencies - How modules relate to each other
- Find core concepts - Key abstractions users need to understand
- Locate configuration - Environment setup, config files
- Review existing docs - Build on what's there, don't duplicate
Step 2: Choose Documentation Type
Based on user request and codebase analysis:
- - New project or missing README → Start with README documentation
- Complex architecture or multiple modules → Create architecture documentation
- Confusing code sections → Add inline code comments
- HTTP/API endpoints → Write API documentation
- Multiple types needed → Address in order: README → Architecture → API → Comments
Step 3: Generate Documentation
Use the templates from assets/templates/ as starting points:
- -
assets/templates/README.template.md - For project READMEs - INLINECODE2 - For architecture docs
- INLINECODE3 - For API documentation
Customize templates based on the specific codebase:
- 1. Fill in project-specific information - Replace placeholders with actual content
- Add concrete examples - Use real code from the project
- Include visual aids - Create file trees, diagrams, flowcharts
- Test instructions - Verify setup steps actually work
- Link related docs - Connect documentation pieces together
Step 4: Review for Clarity
Before finalizing documentation:
- 1. Read as a beginner - Does it make sense without project context?
- Check completeness - Are there gaps in the explanation?
- Verify examples - Do code examples actually work?
- Test instructions - Can someone follow the setup steps?
- Improve structure - Is information easy to find?
Documentation Templates
This skill includes several templates in assets/templates/ that provide starting structures:
Available Templates
- - README.template.md - Comprehensive README structure with sections for quick start, project structure, and common tasks
- ARCHITECTURE.template.md - Architecture documentation template with system design, data flow, and design decisions
- API.template.md - API endpoint documentation with request/response formats and examples
- CODE_COMMENTS.template.md - Examples and patterns for effective inline documentation
Using Templates
- 1. Read the appropriate template from INLINECODE5
- Customize for the specific project - Replace placeholders with actual information
- Add project-specific sections - Extend the template as needed
- Include real examples - Use actual code from the codebase
- Remove irrelevant sections - Delete parts that don't apply
Best Practices Reference
For detailed documentation best practices, style guidelines, and advanced patterns, refer to:
- -
references/documentation_guidelines.md - Comprehensive style guide and best practices - INLINECODE7 - How to create effective diagrams and file trees
Load these references when:
- - Creating documentation for complex enterprise codebases
- Dealing with multiple stakeholder requirements
- Needing advanced documentation patterns
- Standardizing documentation across a large project
Common Patterns
Creating File Tree Structures
File trees help new users understand project organization:
CODEBLOCK5
Explaining Complex Data Flows
Use numbered steps with diagrams:
CODEBLOCK6
Documenting Design Decisions
Capture the "why" behind architectural choices:
CODEBLOCK7
Output Guidelines
When generating documentation:
- 1. Write for the target audience - Adjust complexity based on whether documentation is for beginners, intermediate, or advanced users
- Use consistent formatting - Follow markdown conventions, consistent heading hierarchy
- Provide working examples - Test all code snippets and commands
- Link between documents - Create a documentation navigation structure
- Keep it maintainable - Documentation should be easy to update as code changes
- Add dates and versions - Note when documentation was last updated
Quick Reference
Command to generate README:
"Create a README file for this project that helps new developers get started"
Command to document architecture:
"Document the architecture of this codebase, explaining how the different modules interact"
Command to add code comments:
"Add explanatory comments to this file that help new developers understand the logic"
Command to document API:
"Create API documentation for all the endpoints in this file"
代码库文档生成器
概述
该技能能够为代码库创建全面且对初学者友好的文档。它提供了结构化模板和最佳实践,用于编写README、架构指南、代码注释和API文档,帮助新用户快速理解项目并参与贡献。
面向初学者的文档核心原则
为新用户编写文档时,请遵循以下基本原则:
- 1. 从为什么开始 - 在深入实现细节之前先解释目的
- 采用渐进式披露 - 按从简单到复杂的层次呈现信息
- 提供上下文 - 不仅要解释代码做什么,还要说明它为什么存在
- 包含示例 - 为每个概念提供具体的使用示例
- 假设无先验知识 - 定义术语,尽可能避免使用行话
- 视觉辅助 - 使用图表、流程图和文件树结构
- 快速见效 - 帮助用户在5分钟内让项目运行起来
文档类型及其使用场景
1. README文档
创建时机: 项目根目录、主要功能模块或独立组件。
遵循结构:
markdown
项目名称
功能说明
[1-2句通俗易懂的解释]
快速开始
[让用户在5分钟内运行项目]
项目结构
[带说明的可视化文件树]
核心概念
[用户需要理解的核心概念]
常见任务
[常用操作的逐步指南]
故障排除
[常见问题及解决方案]
最佳实践:
- - 以项目的价值主张开头
- 包含实际可用的安装说明(务必测试!)
- 提供项目结构的可视化概览
- 为高级主题链接到更深入的文档
- 保持根README聚焦于入门指南
2. 架构文档
创建时机: 包含多个模块、复杂数据流或非显而易见设计决策的项目。
遵循结构:
markdown
架构概述
系统设计
[高层级图表和说明]
目录结构
[每个目录用途的详细分解]
数据流
[数据如何在系统中流转]
关键设计决策
[为什么做出某些架构选择]
模块依赖关系
[不同部分如何交互]
扩展点
[在何处以及如何添加新功能]
最佳实践:
- - 使用图表展示系统组件及其关系
- 解释架构决策背后的为什么
- 同时记录正常路径和错误处理
- 明确模块之间的边界
- 包含带注释的可视化文件树结构
3. 代码注释
创建时机: 复杂逻辑、非显而易见的算法或需要上下文的代码。
注释模式:
函数/方法文档:
javascript
/
* 计算部分计费周期的按比例订阅费用。
*
* 为什么存在:用户可能在月中订阅,因此我们只需
* 收取当前计费周期剩余天数的费用。
*
* @param {number} fullPrice - 正常月度订阅价格
* @param {Date} startDate - 用户订阅开始日期
* @param {Date} periodEnd - 当前计费周期结束日期
* @returns {number} 按比例计算的收费金额
*
* @example
* // 用户在1月15日订阅,周期在1月31日结束
* calculateProratedCost(30, new Date(2024-01-15), new Date(2024-01-31))
* // 返回:16.13(31天中的17天)
*/
复杂逻辑文档:
python
为什么存在此检查:API对已删除用户返回null,
但对从未设置名称的用户返回空字符串。我们需要
区分这两种情况以用于审计日志。
if user_name is None:
# 用户已被删除 - 将此记录为安全事件
log
deletionevent(user_id)
elif user_name == :
# 用户从未完成入门流程 - 安全跳过
continue
最佳实践:
- - 解释为什么而非是什么——代码本身已显示其功能
- 记录边界情况和业务逻辑
- 为复杂函数添加示例
- 解释非自解释的参数
- 注明任何陷阱或反直觉行为
4. API文档
创建时机: 任何HTTP端点、SDK方法或公共接口。
遵循结构:
markdown
端点名称
功能说明
[端点用途的通俗解释]
端点
POST /api/v1/resource
身份验证
[需要什么认证以及如何提供]
请求格式
[JSON模式或示例请求]
响应格式
[JSON模式或示例响应]
使用示例
[包含curl/代码的具体示例]
常见错误
[错误代码及其含义]
相关端点
[相关操作的链接]
最佳实践:
- - 提供可用的curl示例
- 同时展示成功和错误响应
- 清晰说明身份验证
- 记录速率限制和约束
- 包含常见问题的故障排除
文档工作流程
第一步:分析代码库
在编写文档之前:
- 1. 识别入口点 - 主文件、索引文件、应用初始化
- 映射依赖关系 - 模块之间的关联方式
- 找到核心概念 - 用户需要理解的关键抽象
- 定位配置 - 环境设置、配置文件
- 审查现有文档 - 在此基础上构建,不重复
第二步:选择文档类型
根据用户请求和代码库分析:
- - 新项目或缺少README → 从README文档开始
- 复杂架构或多个模块 → 创建架构文档
- 令人困惑的代码段 → 添加内联代码注释
- HTTP/API端点 → 编写API文档
- 需要多种类型 → 按顺序处理:README → 架构 → API → 注释
第三步:生成文档
使用assets/templates/中的模板作为起点:
- - assets/templates/README.template.md - 用于项目README
- assets/templates/ARCHITECTURE.template.md - 用于架构文档
- assets/templates/API.template.md - 用于API文档
根据具体代码库自定义模板:
- 1. 填写项目特定信息 - 用实际内容替换占位符
- 添加具体示例 - 使用项目中的真实代码
- 包含视觉辅助 - 创建文件树、图表、流程图
- 测试说明 - 验证设置步骤是否实际可用
- 链接相关文档 - 将文档各部分连接起来
第四步:审查清晰度
在最终确定文档之前:
- 1. 以初学者视角阅读 - 没有项目上下文是否也能理解?
- 检查完整性 - 解释中是否存在空白?
- 验证示例 - 代码示例是否实际可用?
- 测试说明 - 他人能否按照设置步骤操作?
- 改进结构 - 信息是否易于查找?
文档模板
该技能在assets/templates/中包含多个模板,提供起始结构:
可用模板
- - README.template.md - 包含快速开始、项目结构和常见任务部分的全面README结构
- ARCHITECTURE.template.md - 包含系统设计、数据流和设计决策的架构文档模板
- API.template.md - 包含请求/响应格式和示例的API端点文档
- CODE_COMMENTS.template.md - 有效内联文档的示例和模式
使用模板
- 1. 从assets/templates/阅读相应的模板
- 针对特定项目进行自定义 - 用实际信息替换占位符
- 添加项目特定部分 - 根据需要扩展模板
- 包含真实示例 - 使用代码库中的实际代码
- 删除不相关的部分 - 移除不适用的内容
最佳实践参考
有关详细的文档最佳实践、样式指南和高级模式,请参考:
- - references/documentationguidelines.md - 全面的样式指南和最佳实践
- references/visualaids_guide.md - 如何创建有效的图表和文件树
在以下情况下加载这些参考:
- - 为复杂的企业级代码库创建文档
- 处理多个利益相关者的需求
- 需要高级文档模式
- 在大型项目中标准化文档
常见模式
创建文件树结构
文件树帮助新用户理解项目组织:
project-root/
├── src/ # 源代码
│ ├── components/ # 可复用的UI组件
│ ├── pages/ # 页面级组件(路由)
│ ├── services/ # 业务逻辑和API调用
│ ├── utils/ # 辅助函数
│ └── types/ # TypeScript类型定义
├── public/ # 静态资源(图片、字体)
├── tests/ # 镜像src结构的测试文件
└── package.json # 依赖和脚本
解释复杂数据流
使用带图表的编号步骤: