| name | app-analyzer-optimizer |
| description | Deeply analyzes application architecture, dependencies, and performance configurations, and executes targeted optimizations aligned with active project skills. Use whenever the user wants a full project health check, dependency audit, performance review, or asks "analyze my codebase" or "optimize my app." Trigger on phrases like "audit my project", "analyze the architecture", "find performance issues", "optimize this app", or "review my dependencies".
|
App Analyzer & Optimizer
Systematic codebase analysis and targeted optimization workflow.
Analysis Workflow
Run analysis in this order — each stage informs the next:
1. Inventory → What's actually in this project?
2. Dependencies → What's outdated, unused, or risky?
3. Architecture → How is it structured? Any anti-patterns?
4. Performance → Where are the bottlenecks?
5. Security → What's exposed or vulnerable?
6. Recommendations → Prioritized, actionable fixes
Stage 1: Project Inventory
cat package.json 2>/dev/null | head -30
cat Cargo.toml 2>/dev/null
cat pyproject.toml 2>/dev/null
cat go.mod 2>/dev/null
find . -type f -name "*.ts" -o -name "*.tsx" | grep -v node_modules | wc -l
du -sh node_modules 2>/dev/null
du -sh .next dist build 2>/dev/null
ls -la | grep -E "next.config|vite.config|tailwind.config"
Inventory Checklist
Stage 2: Dependency Audit
npm outdated
pnpm outdated
npm audit
pnpm audit
npx depcheck
npm ls --all 2>&1 | grep -B2 "deduped"
npx bundle-phobia <package-name>
Dependency Red Flags
| Finding | Risk | Action |
|---|
| Package unmaintained >2 years | Security/compat risk | Find alternative or fork |
| Multiple lockfiles (package-lock + pnpm-lock) | Build inconsistency | Pick one PM, delete others |
| Direct + transitive version mismatch | Subtle bugs | npm dedupe or pin versions |
| Large unused dependency | Bundle bloat | Remove or tree-shake |
| Dependency with known CVE | Security | Update immediately or patch |
Stage 3: Architecture Review
Structural Red Flags
find src -name "*.ts" -o -name "*.tsx" | xargs wc -l | sort -rn | head -10
npx madge --circular --extensions ts,tsx src/
grep -r "from '\.\./\.\./\.\./\.\./.*'" src/ --include="*.ts*"
Architecture Checklist
Stage 4: Performance Analysis
Frontend (Next.js/React)
ANALYZE=true npm run build
grep -rL "dynamic(" src/components --include="*.tsx" | xargs grep -l "recharts\|monaco-editor\|three"
npx lighthouse https://your-url.com --view
Performance Checklist
Backend Performance
grep -rn "for.*await.*query\|forEach.*await.*find" src/
grep -rn "new Pool\|createPool" src/
SELECT
c.conrelid::regclass AS table_name,
string_agg(a.attname, ', ') AS columns
FROM pg_constraint c
JOIN pg_attribute a ON a.attrelid = c.conrelid AND a.attnum = ANY(c.conkey)
WHERE c.contype = 'f'
AND NOT EXISTS (
SELECT 1 FROM pg_index i
WHERE i.indrelid = c.conrelid AND a.attnum = ANY(i.indkey)
)
GROUP BY c.conrelid;
Stage 5: Security Quick Scan
git log --all --full-history -- "*.env" "*secret*" "*key*"
grep -rn "sk_live\|sk_test\|AKIA\|service_role" src/ --include="*.ts*"
grep -rn "query(\`.*\${" src/ --include="*.ts*"
grep -rn "Access-Control-Allow-Origin.*\*" src/
Security Checklist
Stage 6: Prioritized Recommendations
Output Format
Present findings in priority order, with effort estimate:
## Critical (Fix Now)
- [ ] **Exposed `service_role` key in client bundle** — Effort: 30min
Move to server-only env var, rotate the key.
## High Priority (This Sprint)
- [ ] **N+1 query in `/api/dashboard`** — Effort: 2hrs
47 sequential queries per page load. Batch with a single JOIN.
- [ ] **3 packages with known CVEs** — Effort: 1hr
`npm audit fix` resolves 2; `lodash` needs manual major version bump.
## Medium Priority (Next Sprint)
- [ ] **142 unused dependencies in package.json** — Effort: 3hrs
Bundle size could drop ~340KB. Run `depcheck`, verify, remove.
## Low Priority (Backlog)
- [ ] **Inconsistent file naming** (camelCase vs kebab-case) — Effort: ongoing
Standardize gradually during normal development.
Prioritization Matrix
Impact ↑
High │ Critical │ High Priority
│ (fix now) │ (this sprint)
├─────────────┼──────────────
Low │ Low Priority│ Medium Priority
│ (backlog) │ (next sprint)
└─────────────┴──────────────→
Low Effort High Effort
Optimization Execution Pattern
When executing fixes (not just reporting):
- One category at a time — don't mix dependency updates with architecture refactors in one pass
- Verify before and after — run build/tests before and after each change
- Smallest safe change first — config changes before code rewrites
- Document what changed and why — update CHANGELOG per the auto-doc-updater skill
npm run build && npm run test && npm run lint
Key Rules
- Inventory before judging — understand the actual stack before recommending changes
- Measure, don't assume — use
npm audit, depcheck, madge, bundle analyzer — not guesswork
- Prioritize by impact/effort, not by what's most interesting to fix
- Security findings are always "Critical" or "High" — never deprioritize exposed secrets or injection risks
- One category of change per pass — don't bundle unrelated fixes in one diff
- Verify with build+test after every optimization, not just at the end
- N+1 queries and missing indexes are the most common high-impact, low-effort backend wins
- Bundle size wins (dynamic imports, dead code removal) are usually the highest-impact, lowest-risk frontend fixes
- Never silently "optimize" away functionality — flag risky removals for confirmation
- Report findings even when not asked to fix — visibility into technical debt has value on its own