analyze-code-structure
Examine code organization and identify structural patterns. Use when reviewing module design or understanding architecture.
When & Why to Use This Skill
The Analyze Code Structure skill empowers developers to systematically examine code organization, map complex dependencies, and identify architectural patterns. By automating the discovery of classes, functions, and module relationships, it simplifies the process of understanding complex software architectures and ensures structural integrity throughout the development lifecycle.
Use Cases
- Pre-implementation Review: Evaluating module design and planned interfaces to ensure alignment with architectural standards before writing production code.
- Legacy Code Onboarding: Rapidly mapping out how components connect and interact within an unfamiliar or large-scale codebase to reduce ramp-up time.
- Refactoring Strategy: Identifying structural bottlenecks, tight coupling, or violations of separation of concerns to plan effective and safe refactoring paths.
- Architectural Documentation: Generating structured reports that inventory components and visualize dependency graphs for better team alignment and system maintenance.
| name | analyze-code-structure |
|---|---|
| description | "Examine code organization and identify structural patterns. Use when reviewing module design or understanding architecture." |
| mcp_fallback | none |
| category | analysis |
| tier | 2 |
| user-invocable | false |
Analyze Code Structure
Examine code organization, dependencies, and architectural patterns to understand how modules are organized.
When to Use
- Reviewing module design before implementation
- Understanding how components connect
- Identifying structural improvements needed
- Planning refactoring strategies
Quick Reference
# Analyze Python file structure
python3 << 'EOF'
import ast
import sys
def analyze_structure(filepath):
with open(filepath) as f:
tree = ast.parse(f.read())
classes = [n.name for n in ast.walk(tree) if isinstance(n, ast.ClassDef)]
functions = [n.name for n in ast.walk(tree) if isinstance(n, ast.FunctionDef)]
print(f"Classes: {classes}")
print(f"Functions: {functions}")
analyze_structure(sys.argv[1])
EOF
Workflow
- Identify module components: List classes, functions, and major imports
- Map dependencies: Trace how modules import and reference each other
- Analyze layers: Categorize code into logical layers (interface, business logic, persistence)
- Document patterns: Note recurring architectural patterns (factory, singleton, observer)
- Propose improvements: Identify coupling issues or missing separation of concerns
Output Format
Structured analysis report:
- Component inventory (classes, functions, data structures)
- Dependency graph (which modules import which)
- Layer organization (presentation, business, data)
- Design patterns identified
- Recommendations for improvement
References
- See CLAUDE.md > Modularity section for design principles
- See
identify-architectureskill for full architecture analysis - See CLAUDE.md > SOLID principles for structural best practices