Phase System Simplification - Executive Summary
Current State
The netherframe phase system has grown organically to handle circular dependencies in infrastructure deployments. While functional, it now suffers from:
- 700-900 lines of duplicated code across 15+ files
- Multiple competing implementations (v1 vs v2 planners, duplicate models)
- Complex API surface with unclear entry points
- Fragmented execution paths for different modes
Key Findings
1. Major Duplication Areas
| Component | Files Affected | Lines Duplicated |
|---|---|---|
| Circular dependency detection | 4-5 files | ~150-200 |
| Resource reference handling | 6+ files | ~120-150 |
| Phase model definitions | 2 files | ~100 |
| Execution step generation | 3 files | ~100-120 |
| Configuration modification | 4 files | ~80-100 |
2. Complexity Sources
- No single source of truth for phase models
- Strategy pattern over-engineered with 3 overlapping strategies
- Dependency analysis scattered across multiple modules
- Unclear separation between planning and execution
Proposed Solution
Simplified Architecture
Current: 15+ files, multiple entry points
Proposed: 6 core modules, single API
nf.core.phases/
├── models.py # Single source for all models
├── analyzer.py # Centralized dependency analysis
├── planner.py # Unified planning logic
├── strategies/ # Simplified strategies (2 instead of 3)
├── executor.py # Unified execution
└── __init__.py # Clean public API
Clean API
# Before: Complex and unclear
from nf.core.phase_planner_v2 import OptimizedPhasePlanner
from nf.core.phase_strategies import get_strategy
planner = OptimizedPhasePlanner()
# ... many steps ...
# After: Simple and intuitive
from nf.core import phases
plan = phases.analyze(app)
result = phases.execute(plan)
Implementation Roadmap
Quick Wins (Week 1)
- Consolidate duplicate models
- Create centralized dependency analyzer
- Set up new module structure
Core Refactoring (Weeks 2-3)
- Implement unified planner
- Simplify strategy system
- Create compatibility layer
Integration (Week 4)
- Update CLI and orchestrators
- Comprehensive testing
- Performance validation
Rollout (Week 5)
- Documentation
- Migration guides
- Gradual deployment
Expected Benefits
- Code Reduction: 35-45% less code to maintain
- Performance: Unified caching and optimized algorithms
- Maintainability: Clear module boundaries and responsibilities
- Developer Experience: Intuitive API with fewer concepts
- Reliability: Single implementation reduces inconsistency bugs
Risks and Mitigation
| Risk | Impact | Mitigation |
|---|---|---|
| Breaking changes | High | Comprehensive compatibility layer |
| Performance regression | Medium | Continuous benchmarking |
| Feature gaps | Low | Extensive test coverage |
| User confusion | Low | Clear migration guides |
Recommendations
- Proceed with simplification - The benefits clearly outweigh the risks
- Start with foundation - Models and analyzer first
- Maintain compatibility - Keep old APIs working during transition
- Feature flag rollout - Allow gradual adoption
- Comprehensive testing - Ensure no regressions
Next Steps
- Review and approve the implementation plan
- Create feature branch for development
- Begin Week 1 tasks (foundation)
- Set up performance benchmarks
- Communicate changes to team
Conclusion
The phase system simplification will transform a complex, sprawling codebase into a clean, maintainable module. With proper planning and execution, this can be accomplished in 5 weeks with minimal disruption to users while providing significant long-term benefits to the project.