tech-docs-generator
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseTechnical Documentation Generator
技术文档生成器
Overview
概述
Generate comprehensive technical documentation by analyzing the actual codebase. Produces API references, architecture overviews, getting started guides, and component documentation with real examples extracted from project code, not invented ones.
Announce at start: "I'm using the tech-docs-generator skill to create documentation."
通过分析实际代码库生成全面的技术文档。可生成API参考、架构概览、入门指南和组件文档,所有示例均提取自项目代码,而非虚构内容。
开始时请声明:"I'm using the tech-docs-generator skill to create documentation."
Phase 1: Codebase Analysis
阶段1:代码库分析
Scan the codebase to identify what needs documenting. Deploy parallel subagents via the tool (up to 500, with ) to analyze:
Agentsubagent_type="Explore"| Analysis Target | What to Capture |
|---|---|
| Exported functions/classes | Public API surface, signatures, return types |
| API routes/endpoints | REST, GraphQL, tRPC definitions with methods |
| Configuration | Env vars, config files, feature flags |
| Database schemas | Models, migrations, relationships |
| Component hierarchy | UI components and their props/interfaces |
| Type definitions | Interfaces, types, Zod schemas, enums |
| Entry points | CLI commands, main files, server bootstrap |
| Dependencies | External packages and their roles |
STOP after analysis — present a summary of what was found and ask which documentation types are needed.
扫描代码库以确定需要记录的内容。通过工具部署并行子Agent(最多500个,)来分析以下内容:
Agentsubagent_type="Explore"| 分析目标 | 要采集的内容 |
|---|---|
| 导出的函数/类 | 公共API层、签名、返回类型 |
| API路由/端点 | REST、GraphQL、tRPC定义及请求方法 |
| 配置 | 环境变量、配置文件、功能开关 |
| 数据库 schema | 模型、迁移文件、关联关系 |
| 组件层级 | UI组件及其属性/接口 |
| 类型定义 | 接口、类型、Zod schemas、枚举 |
| 入口点 | CLI命令、主文件、服务启动文件 |
| 依赖 | 外部包及其作用 |
分析完成后停止,展示发现的内容摘要并询问需要生成哪些类型的文档。
Phase 2: Documentation Type Selection
阶段2:文档类型选择
| Type | When to Use | Output Path | Typical Size |
|---|---|---|---|
| API Reference | Documenting endpoints or public functions | | 200-1000 lines |
| Architecture Overview | Explaining system design and data flow | | 100-300 lines |
| Getting Started | Onboarding new developers | | 50-150 lines |
| Component Docs | Documenting UI components | | 50-200 lines |
| Contributing Guide | Explaining how to contribute | | 50-100 lines |
| Configuration Guide | Documenting config options | | 50-200 lines |
| Migration Guide | Documenting version upgrades | | 50-150 lines |
Ask the user which type(s) they need if not specified. If multiple types are requested, dispatch parallel subagents via the tool — one per doc type.
Agent| 类型 | 适用场景 | 输出路径 | 典型长度 |
|---|---|---|---|
| API参考 | 记录端点或公共函数 | | 200-1000行 |
| 架构概览 | 解释系统设计和数据流 | | 100-300行 |
| 入门指南 | 供新开发者上手使用 | | 50-150行 |
| 组件文档 | 记录UI组件 | | 50-200行 |
| 贡献指南 | 说明如何参与贡献 | | 50-100行 |
| 配置指南 | 记录配置选项 | | 50-200行 |
| 迁移指南 | 记录版本升级说明 | | 50-150行 |
如果未指定需要的文档类型,询问用户需要哪些。如果请求了多种类型,通过工具部署并行子Agent,每种文档类型对应一个子Agent。
AgentPhase 3: Generate Documentation
阶段3:生成文档
Dispatch agent with:
doc-generator- File analysis results from Phase 1
- Documentation type selected in Phase 2
- Existing documentation (to update, not replace)
- Project context from memory files
STOP after generation — present each section for review before saving.
部署 Agent并传入以下参数:
doc-generator- 阶段1的文件分析结果
- 阶段2选择的文档类型
- 现有文档(用于更新而非替换)
- 内存文件中的项目上下文
生成完成后停止,在保存前展示每个部分供审核。
Documentation Format Standards
文档格式标准
API Reference format:
markdown
undefinedAPI参考格式:
markdown
undefinedfunctionName(param1, param2)
functionName(param1, param2)functionName(param1, param2)
functionName(param1, param2)Description of what this function does.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
| param1 | | Yes | What it does |
| param2 | | No | Configuration options |
Returns:
Promise<Result>Example:
typescript
const result = await functionName('value', { option: true });Throws: if param1 is empty
ValidationError
**Architecture Overview format:**
```markdownDescription of what this function does.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
| param1 | | Yes | What it does |
| param2 | | No | Configuration options |
Returns:
Promise<Result>Example:
typescript
const result = await functionName('value', { option: true });Throws: if param1 is empty
ValidationError
**架构概览格式:**
```markdownSystem Architecture
System Architecture
Overview
Overview
[High-level description with ASCII diagram]
[High-level description with ASCII diagram]
Components
Components
| Component | Responsibility | Key Files |
|---|
| Component | Responsibility | Key Files |
|---|
Data Flow
Data Flow
[How data moves through the system — request lifecycle]
[How data moves through the system — request lifecycle]
Key Decisions
Key Decisions
| Decision | Rationale | Alternatives Considered |
|---|
**Getting Started format:**
```markdown| Decision | Rationale | Alternatives Considered |
|---|
**入门指南格式:**
```markdownPrerequisites
Prerequisites
[Required tools, versions, accounts]
[Required tools, versions, accounts]
Installation
Installation
[Step-by-step with copy-pasteable commands]
[Step-by-step with copy-pasteable commands]
Configuration
Configuration
[Required env vars and config]
[Required env vars and config]
First Run
First Run
[How to start the app and verify it works]
[How to start the app and verify it works]
Next Steps
Next Steps
[Links to deeper documentation]
undefined[Links to deeper documentation]
undefinedPhase 4: Review and Save
阶段4:审核与保存
Present documentation section by section:
- Ask after each section: "Does this accurately describe the code?"
- Cross-reference with actual code to verify accuracy
- Include real examples from the codebase — never invented ones
- After approval, save to directory
docs/ - Commit with message:
docs(<scope>): add/update <doc-type>
逐节展示文档:
- 每展示完一节询问:"Does this accurately describe the code?"
- 与实际代码交叉验证准确性
- 包含来自代码库的真实示例,绝对不能使用虚构内容
- 获得批准后,保存到目录
docs/ - 提交信息格式为:
docs(<scope>): add/update <doc-type>
Accuracy Verification Checklist
准确性验证检查清单
| Check | How to Verify |
|---|---|
| Function signatures match code | Read the source file |
| Examples actually work | Trace the code path |
| Config options are current | Check actual config files |
| Dependencies listed are installed | Check package.json / requirements |
| File paths referenced exist | Glob for the files |
| 检查项 | 验证方式 |
|---|---|
| 函数签名与代码匹配 | 阅读源文件 |
| 示例可正常运行 | 追踪代码路径 |
| 配置选项为最新版本 | 检查实际配置文件 |
| 列出的依赖已安装 | 检查package.json / requirements文件 |
| 引用的文件路径存在 | 搜索对应文件 |
Anti-Patterns / Common Mistakes
反模式/常见错误
| Mistake | Why It Is Wrong | What To Do Instead |
|---|---|---|
| Inventing code examples | Readers copy-paste and get errors | Extract real examples from the codebase |
| Documenting internal/private APIs | Creates coupling to implementation | Only document public/exported surface |
| Writing docs that duplicate source code | Goes stale immediately | Reference behavior, not implementation |
| Giant monolithic doc file | Hard to navigate and maintain | Split by concern (API, architecture, config) |
| Documenting aspirational behavior | Misleads users about current capabilities | Document what actually works today |
| Skipping the analysis phase | Miss important APIs or get signatures wrong | Always analyze code first |
| Not verifying examples compile/run | Broken docs worse than no docs | Test every code example |
| 错误 | 错误原因 | 正确做法 |
|---|---|---|
| 虚构代码示例 | 读者复制粘贴后会报错 | 从代码库中提取真实示例 |
| 记录内部/私有API | 会与实现产生耦合 | 仅记录公共/导出的接口 |
| 编写的文档与源代码重复 | 会很快过时 | 记录行为而非实现细节 |
| 庞大的单块文档文件 | 难以导航和维护 | 按用途拆分(API、架构、配置等) |
| 记录规划中的功能 | 会误导用户对当前能力的认知 | 仅记录当前实际可用的功能 |
| 跳过分析阶段 | 会遗漏重要API或签名错误 | 始终先分析代码 |
| 不验证示例是否可编译/运行 | 错误的文档比没有文档更糟 | 测试每个代码示例 |
Anti-Rationalization Guards
反合理化规则
- Do NOT generate documentation without first analyzing the actual code
- Do NOT invent examples — every code snippet must come from or be verified against the codebase
- Do NOT document private/internal APIs unless explicitly requested
- Do NOT skip the review phase — present each section for user verification
- Do NOT duplicate information already covered in other docs — reference instead
- 禁止在未分析实际代码的情况下生成文档
- 禁止虚构示例——每个代码片段必须来自代码库或经过代码库验证
- 禁止记录私有/内部API,除非明确要求
- 禁止跳过审核阶段——每个部分都要提交给用户验证
- 禁止重复其他文档中已涵盖的信息——改为引用对应内容
Integration Points
集成点
| Skill | Relationship |
|---|---|
| Upstream: PRD defines what needs documenting |
| Parallel: both analyze codebase; self-learning populates memory files used here |
| Upstream: API design specs inform API reference docs |
| Parallel: specs define behavior; docs explain usage |
| Upstream: reverse-engineered specs provide behavioral understanding |
| Downstream: reviewer checks if docs were updated alongside code changes |
| Skill | 关系 |
|---|---|
| 上游:PRD定义了需要记录的内容 |
| 并行:两者都分析代码库;self-learning会填充此处使用的内存文件 |
| 上游:API设计规范为API参考文档提供依据 |
| 并行:规范定义行为;文档解释使用方法 |
| 上游:逆向生成的规范可帮助理解行为 |
| 下游:审核者会检查代码变更时是否同步更新了文档 |
Verification Gate
验证关口
Before claiming documentation is complete:
- VERIFY all public APIs are documented with correct signatures
- VERIFY code examples actually work (not invented)
- VERIFY cross-references link to existing content
- VERIFY documentation matches current code state
- VERIFY the user has approved each section
- RUN any documented commands to confirm they work
在声明文档完成前:
- 验证所有公共API都已记录,且签名正确
- 验证代码示例确实可用(非虚构)
- 验证交叉引用链接指向现有内容
- 验证文档与当前代码状态匹配
- 验证用户已批准每个部分
- 运行所有记录的命令确认其可正常工作
Concrete Example: API Reference Entry
具体示例:API参考条目
Given this source code:
typescript
export async function createUser(data: CreateUserInput): Promise<User> {
// validates, hashes password, inserts into DB
}Generate this documentation:
markdown
undefined给定以下源代码:
typescript
export async function createUser(data: CreateUserInput): Promise<User> {
// validates, hashes password, inserts into DB
}生成对应文档:
markdown
undefinedcreateUser(data)
createUser(data)createUser(data)
createUser(data)Create a new user account with the provided details.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
| data | | Yes | User registration data |
CreateUserInput| Field | Type | Required | Constraints |
|---|---|---|---|
| Yes | Valid email format | |
| password | | Yes | Minimum 8 characters |
| name | | Yes | 1-100 characters |
Returns: — the created user object (password excluded)
Promise<User>Throws:
- — if input fails validation
ValidationError - — if email already exists
ConflictError
undefinedCreate a new user account with the provided details.
Parameters:
| Name | Type | Required | Description |
|---|---|---|---|
| data | | Yes | User registration data |
CreateUserInput| Field | Type | Required | Constraints |
|---|---|---|---|
| Yes | Valid email format | |
| password | | Yes | Minimum 8 characters |
| name | | Yes | 1-100 characters |
Returns: — the created user object (password excluded)
Promise<User>Throws:
- — if input fails validation
ValidationError - — if email already exists
ConflictError
undefinedSkill Type
Skill类型
Flexible — Adapt documentation depth and format to project needs while preserving the analyze-first principle and accuracy verification.
灵活——在遵守先分析原则和准确性验证的前提下,可根据项目需求调整文档深度和格式。