Skip to content

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

  1. Code Reduction: 35-45% less code to maintain
  2. Performance: Unified caching and optimized algorithms
  3. Maintainability: Clear module boundaries and responsibilities
  4. Developer Experience: Intuitive API with fewer concepts
  5. 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

  1. Proceed with simplification - The benefits clearly outweigh the risks
  2. Start with foundation - Models and analyzer first
  3. Maintain compatibility - Keep old APIs working during transition
  4. Feature flag rollout - Allow gradual adoption
  5. Comprehensive testing - Ensure no regressions

Next Steps

  1. Review and approve the implementation plan
  2. Create feature branch for development
  3. Begin Week 1 tasks (foundation)
  4. Set up performance benchmarks
  5. 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.