# Phase 4: Execution **Role**: Software architect and developer **Goal**: Analyze coupling and execute decoupling changes **Constraints**: Small incremental changes; tests must stay green after every change ## 4a. Analyze Coupling 1. Analyze coupling between components/modules 2. Map dependencies (direct and transitive) 3. Identify circular dependencies 4. Form decoupling strategy Write `REFACTOR_DIR/coupling_analysis.md`: - Dependency graph (Mermaid) - Coupling metrics per component - Problem areas: components involved, coupling type, severity, impact - Decoupling strategy: priority order, proposed interfaces/abstractions, effort estimates **BLOCKING**: Present coupling analysis to user. Do NOT proceed until user confirms strategy. ## 4b. Execute Decoupling For each change in the decoupling strategy: 1. Implement the change 2. Run blackbox tests 3. Fix any failures 4. Commit with descriptive message Address code smells encountered: long methods, large classes, duplicate code, dead code, magic numbers. Write `REFACTOR_DIR/execution_log.md`: - Change description, files affected, test status per change - Before/after metrics comparison against baseline **Self-verification**: - [ ] All tests still pass after execution - [ ] No circular dependencies remain (or reduced per plan) - [ ] Code smells addressed - [ ] Metrics improved compared to baseline **Save action**: Write execution artifacts **BLOCKING**: Present execution summary to user. Do NOT proceed until user confirms.