Commit 1fe82de
committed
aa531e3 feat: [#156] implement dispatch layer with ExecutionContext wrapper (Jose Celano)
04d0d5f feat: [#156] implement Dispatch Layer with ExecutionContext wrapper (Jose Celano)
Pull request description:
## 🎯 Overview
This PR implements **Proposal 2: Create Dispatch Layer** from the presentation layer reorganization epic ([#154](#154)).
The Dispatch Layer establishes clear separation between command routing, execution context, and command execution, following the four-layer presentation architecture: **Input → Dispatch → Controllers → Views**.
## 📋 What's Implemented
### Core Components
- **ExecutionContext wrapper** around `Arc<Container>` for future-proof command signatures
- **Central command routing** with `route_command(command, working_dir, &context)` function
- **Complete dispatch module** with router and context submodules
- **Bootstrap integration** - Updated `bootstrap/app.rs` to use new dispatch layer
- **Legacy deprecation** - Marked old `presentation::execute` as deprecated with migration guide
### Documentation & Quality
- **Architectural Decision Record** - [`docs/decisions/execution-context-wrapper.md`](docs/decisions/execution-context-wrapper.md) documenting design rationale
- **Comprehensive documentation** - Module-level docs explaining architecture and benefits
- **Fixed all doctest issues** - All 303 documentation tests compile and pass
- **Linting fixes** - Added 'configurator' to spell-check dictionary, fixed clippy issues
## 🏗️ Architecture Benefits
### ExecutionContext Design
The dispatch layer uses an `ExecutionContext` wrapper instead of passing `Container` directly:
```rust
pub struct ExecutionContext {
container: Arc<Container>,
// Future extensions without breaking changes:
// request_id: RequestId,
// execution_metadata: ExecutionMetadata,
// tracing_context: TracingContext,
}
```
**Benefits:**
- **Future-proof** - Can extend execution context without breaking command signatures
- **Clear abstraction** - Represents "everything a command needs" vs generic container
- **Command-specific access** - Convenience methods for common services
- **Type safety** - Compile-time guarantees for service access
### Routing Architecture
```rust
pub fn route_command(
command: Commands,
working_dir: &Path,
context: &ExecutionContext,
) -> Result<(), CommandError>
```
**Benefits:**
- **Centralized routing** - All command dispatch logic in one place
- **Type safety** - Compile-time guarantees that all commands are handled
- **Testable** - Router can be tested independently of handlers
- **Scalable** - Easy to add new commands without modifying existing code
## 🔧 Module Structure
```text
src/presentation/dispatch/
├── mod.rs # Layer exports and comprehensive documentation
├── router.rs # Central command routing logic
└── context.rs # ExecutionContext wrapper implementation
```
## ✅ Quality Validation
All quality checks pass:
- **1,200+ Unit Tests** ✅ - All pass successfully
- **E2E Tests** ✅ - Provision and configuration tests validated
- **Documentation Tests** ✅ - All 303 doctests compile and pass
- **Linting** ✅ - cargo machete, clippy, rustfmt, shellcheck, cspell all pass
- **Pre-commit Validation** ✅ - Complete pre-commit suite passes
## 📖 Related Documentation
- **ADR**: [`docs/decisions/execution-context-wrapper.md`](docs/decisions/execution-context-wrapper.md) - Design rationale for ExecutionContext wrapper
- **Epic Issue**: [#154](#154) - Presentation layer reorganization roadmap
- **Module Documentation** - Comprehensive docs in `src/presentation/dispatch/mod.rs`
## 🚀 Next Steps
After this PR is merged:
1. **Update epic progress** - Mark Proposal 2 as completed in [#156](#156)
2. **Begin Proposal 3** - Start implementing Controllers layer
3. **Integration** - New dispatch layer is ready for remaining presentation components
## 🔍 Migration Guide
For code using the old `presentation::execute` function:
```rust
// Old (deprecated)
use torrust_tracker_deployer_lib::presentation::execute;
execute(command, working_dir, user_output).await?;
// New (recommended)
use torrust_tracker_deployer_lib::presentation::dispatch::{route_command, ExecutionContext};
let context = ExecutionContext::new(Arc::new(container));
route_command(command, working_dir, &context)?;
```
---
**Closes:** #156
**Part of Epic:** #154
ACKs for top commit:
josecelano:
ACK aa531e3
Tree-SHA512: c7a2815acef975d06a620943223a68e34f0463d81621cea96dc3c5a072d43fe6b08da33d5d540cc62cd24ec3f78431260bc85691af6c8dba9bec82081b49270a
File tree
9 files changed
+726
-4
lines changed- docs/decisions
- src
- bootstrap
- presentation
- commands
- dispatch
9 files changed
+726
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
56 | 58 | | |
57 | 59 | | |
58 | 60 | | |
59 | | - | |
| 61 | + | |
| 62 | + | |
60 | 63 | | |
61 | 64 | | |
62 | 65 | | |
63 | 66 | | |
64 | | - | |
| 67 | + | |
65 | 68 | | |
66 | | - | |
| 69 | + | |
67 | 70 | | |
68 | 71 | | |
69 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
31 | 59 | | |
32 | 60 | | |
33 | 61 | | |
| |||
65 | 93 | | |
66 | 94 | | |
67 | 95 | | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
68 | 117 | | |
69 | 118 | | |
70 | 119 | | |
| |||
0 commit comments