Use when adding new error messages to React, or seeing "unknown error code" warnings.
npx skills add TheSimpleApp/agent-skills --skill "codebase-analysis"
Install specific skill from multi-skill repository
# Description
Deep dive analysis of any codebase. Maps architecture, identifies patterns, finds issues, and generates comprehensive reports. Use before major refactoring or when onboarding to unfamiliar code.
# SKILL.md
name: codebase-analysis
description: Deep dive analysis of any codebase. Maps architecture, identifies patterns, finds issues, and generates comprehensive reports. Use before major refactoring or when onboarding to unfamiliar code.
license: MIT
metadata:
author: thesimpleapp
version: "1.0"
Codebase Analysis
Systematic deep-dive into any codebase to understand architecture, patterns, and issues.
Analysis Framework
1. SURVEY β High-level structure scan
2. TRACE β Follow key flows through code
3. IDENTIFY β Find patterns and anti-patterns
4. MEASURE β Quantify code quality metrics
5. REPORT β Generate actionable findings
Phase 1: Survey
Structure Scan
Analyze:
- Root files (config, entry points)
- Folder organization
- Key directories
- Dependency graph
Questions to Answer
β‘ What's the entry point?
β‘ How is code organized?
β‘ What are the main modules/features?
β‘ What external dependencies?
β‘ What build/deploy configuration?
Phase 2: Trace Key Flows
Pick 3-5 critical user flows and trace them:
Flow Tracing Template
## Flow: User Login
### Entry Point
- File: src/features/auth/LoginScreen.tsx
- Trigger: User clicks "Sign In"
### Data Flow
1. UI captures credentials
2. β AuthService.login()
3. β Supabase client call
4. β Token stored in state
5. β Redirect to dashboard
### Components Touched
- LoginScreen (UI)
- AuthService (logic)
- useAuth hook (state)
- supabaseClient (external)
### Observations
- Good: Separation of concerns
- Issue: No error handling on line 45
- Issue: Hardcoded redirect path
Phase 3: Pattern Identification
Positive Patterns to Note
β Repository pattern
β Dependency injection
β Consistent naming
β Type safety
β Error boundaries
β Loading states
β Test coverage
Anti-Patterns to Flag
β God components (>300 lines)
β Prop drilling (>3 levels)
β Direct API calls in UI
β Inconsistent state management
β Missing error handling
β Hardcoded values
β Dead code
β Circular dependencies
β Mixed responsibilities
Pattern Detection Queries
# Find large files (potential god objects)
find . -name "*.ts" -o -name "*.dart" | xargs wc -l | sort -n | tail -20
# Find TODO/FIXME comments
grep -r "TODO\|FIXME\|HACK\|XXX" --include="*.ts" --include="*.dart"
# Find console.log (should be cleaned)
grep -r "console.log\|print(" --include="*.ts" --include="*.dart"
# Find hardcoded strings
grep -r "http://\|https://" --include="*.ts" --include="*.dart"
Phase 4: Metrics
Code Quality Metrics
| Metric | Good | Warning | Critical |
|---|---|---|---|
| File lines | <200 | 200-400 | >400 |
| Function lines | <30 | 30-50 | >50 |
| Cyclomatic complexity | <10 | 10-20 | >20 |
| Test coverage | >80% | 50-80% | <50% |
| Dependencies | Current | <6mo old | >1yr old |
Generate Metrics Report
## Code Metrics
### File Size Distribution
- Small (<100 lines): 45 files
- Medium (100-300 lines): 23 files
- Large (>300 lines): 7 files β οΈ
### Largest Files (Need Review)
1. UserDashboard.tsx (523 lines) β
2. ApiClient.ts (412 lines) β οΈ
3. utils.ts (389 lines) β οΈ
### Dependency Health
- Total: 47 packages
- Outdated: 12 β οΈ
- Vulnerable: 2 β
Phase 5: Report Generation
Analysis Report Template
# Codebase Analysis Report
**Project**: [name]
**Date**: [date]
**Analyst**: Claude + Human
## Executive Summary
[2-3 sentence overview]
## Architecture Overview
[Diagram or description]
## Strengths
1. [Positive finding]
2. [Positive finding]
3. [Positive finding]
## Critical Issues (Fix Immediately)
1. **[Issue]**: [location] - [impact]
2. **[Issue]**: [location] - [impact]
## Improvement Opportunities
1. [Improvement] - Priority: High/Medium/Low
2. [Improvement] - Priority: High/Medium/Low
## Technical Debt Inventory
| Item | Location | Effort | Impact |
|------|----------|--------|--------|
| [debt] | [file] | [hours] | [risk] |
## Recommendations
### Quick Wins (< 1 day)
- [action]
### Short Term (1 week)
- [action]
### Long Term (1 month+)
- [action]
## Next Steps
1. Review this report with team
2. Prioritize issues
3. Run /architecture-cleanup for fixes
Integration with Other Skills
After analysis:
- Use /architecture-cleanup to fix issues
- Use /sprint-planning to plan improvements
- Use framework-specific skills for implementation
Output Artifacts
This skill produces:
- ANALYSIS_REPORT.md - Full findings
- ARCHITECTURE.md - Architecture documentation
- TECH_DEBT.md - Technical debt inventory
- List of files needing attention
# Supported AI Coding Agents
This skill is compatible with the SKILL.md standard and works with all major AI coding agents:
Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.