Overview
Extract command routing logic into an explicit Dispatch Layer with src/presentation/dispatch/router.rs and ExecutionContext. This separates routing from command execution and creates a clean pattern for controllers to access dependencies.
Parent Epic: #154 - Presentation Layer Reorganization
Depends On: #155 (Proposal 1: Create Input Layer)
Related: Refactor Plan | Design Proposal
Impact: 🟢🟢🟢 High - Separates routing from execution, enables clean controller pattern
Effort: 🔵🔵 Medium - Extract routing logic, create ExecutionContext
Estimated Time: 2-3 hours
Goals
🏗️ Architecture Requirements
DDD Layer: Presentation
Module Path: src/presentation/dispatch/
Pattern: Dispatch Layer (Layer 2 of 4-layer presentation architecture)
Target Structure
After this proposal:
src/presentation/
├── input/ # Layer 1 - CLI parsing
├── dispatch/ # ← NEW: Layer 2 - Routing & context
│ ├── mod.rs # Re-exports router and context
│ ├── router.rs # route_command() function
│ └── context.rs # ExecutionContext wrapper
├── commands/ # ← UNCHANGED (for now)
├── user_output/ # ← UNCHANGED (for now)
├── progress.rs # ← UNCHANGED (for now)
└── errors.rs # ← UNCHANGED
Implementation Plan
Phase 1: Create Directory Structure (30 minutes)
Phase 2: Implement ExecutionContext (45 minutes)
Phase 3: Implement Router (60 minutes)
Phase 4: Update Main Entry Point (30 minutes)
Phase 5: Documentation Updates (30 minutes)
Phase 6: Testing & Verification (30 minutes)
Acceptance Criteria
Note for Contributors: These criteria define what the PR reviewer will check. Use this as your pre-review checklist before submitting the PR.
Quality Checks:
Structure:
Routing:
ExecutionContext:
Functionality:
Documentation:
Mergeable State:
📚 Related Documentation
Created: November 6, 2025
Status: Ready for Implementation (after Proposal 1 completes)
Next Action: Wait for Proposal 1 completion, then begin Phase 1
Overview
Extract command routing logic into an explicit Dispatch Layer with
src/presentation/dispatch/router.rsandExecutionContext. This separates routing from command execution and creates a clean pattern for controllers to access dependencies.Parent Epic: #154 - Presentation Layer Reorganization
Depends On: #155 (Proposal 1: Create Input Layer)
Related: Refactor Plan | Design Proposal
Impact: 🟢🟢🟢 High - Separates routing from execution, enables clean controller pattern
Effort: 🔵🔵 Medium - Extract routing logic, create ExecutionContext
Estimated Time: 2-3 hours
Goals
src/presentation/dispatch/directory with router and context modulessrc/main.rsandcommands/mod.rsintoroute_command()ExecutionContextwrapper aroundContainerfor command executionsrc/main.rsto use new routercommands/directory remains functional🏗️ Architecture Requirements
DDD Layer: Presentation
Module Path:
src/presentation/dispatch/Pattern: Dispatch Layer (Layer 2 of 4-layer presentation architecture)
Target Structure
After this proposal:
Implementation Plan
Phase 1: Create Directory Structure (30 minutes)
src/presentation/dispatch/directorysrc/presentation/dispatch/mod.rswith module documentationsrc/presentation/dispatch/router.rssrc/presentation/dispatch/context.rssrc/presentation/mod.rsto includepub mod dispatch;Phase 2: Implement ExecutionContext (45 minutes)
ExecutionContextstruct incontext.rsnew()constructor acceptingArc<Container>container()accessor methodopentofu_client()ansible_client()environment_repository()clock()cargo checkPhase 3: Implement Router (60 minutes)
src/main.rsandcommands/mod.rsroute_command()function inrouter.rs:CommandsenumExecutionContextto handlers&ExecutionContextparametercargo checkPhase 4: Update Main Entry Point (30 minutes)
src/main.rsto use new routermain.rscargo checkPhase 5: Documentation Updates (30 minutes)
README.mdif it references routing logicPhase 6: Testing & Verification (30 minutes)
./scripts/pre-commit.shAcceptance Criteria
Quality Checks:
./scripts/pre-commit.shStructure:
src/presentation/dispatch/directory existssrc/presentation/dispatch/mod.rscontains module documentationsrc/presentation/dispatch/router.rscontainsroute_command()functionsrc/presentation/dispatch/context.rscontainsExecutionContextstructRouting:
route_command()handles all CLI commandsmain.rssrc/main.rsuses new routerExecutionContext:
ExecutionContextwrapsContainer&ExecutionContextparameterSend + Sync)Functionality:
commands/directory still functionalDocumentation:
dispatch/mod.rsexplains dispatch layer purposerouter.rshas comprehensive function documentationcontext.rsdocuments ExecutionContext usageMergeable State:
📚 Related Documentation
Created: November 6, 2025
Status: Ready for Implementation (after Proposal 1 completes)
Next Action: Wait for Proposal 1 completion, then begin Phase 1