Research a codebase and produce an architectural document describing how features or systems work. The output is a markdown file organized for both human readers and future AI agents.
Understand what to document before exploring:
Explore the codebase broadly to build a mental model. Use lightweight, fast exploration methods when available (in Claude Code, for example, use a Haiku Explore subagent):
Present a high-level outline to the user:
## Proposed Outline
1. [Component A] - Brief description
2. [Component B] - Brief description
3. [Component C] - Brief description
* Have I correctly captured the scope of the research? Reply "yes" to continue.
* Otherwise, please let me know what I've misunderstood.
When the user confirms the scope, move on to deep research.
For each component in the approved outline:
Try to rely on the initial code exploration for much of this information. Read additional files as needed. If the scope changed considerably in Stage 2, you can engage a second code exploration subagent.
You're ready to draft when you can:
Signs you're not done:
Signs you've gone too far:
Generate the document following the template below. Present the draft to the user for review and iterate based on feedback. If available, use the AskUserQuestion tool to request user input on key decisions.
docs/architecture/, ARCHITECTURE.md), but NEVER write the file
without explicit user confirmation of the location. If the user provided a path upfront,
that counts as confirmation.The following template provides a starting point. Adapt it to fit the feature being documented — omit sections that don't apply, add sections for unique aspects, and adjust the structure to best serve the target audience.
# [Feature/System Name] Architecture
## Overview
[1-2 paragraph summary of what this feature/system does and why it exists]
## Architecture Diagram
```mermaid
flowchart TD
A[Entry Point] --> B[Component]
B --> C[Data Store]
Purpose: [What it does]
Location: path/to/file.ext
Key Functions:
functionName() - Brief descriptionanotherFunction() - Brief descriptionInteractions:
[Description of how data moves through the system, from input to output]
[How features are enabled, disabled, or configured. Include file paths and environment variables.]
| Component | File | Key Symbols |
|---|---|---|
| Auth | src/auth/index.ts |
authenticate(), AuthConfig |
| Cache | src/cache/redis.ts |
CacheManager, invalidate() |
更多技能请访问小葱技能站7w4.net。
| Term | Definition |
|---|---|
| [Term] | [Project-specific definition] |
## Code Reference Conventions
Use stable references that survive refactoring:
- **Paths**: Use relative paths from repository root (`src/auth/login.ts`)
- **Symbols**: Reference function and class names, not line numbers
- **Format**: `path/to/file.ext` with key symbols listed separately
- **Anchors**: Use search patterns when helpful (`handleAuth function in auth/`)
Avoid:
- **Copying code**: Never paste code into the document. Code goes stale immediately;
the document should be a guide that points readers to the source. Describe what
code does, then reference where to find it.
- **Line numbers**: They change with every edit.
- **Absolute paths**: Use repository-relative paths only.
## Mermaid Diagrams
Use Mermaid for architecture visualizations:
**Flowcharts** for component relationships:
```mermaid
flowchart TD
A[Client] --> B[API Gateway]
B --> C[Service]
C --> D[(Database)]
Sequence diagrams for request flows:
sequenceDiagram
Client->>API: Request
API->>Service: Process
Service-->>API: Response
API-->>Client: Result
Keep diagrams focused on the specific feature being documented. Avoid overcrowding with unrelated components.
这个工具质量中等偏上,能帮助把复杂的代码结构转化为清晰易懂的架构文档,输出的格式规范且配有图表。主要优点是流程清晰、模板实用;不足之处是缺少示例和详细指引,新手需要自己摸索,且对复杂项目或需求不明确的情况支持不足。总体适合有一定经验的开发者使用,但入门门槛略高。