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 organization4version: 1.0.05author: AI-Vibe-Prompts6tags: [analysis, code-quality, architecture, dependencies]7auto_invoke: true8---910# Codebase Analysis Skill1112## Objective1314Perform comprehensive, systematic analysis of project codebases to understand:15- Project structure and organization16- Technology stack and dependencies17- Architectural patterns and conventions18- Code complexity and quality metrics19- Key components and their relationships2021## When to Use This Skill2223Auto-invoke when:24- Starting work on a new project25- User asks to "analyze", "review", "audit", or "understand" the codebase26- Before making architectural decisions27- Planning refactoring or major changes28- Onboarding new developers2930## Analysis Methodology3132### Phase 1: Discovery (Project Structure)3334**Goal**: Map the high-level project organization3536**Tools**: Glob, LS, Read3738**Process**:391. **Identify project type** by reading `package.json`, `tsconfig.json`, or framework-specific configs402. **Map directory structure** using LS at root level:41 ```42 Key directories to identify:43 - Source code: src/, app/, pages/, components/44 - Tests: __tests__/, tests/, *.test.*, *.spec.*45 - Config: config/, .config/46 - Documentation: docs/, README.md47 - Build output: dist/, build/, .next/48 ```493. **Scan for important files**:50 - Build configs: `vite.config.*, webpack.config.*, next.config.*`51 - TypeScript: `tsconfig.json`, `tsconfig.*.json`52 - Package management: `package.json`, `package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`53 - Environment: `.env*`, `.env.example`54 - Git: `.gitignore`, `.git/`5556### Phase 2: Technology Stack Analysis5758**Goal**: Identify frameworks, libraries, and versions5960**Tools**: Read, Grep6162**Process**:631. **Read package.json**:64 - Extract `dependencies` (runtime libraries)65 - Extract `devDependencies` (development tools)66 - Note `scripts` (available commands)67 - Check `engines` (Node.js version requirements)68692. **Identify framework**:70 - Next.js: Check for `next` in dependencies, `next.config.*`, `app/` or `pages/` directory71 - React: Check for `react` and `react-dom`72 - Vue: Check for `vue`, `*.vue` files73 - Svelte: Check for `svelte`, `*.svelte` files74 - Angular: Check for `@angular/core`, `angular.json`75763. **Identify key libraries**:77 - State management: Redux, Zustand, MobX, Pinia78 - Routing: react-router, vue-router, next/navigation79 - UI libraries: MUI, Ant Design, shadcn/ui, Chakra UI80 - Styling: Tailwind CSS, styled-components, emotion, CSS modules81 - Testing: Vitest, Jest, Playwright, Cypress82 - Build tools: Vite, Webpack, esbuild, Turbopack8384### Phase 3: Architecture Pattern Analysis8586**Goal**: Understand code organization and patterns8788**Tools**: Grep, Glob, Read8990**Process**:911. **Component patterns** (for React/Vue/Svelte):92 ```93 Use Glob to find: **/*.{jsx,tsx,vue,svelte}94 Analyze:95 - Component naming conventions96 - File structure (co-located styles, tests)97 - Component size (lines of code)98 ```991002. **API/Backend patterns**:101 ```102 Use Grep to search for:103 - API routes: "export.*GET|POST|PUT|DELETE"104 - Database queries: "prisma\.|mongoose\.|sql"105 - Authentication: "auth|jwt|session"106 ```1071083. **State management patterns**:109 ```110 Use Grep to find:111 - Context API: "createContext|useContext"112 - Redux: "createSlice|useSelector"113 - Zustand: "create.*useStore"114 ```1151164. **File organization patterns**:117 - Monorepo: Check for `packages/`, `apps/`, `turbo.json`, `nx.json`118 - Feature-based: Check for directories like `features/`, `modules/`119 - Layer-based: Check for `components/`, `services/`, `utils/`, `hooks/`120121### Phase 4: Code Quality & Complexity Assessment122123**Goal**: Identify potential issues and technical debt124125**Tools**: Grep, Bash, Read126127**Process**:1281. **Linting & Formatting**:129 - Check for: `.eslintrc*`, `.prettierrc*`, `biome.json`130 - Run linter if available: `npm run lint` (via Bash)1311322. **Testing coverage**:133 - Find test files: Use Glob for `**/*.{test,spec}.{js,ts,jsx,tsx}`134 - Calculate coverage: Run `npm run test:coverage` if available1351363. **TypeScript strictness**:137 - Read `tsconfig.json`138 - Check `strict: true`, `strictNullChecks`, etc.139 - Look for `@ts-ignore` or `any` usage (Grep)1401414. **Code complexity indicators**:142 ```143 Use Grep to flag potential issues:144 - Large files: Find files > 500 lines145 - Deep nesting: Search for excessive indentation146 - TODO/FIXME comments: Grep for "TODO|FIXME|HACK"147 - Console logs: Grep for "console\.(log|debug|warn)"148 ```149150### Phase 5: Dependency & Security Analysis151152**Goal**: Identify outdated or vulnerable dependencies153154**Tools**: Bash, Read155156**Process**:1571. **Check for lock files**:158 - Presence of `package-lock.json`, `yarn.lock`, `pnpm-lock.yaml`1591602. **Run security audit** (if npm/pnpm available):161 ```bash162 npm audit --json163 # or164 pnpm audit --json165 ```1661673. **Check for outdated dependencies**:168 ```bash169 npm outdated170 ```171172## Output Format173174Provide a structured analysis report:175176```markdown177# Codebase Analysis Report178179## Project Overview180- **Name**: [project name from package.json]181- **Type**: [framework/library]182- **Version**: [version]183- **Node.js**: [required version]184185## Technology Stack186### Core Framework187- [Framework name & version]188189### Key Dependencies190- UI: [library]191- State: [library]192- Routing: [library]193- Styling: [library]194- Testing: [library]195196### Build Tools197- [Vite/Webpack/etc]198199## Architecture200201### Directory Structure202```203[tree-like representation of key directories]204```205206### Patterns Identified207- [Component patterns]208- [State management approach]209- [API structure]210- [File organization]211212## Code Quality Metrics213- **TypeScript**: [strict/loose/none]214- **Linting**: [ESLint/Biome/none]215- **Testing**: [X test files found, coverage: Y%]216- **Code Issues**: [TODOs: X, Console logs: Y]217218## Recommendations2191. [Priority recommendation]2202. [Next priority]2213. ...222223## Risk Areas224- [Potential issues or technical debt]225226## Next Steps227- [Suggested actions based on analysis]228```229230## Best Practices2312321. **Progressive Detail**: Start with high-level overview, dive deeper only when needed2332. **Context Window Management**: For large codebases, analyze in chunks (by directory/feature)2343. **Tool Selection**: 235 - Use Glob for file discovery (faster than find)236 - Use Grep for pattern search (faster than reading all files)237 - Use Read only for critical files (package.json, configs)2384. **Time Efficiency**: Complete analysis in < 60 seconds for typical projects2395. **Actionable Insights**: Always provide specific, actionable recommendations240241## Integration with Other Skills242243This skill works well with:244- `quality-gates` - Use analysis results to run appropriate quality checks245- `project-initialization` - Compare against templates to identify missing setup246- `refactoring-safe` - Identify refactoring opportunities247- Framework-specific skills (`nextjs-optimization`, `react-patterns`) - Auto-invoke based on detected framework248249## Error Handling250251If analysis cannot complete:2521. **Missing dependencies**: Suggest running `npm install`2532. **Corrupted files**: Report specific files and continue with partial analysis2543. **Large codebase**: Switch to targeted analysis mode (specific directories only)2554. **Permission issues**: Request necessary file access permissions256257## Version History258259- **1.0.0** (2025-01-03): Initial skill creation with progressive disclosure support