Codebase Analysis Skill
Objective
Perform comprehensive, systematic analysis of project codebases to understand:
- Project structure and organization
- Technology stack and dependencies
- Architectural patterns and conventions
- Code complexity and quality metrics
- Key components and their relationships
When to Use This Skill
Auto-invoke when:
- Starting work on a new project
- User asks to "analyze", "review", "audit", or "understand" the codebase
- Before making architectural decisions
- Planning refactoring or major changes
- Onboarding new developers
Analysis Methodology
Phase 1: Discovery (Project Structure)
Goal: Map the high-level project organization
Tools: Glob, LS, Read
Process:
- Identify project type by reading
package.json, tsconfig.json, or framework-specific configs
- Map directory structure using LS at root level:
Key directories to identify:
- Source code: src/, app/, pages/, components/
- Tests: __tests__/, tests/, *.test.*, *.spec.*
- Config: config/, .config/
- Documentation: docs/, README.md
- Build output: dist/, build/, .next/
- Scan for important files:
- Build configs:
vite.config.*, webpack.config.*, next.config.*
- TypeScript:
tsconfig.json, tsconfig.*.json
- Package management:
package.json, package-lock.json, yarn.lock, pnpm-lock.yaml
- Environment:
.env*, .env.example
- Git:
.gitignore, .git/
Phase 2: Technology Stack Analysis
Goal: Identify frameworks, libraries, and versions
Tools: Read, Grep
Process:
Read package.json:
- Extract
dependencies (runtime libraries)
- Extract
devDependencies (development tools)
- Note
scripts (available commands)
- Check
engines (Node.js version requirements)
Identify framework:
- Next.js: Check for
next in dependencies, next.config.*, app/ or pages/ directory
- React: Check for
react and react-dom
- Vue: Check for
vue, *.vue files
- Svelte: Check for
svelte, *.svelte files
- Angular: Check for
@angular/core, angular.json
Identify key libraries:
- State management: Redux, Zustand, MobX, Pinia
- Routing: react-router, vue-router, next/navigation
- UI libraries: MUI, Ant Design, shadcn/ui, Chakra UI
- Styling: Tailwind CSS, styled-components, emotion, CSS modules
- Testing: Vitest, Jest, Playwright, Cypress
- Build tools: Vite, Webpack, esbuild, Turbopack
Phase 3: Architecture Pattern Analysis
Goal: Understand code organization and patterns
Tools: Grep, Glob, Read
Process:
Component patterns (for React/Vue/Svelte):
Use Glob to find: **/*.{jsx,tsx,vue,svelte}
Analyze:
- Component naming conventions
- File structure (co-located styles, tests)
- Component size (lines of code)
API/Backend patterns:
Use Grep to search for:
- API routes: "export.*GET|POST|PUT|DELETE"
- Database queries: "prisma\.|mongoose\.|sql"
- Authentication: "auth|jwt|session"
State management patterns:
Use Grep to find:
- Context API: "createContext|useContext"
- Redux: "createSlice|useSelector"
- Zustand: "create.*useStore"
File organization patterns:
- Monorepo: Check for
packages/, apps/, turbo.json, nx.json
- Feature-based: Check for directories like
features/, modules/
- Layer-based: Check for
components/, services/, utils/, hooks/
Phase 4: Code Quality & Complexity Assessment
Goal: Identify potential issues and technical debt
Tools: Grep, Bash, Read
Process:
Linting & Formatting:
- Check for:
.eslintrc*, .prettierrc*, biome.json
- Run linter if available:
npm run lint (via Bash)
Testing coverage:
- Find test files: Use Glob for
**/*.{test,spec}.{js,ts,jsx,tsx}
- Calculate coverage: Run
npm run test:coverage if available
TypeScript strictness:
- Read
tsconfig.json
- Check
strict: true, strictNullChecks, etc.
- Look for
@ts-ignore or any usage (Grep)
Code complexity indicators:
Use Grep to flag potential issues:
- Large files: Find files > 500 lines
- Deep nesting: Search for excessive indentation
- TODO/FIXME comments: Grep for "TODO|FIXME|HACK"
- Console logs: Grep for "console\.(log|debug|warn)"
Phase 5: Dependency & Security Analysis
Goal: Identify outdated or vulnerable dependencies
Tools: Bash, Read
Process:
Check for lock files:
- Presence of
package-lock.json, yarn.lock, pnpm-lock.yaml
Run security audit (if npm/pnpm available):
npm audit --json
# or
pnpm audit --json
Check for outdated dependencies:
npm outdated
Output Format
Provide a structured analysis report:
# Codebase Analysis Report
## Project Overview
- **Name**: [project name from package.json]
- **Type**: [framework/library]
- **Version**: [version]
- **Node.js**: [required version]
## Technology Stack
### Core Framework
- [Framework name & version]
### Key Dependencies
- UI: [library]
- State: [library]
- Routing: [library]
- Styling: [library]
- Testing: [library]
### Build Tools
- [Vite/Webpack/etc]
## Architecture
### Directory Structure
[tree-like representation of key directories]
### Patterns Identified
- [Component patterns]
- [State management approach]
- [API structure]
- [File organization]
## Code Quality Metrics
- **TypeScript**: [strict/loose/none]
- **Linting**: [ESLint/Biome/none]
- **Testing**: [X test files found, coverage: Y%]
- **Code Issues**: [TODOs: X, Console logs: Y]
## Recommendations
1. [Priority recommendation]
2. [Next priority]
3. ...
## Risk Areas
- [Potential issues or technical debt]
## Next Steps
- [Suggested actions based on analysis]
Best Practices
- Progressive Detail: Start with high-level overview, dive deeper only when needed
- Context Window Management: For large codebases, analyze in chunks (by directory/feature)
- Tool Selection:
- Use Glob for file discovery (faster than find)
- Use Grep for pattern search (faster than reading all files)
- Use Read only for critical files (package.json, configs)
- Time Efficiency: Complete analysis in < 60 seconds for typical projects
- Actionable Insights: Always provide specific, actionable recommendations
Integration with Other Skills
This skill works well with:
quality-gates - Use analysis results to run appropriate quality checks
project-initialization - Compare against templates to identify missing setup
refactoring-safe - Identify refactoring opportunities
- Framework-specific skills (
nextjs-optimization, react-patterns) - Auto-invoke based on detected framework
Error Handling
If analysis cannot complete:
- Missing dependencies: Suggest running
npm install
- Corrupted files: Report specific files and continue with partial analysis
- Large codebase: Switch to targeted analysis mode (specific directories only)
- Permission issues: Request necessary file access permissions
Version History
- 1.0.0 (2025-01-03): Initial skill creation with progressive disclosure support
1---2name: codebase-analysis3description: Systematically analyze codebase structure, complexity, dependencies, and architectural patterns to understand project organization4---56# Codebase Analysis Skill78## Objective910Perform comprehensive, systematic analysis of project codebases to understand:11- Project structure and organization12- Technology stack and dependencies13- Architectural patterns and conventions14- Code complexity and quality metrics15- Key components and their relationships1617## When to Use This Skill1819Auto-invoke when:20- Starting work on a new project21- User asks to "analyze", "review", "audit", or "understand" the codebase22- Before making architectural decisions23- Planning refactoring or major changes24- Onboarding new developers2526## Analysis Methodology2728### Phase 1: Discovery (Project Structure)2930**Goal**: Map the high-level project organization3132**Tools**: Glob, LS, Read3334**Process**:351. **Identify project type** by reading `package.json`, `tsconfig.json`, or framework-specific configs362. **Map directory structure** using LS at root level:37 ```38 Key directories to identify:39 - Source code: src/, app/, pages/, components/40 - Tests: __tests__/, tests/, *.test.*, *.spec.*41 - Config: config/, .config/42 - Documentation: docs/, README.md43 - Build output: dist/, build/, .next/44 ```453. **Scan for important files**:46 - Build configs: `vite.config.*, webpack.config.*, next.config.*`47 - TypeScript: `tsconfig.json`, `tsconfig.*.json`48 - Package management: `package.json`, `package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`49 - Environment: `.env*`, `.env.example`50 - Git: `.gitignore`, `.git/`5152### Phase 2: Technology Stack Analysis5354**Goal**: Identify frameworks, libraries, and versions5556**Tools**: Read, Grep5758**Process**:591. **Read package.json**:60 - Extract `dependencies` (runtime libraries)61 - Extract `devDependencies` (development tools)62 - Note `scripts` (available commands)63 - Check `engines` (Node.js version requirements)64652. **Identify framework**:66 - Next.js: Check for `next` in dependencies, `next.config.*`, `app/` or `pages/` directory67 - React: Check for `react` and `react-dom`68 - Vue: Check for `vue`, `*.vue` files69 - Svelte: Check for `svelte`, `*.svelte` files70 - Angular: Check for `@angular/core`, `angular.json`71723. **Identify key libraries**:73 - State management: Redux, Zustand, MobX, Pinia74 - Routing: react-router, vue-router, next/navigation75 - UI libraries: MUI, Ant Design, shadcn/ui, Chakra UI76 - Styling: Tailwind CSS, styled-components, emotion, CSS modules77 - Testing: Vitest, Jest, Playwright, Cypress78 - Build tools: Vite, Webpack, esbuild, Turbopack7980### Phase 3: Architecture Pattern Analysis8182**Goal**: Understand code organization and patterns8384**Tools**: Grep, Glob, Read8586**Process**:871. **Component patterns** (for React/Vue/Svelte):88 ```89 Use Glob to find: **/*.{jsx,tsx,vue,svelte}90 Analyze:91 - Component naming conventions92 - File structure (co-located styles, tests)93 - Component size (lines of code)94 ```95962. **API/Backend patterns**:97 ```98 Use Grep to search for:99 - API routes: "export.*GET|POST|PUT|DELETE"100 - Database queries: "prisma\.|mongoose\.|sql"101 - Authentication: "auth|jwt|session"102 ```1031043. **State management patterns**:105 ```106 Use Grep to find:107 - Context API: "createContext|useContext"108 - Redux: "createSlice|useSelector"109 - Zustand: "create.*useStore"110 ```1111124. **File organization patterns**:113 - Monorepo: Check for `packages/`, `apps/`, `turbo.json`, `nx.json`114 - Feature-based: Check for directories like `features/`, `modules/`115 - Layer-based: Check for `components/`, `services/`, `utils/`, `hooks/`116117### Phase 4: Code Quality & Complexity Assessment118119**Goal**: Identify potential issues and technical debt120121**Tools**: Grep, Bash, Read122123**Process**:1241. **Linting & Formatting**:125 - Check for: `.eslintrc*`, `.prettierrc*`, `biome.json`126 - Run linter if available: `npm run lint` (via Bash)1271282. **Testing coverage**:129 - Find test files: Use Glob for `**/*.{test,spec}.{js,ts,jsx,tsx}`130 - Calculate coverage: Run `npm run test:coverage` if available1311323. **TypeScript strictness**:133 - Read `tsconfig.json`134 - Check `strict: true`, `strictNullChecks`, etc.135 - Look for `@ts-ignore` or `any` usage (Grep)1361374. **Code complexity indicators**:138 ```139 Use Grep to flag potential issues:140 - Large files: Find files > 500 lines141 - Deep nesting: Search for excessive indentation142 - TODO/FIXME comments: Grep for "TODO|FIXME|HACK"143 - Console logs: Grep for "console\.(log|debug|warn)"144 ```145146### Phase 5: Dependency & Security Analysis147148**Goal**: Identify outdated or vulnerable dependencies149150**Tools**: Bash, Read151152**Process**:1531. **Check for lock files**:154 - Presence of `package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`1551562. **Run security audit** (if npm/pnpm available):157 ```bash158 npm audit --json159 # or160 pnpm audit --json161 ```1621633. **Check for outdated dependencies**:164 ```bash165 npm outdated166 ```167168## Output Format169170Provide a structured analysis report:171172```markdown173# Codebase Analysis Report174175## Project Overview176- **Name**: [project name from package.json]177- **Type**: [framework/library]178- **Version**: [version]179- **Node.js**: [required version]180181## Technology Stack182### Core Framework183- [Framework name & version]184185### Key Dependencies186- UI: [library]187- State: [library]188- Routing: [library]189- Styling: [library]190- Testing: [library]191192### Build Tools193- [Vite/Webpack/etc]194195## Architecture196197### Directory Structure198```199[tree-like representation of key directories]200```201202### Patterns Identified203- [Component patterns]204- [State management approach]205- [API structure]206- [File organization]207208## Code Quality Metrics209- **TypeScript**: [strict/loose/none]210- **Linting**: [ESLint/Biome/none]211- **Testing**: [X test files found, coverage: Y%]212- **Code Issues**: [TODOs: X, Console logs: Y]213214## Recommendations2151. [Priority recommendation]2162. [Next priority]2173. ...218219## Risk Areas220- [Potential issues or technical debt]221222## Next Steps223- [Suggested actions based on analysis]224```225226## Best Practices2272281. **Progressive Detail**: Start with high-level overview, dive deeper only when needed2292. **Context Window Management**: For large codebases, analyze in chunks (by directory/feature)2303. **Tool Selection**: 231 - Use Glob for file discovery (faster than find)232 - Use Grep for pattern search (faster than reading all files)233 - Use Read only for critical files (package.json, configs)2344. **Time Efficiency**: Complete analysis in < 60 seconds for typical projects2355. **Actionable Insights**: Always provide specific, actionable recommendations236237## Integration with Other Skills238239This skill works well with:240- `quality-gates` - Use analysis results to run appropriate quality checks241- `project-initialization` - Compare against templates to identify missing setup242- `refactoring-safe` - Identify refactoring opportunities243- Framework-specific skills (`nextjs-optimization`, `react-patterns`) - Auto-invoke based on detected framework244245## Error Handling246247If analysis cannot complete:2481. **Missing dependencies**: Suggest running `npm install`2492. **Corrupted files**: Report specific files and continue with partial analysis2503. **Large codebase**: Switch to targeted analysis mode (specific directories only)2514. **Permission issues**: Request necessary file access permissions252253## Version History254255- **1.0.0** (2025-01-03): Initial skill creation with progressive disclosure support