Fixing Cycles
Fixing Cycles
Section titled “Fixing Cycles”This guide walks you through identifying and breaking circular dependencies. For refactoring patterns, see Refactoring Patterns. For an overview, see Circular Dependencies.
Step-by-Step Process
Section titled “Step-by-Step Process”-
Identify the largest cycle
Terminal window arxo analyze --format json | jq '.results[] | select(.id=="scc") | .data[] | select(.key=="scc.max_cycle_size") | .value.v' -
Examine cycle details
Terminal window arxo analyze --format json | jq '.ui_schemas.scc.scc_details[] | select((.nodes | length) > 1)' -
Review cycle-cut candidates
- Start with the edge with lowest
call_count - This represents the weakest coupling
- Start with the edge with lowest
-
Apply a refactoring pattern — see Refactoring Patterns
-
Verify the fix
Terminal window arxo analyze # Should show reduced cycle count
Quick Wins
Section titled “Quick Wins”For pragmatic refactoring:
- Start with small cycles - 2-node cycles are easier to fix
- Fix high-churn files first - Use git history to find frequently changed files
- Focus on the largest cycle - Breaking a 56-node cycle has massive impact
- Use cycle-cut candidates - Start with suggested edges (lowest effort)
Further Reading
Section titled “Further Reading”- Refactoring Patterns — Extract shared modules, dependency injection, types files
- Interpretation — Understanding cycle-cut candidates
- Policy — Enforce cycle rules in CI
- Breaking Cycles Guide — Comprehensive strategies