Expand description
§Bootstrap Module
The bootstrap module sits outside the enterprise application layers (domain, application, infrastructure) and provides:
- Entry point - Application lifecycle management
- Platform abstraction - OS-specific operations (POSIX vs Windows)
- Signal handling - Graceful shutdown (SIGTERM, SIGINT, SIGHUP)
- Argument parsing - Secure CLI argument validation
- Dependency injection - Composition root for wiring dependencies
- Error handling - Unix exit code mapping
- Async coordination - Shutdown coordination and cancellation
§Architecture Position
┌─────────────────────────────────────────────┐
│ BOOTSTRAP (This Module) │
│ - Entry Point │
│ - DI Container (Composition Root) │
│ - Platform Abstraction │
│ - Signal Handling │
│ - Secure Arg Parsing │
└─────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────┐
│ APPLICATION LAYER │
│ - Use Cases │
│ - Application Services │
└─────────────────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────┐
│ DOMAIN LAYER │
│ - Business Logic │
│ - Domain Services │
│ - Entities & Value Objects │
└─────────────────────────────────────────────┘
▲
│
┌─────────────────────────────────────────────┐
│ INFRASTRUCTURE LAYER │
│ - Adapters │
│ - Repositories │
│ - External Services │
└─────────────────────────────────────────────┘§Key Design Principles
-
Separation from Enterprise Layers
- Bootstrap can access all layers
- Enterprise layers cannot access bootstrap
- Clear architectural boundary
-
Platform Abstraction
- Abstract OS-specific functionality behind traits
- POSIX implementation for Linux/macOS
- Windows implementation with cross-platform stubs
- Compile-time platform selection
-
Graceful Shutdown
- Signal handlers (SIGTERM, SIGINT, SIGHUP)
- Cancellation token propagation
- Grace period with timeout enforcement
- Coordinated shutdown across components
-
Security First
- Input validation for all arguments
- Path traversal prevention
- Injection attack protection
- Privilege checking
-
Testability
- All components behind traits
- No-op implementations for testing
- Dependency injection for mocking
§Usage Example
use adaptive_pipeline_bootstrap::platform::create_platform;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Get platform abstraction
let platform = create_platform();
println!("Running on: {}", platform.platform_name());
// Bootstrap will handle:
// - Argument parsing
// - Signal handling setup
// - Dependency wiring
// - Application lifecycle
// - Graceful shutdown
Ok(())
}§Module Structure
platform- OS abstraction (Unix/Windows)signals- Signal handling (SIGTERM, SIGINT, SIGHUP)cli- Secure argument parsingconfig- Application configurationexit_code- Unix exit code enumerationlogger- Bootstrap-specific loggingshutdown- Shutdown coordinationcomposition_root- Dependency injection containerapp_runner- Application lifecycle management
Re-exports§
pub use cli::parse_and_validate;pub use cli::ValidatedCli;pub use cli::ValidatedCommand;pub use exit_code::map_error_to_exit_code;pub use exit_code::result_to_exit_code;pub use exit_code::ExitCode;
Modules§
- cli
- Command-Line Interface Module
- config
- Application Configuration
- exit_
code - Exit Code Management
- logger
- Bootstrap Logger
- platform
- Platform Abstraction Module
- shutdown
- Shutdown Coordination
- signals
- System Signal Handling
Functions§
- bootstrap_
cli - Bootstrap and parse CLI arguments