Dependency Graph Analysis
Entry: $1 (or src/index.ts if not specified)
- Try dependency analysis tools:
npx madge --circular src/ 2>/dev/null | head -30
npx depcruise --include-only "^src" --output-type text src/ 2>/dev/null | head -50
- Manual circular dependency search:
# Files that import each other
grep -rn "^import.*from" src/ --include="*.ts" | awk '{print $NF}' | sort | uniq -c | sort -rn | head -20
- Identify:
- Circular imports: A → B → C → A (breaks tree-shaking, causes runtime issues)
- High fan-in: modules imported by many others (change = high risk)
- High fan-out: modules that import many things (likely doing too much)
- Layer violations: UI importing from DB layer directly
- For each circular import: propose how to break the cycle (extract shared types, invert dependency, use dependency injection).
- Draw a simplified text dependency graph for the top-level modules.