explain-complex-code
Skill1 starsChanged 48 days agoMITView on GitHub
Generate comprehensive architecture documentation for complex code modules with Mermaid diagrams and examples. Use when user asks to "explain this code", "document the architecture", or wants to understand how a module/system works.
In this repository26 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- agent-lintSkill
- skill-lintSkill
- add-ruleSkill
- bdk-implementer-return-contractSkill
- bdk-lint-toolsSkill
- bdk-rules-architectureSkill
- bdk-rules-code-qualitySkill
- bdk-rules-design-patternsSkill
- bdk-rules-languagesSkill
- bdk-rules-securitySkill
- bdk-test-toolsSkill
- commitSkill
- create-adrSkill
- create-planSkill
- crSkill
- debugSkill
- designSkill
- mermaid-drawerSkill
- pr-reviewSkill
- refine-rulesSkill
- setupSkill
- subagent-execute-planSkill
- test-driven-developmentSkill
- update-docsSkill
- verify-planSkill
The file
We split this skill into the rules it gives an agent
1 rule. About 0 are common, 1 is distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 130
Prototype code mandatory: Never copy actual implementation
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Explain Complex Code
Relies on BDK foundation (STARTUP_INSTRUCTIONS.md) for project context.
Generate architecture docs for complex code with visual diagrams and examples.
Workflow
1. Understand Scope
path arg specifies code to explain. Clarify:
- Focus areas: Architecture, algorithms, data flow, testing strategy
- Audience level: Team onboarding, external docs, debugging guide
2. Analyze Code Structure
Step 2.1: Initial Discovery
Find all symbols in the area and identify the high-dependency ones (most importers).
Step 2.2: Map Dependencies For each key class/function: find its callers across the source tree, and read its body for the callees it uses.
Step 2.3: Decide Partitioning Strategy
Partition by file count, keeping each directory that forms one logical block together:
| Files Count | Strategy | Subagent Count |
| 1-2 files | One subagent for entire module | 1 subagent |
| 3-5 files | Group into 1-2 logical blocks | 1-2 subagents |
| 6-10 files | Group into 2-3 logical blocks | 2-3 subagents |
| 10+ files | Group by architectural layers | 3-4 subagents |
Never more than 3-4 subagents.
3. Launch Subagents Strategically
Launch ALL subagents in ONE message. Per subagent:
Explore the following files as a logical block: [FILE_LIST]
For EACH file, report:
1. Core responsibilities and purpose
2. Key classes/functions and their roles
3. Important dependencies
4. Critical algorithms or rules
5. Data structures
6. Edge cases or special handling
Then synthesize:
7. How these files work together
8. Data flow between them
9. Shared dependencies or patterns4. Synthesize Documentation
From subagent findings, create structured docs.
Structure:
- Overview: 2-3 sentence summary
- Core Architecture: File tree + component diagram
- Architecture Flow: Process flow with Mermaid
- Critical Rules: Non-obvious rules with examples
- Live Examples: Prototype code (NOT actual implementation)
- Core Classes: Key classes with usage patterns
- Testing Coverage: Existing test structure and patterns
5. Create Mermaid Diagrams
Embed diagrams directly as fenced mermaid code blocks — no separate source file, no compile step, renders natively wherever the doc is viewed.
Follow /bdk:mermaid-drawer for type selection, node budget and colour. It is the shared standard across every BDK skill that emits a diagram, so docs from different skills read alike. Architecture docs typically need a component flowchart with one subgraph per layer; add a sequenceDiagram when the module's behaviour is a call chain across boundaries, and a stateDiagram-v2 when it drives an entity through named states.
6. Write Prototype Examples
CRITICAL RULE: Prototype code only — NOT actual implementation.
Good Prototype:
# Parse and validate
parsed = parse(input_data)
if not parsed.is_valid:
return error_response()
# Transform based on type
result = transform(parsed)
return format_output(result)Prototype Rules:
- Placeholder function names
- Clear control flow
- Comments for key steps
- Under 20 lines per example
- One concept per example
7. Save Documentation
Save to .bdk/explain-complex-code/[feature-name].md.
Quality Checklist
- Overview (2-3 sentences)
- File tree
- At least one Mermaid diagram
- Critical rules with examples
- Live examples with prototype code
- Core classes with usage
- Testing coverage
Notes
- Prototype code mandatory: Never copy actual implementation
- Parallel subagents save time: Launch all in one message
- Focus non-obvious details: Skip basic patterns
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

