Files
hakorune/docs/development/proposals
nyash-codex 8fe0babf01 docs: Add comprehensive code refactoring discovery analysis
Analyze entire codebase for refactoring opportunities:
- 110 files > 400 lines (72,936 lines total)
- Identified 6 critical files blocking Pattern 4/5 implementation
- Created Phase 1-3 refactoring roadmap (95-105 hours total)

Key findings:

**Critical Path (Phase 1): 26.5 hours**
- control_flow.rs: 1,632 lines → 6 modules (12.5h)
  - Blocks: Pattern 4/5 implementation
  - 714-line function, 168 control flow branches
  - Cognitive complexity: 5/5 (EXTREME)

- loopform_builder.rs: 1,166 lines → 6 modules (8h)
  - 4-pass split (prepare/preheader/header/seal)
  - 330+ lines of tests needing organization

- Quick wins: 5 files, 14 hours total
  - mir_json_emit.rs: v0/v1 format split (3h)
  - generic_case_a.rs: EntryFunctionBuilder extract (3h)
  - config_joinir.rs: JoinIR config extract (3h)
  - join_ir_runner.rs: Pattern handlers (3h)
  - box_factory.rs: Factory policy (2h)

**High Priority (Phase 2): 29 hours**
- builder.rs: 322 commits in 2025 (highest churn)
- strip.rs: using module handling (1,081 lines)
- Other large files

**Optional (Phase 3): 40-50 hours**
- Remaining 600-800 line files
- Code health improvements

**ROI Analysis**:
- Phase 1 investment: 26.5 hours
- Time saved on Pattern 4/5: 15-20 hours
- Maintenance savings: 5h/month long-term
- Breakeven: < 2 months

**Prioritization Strategy**:
1. Unblocks future development (Pattern 4/5)
2. Reduces cognitive load (5/5 → avg 2/5)
3. Improves testability
4. Zero breaking changes (fully reversible)

Document includes:
- Detailed analysis of 110 files
- Refactoring plans for each critical file
- Before/after code examples
- Complete prioritization matrix
- Risk assessment and mitigation

Next step: Execute Phase 1 starting with control_flow.rs

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-12-05 20:23:59 +09:00
..