adaptive-pipeline-bootstrap
Bootstrap and platform abstraction layer for the Adaptive Pipeline - Handles application entry points, dependency injection, signal handling, and cross-platform operations.
๐ฏ Overview
This crate sits outside the enterprise application layers and provides the foundational infrastructure needed to bootstrap and run Rust applications with:
- Platform Abstraction - Unified API for Unix and Windows
- Signal Handling - Graceful shutdown for SIGTERM, SIGINT, SIGHUP
- CLI Parsing - Secure argument validation with clap
- Dependency Injection - Composition root for wiring services
- Shutdown Coordination - CancellationToken-based graceful teardown
- Exit Code Mapping - Unix sysexits.h standard codes
Design Philosophy
- ๐ช Entry Point - Application lifecycle management
- ๐ Cross-Platform - Write once, run on Unix/Windows
- ๐ Security - Input validation, path traversal prevention
- โป๏ธ Reusable - Can bootstrap any Rust CLI application
- ๐งช Testable - Trait-based with mock implementations
๐ฆ Installation
Add this to your Cargo.toml:
[]
= "1.0"
๐๏ธ Architecture Position
Bootstrap is the outermost layer that initializes the application:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ BOOTSTRAP (This Crate) โ
โ - 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 โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
๐ Usage Examples
Basic CLI Bootstrapping
use ;
async
async
Platform Abstraction
use create_platform;
// Get platform-specific implementation
let platform = create_platform;
// Cross-platform API
println!;
println!;
println!;
// Memory information
let total = platform.total_memory?;
let available = platform.available_memory?;
println!;
// Platform-specific constants
println!;
println!;
Signal Handling
use create_signal_handler;
use ShutdownCoordinator;
async
CLI Validation
use ;
// Parse with automatic validation
let cli = parse_and_validate?;
// All inputs are validated:
// - No SQL injection patterns
// - No path traversal (../)
// - No dangerous shell characters
// - Numbers within allowed ranges
// - Paths are sanitized
match &cli.command
Exit Code Mapping
use ;
// Maps error messages to sysexits.h codes:
// - "file not found" -> EX_NOINPUT (66)
// - "invalid data" -> EX_DATAERR (65)
// - "I/O error" -> EX_IOERR (74)
๐ง Module Overview
Platform Abstraction (platform)
Provides unified cross-platform API:
Implementations:
UnixPlatform- Uses libc, /proc, /sysWindowsPlatform- Uses winapi, with stubs for non-Windows
Signal Handling (signals)
Cross-platform graceful shutdown:
// Unix: SIGTERM, SIGINT, SIGHUP
// Windows: Ctrl+C, Ctrl+Break
let handler = create_signal_handler;
CLI Parsing (cli)
Secure argument validation with clap:
// Security validations:
// - SQL injection prevention
// - Path traversal checks
// - Shell command injection blocking
// - Numeric range validation
Shutdown Coordination (shutdown)
CancellationToken-based coordination:
Exit Codes (exit_code)
Unix sysexits.h standard codes:
// Automatic error message mapping
let code = map_error_to_exit_code;
assert_eq!;
๐ฏ Key Features
Cross-Platform Compatibility
Compile-time platform selection:
pub use UnixPlatform;
pub use WindowsPlatform;
Runtime platform detection:
let platform = create_platform;
if platform.platform_name == "macos"
Security Validations
All CLI inputs are validated for security:
// โ Rejected patterns:
// - "../../../etc/passwd" (path traversal)
// - "'; DROP TABLE users; --" (SQL injection)
// - "$(rm -rf /)" (shell injection)
// - "\x00\x01\x02" (binary data)
// โ
Accepted inputs:
// - "/valid/path/to/file.txt"
// - "my-pipeline-name"
// - "8" (numeric validation)
Graceful Shutdown
Multi-stage shutdown:
1. Signal received (SIGTERM/SIGINT)
2. CancellationToken triggered
3. Tasks check token and cleanup
4. Coordinator waits for completion
5. Timeout enforcement (default: 30s)
6. Process exits cleanly
๐งช Testing
Bootstrap includes testable abstractions:
๐ Dependencies
Minimal dependencies for cross-platform support:
- tokio - Async runtime
- async-trait - Async trait support
- thiserror / anyhow - Error handling
- clap - CLI argument parsing
- tracing - Structured logging
Platform-specific:
- Unix:
libc - Windows:
winapi
๐ Related Crates
- adaptive-pipeline - Application layer and CLI
- adaptive-pipeline-domain - Pure business logic
๐ License
BSD 3-Clause License - see LICENSE file for details.
๐ค Contributing
Contributions should focus on:
- โ Cross-platform compatibility
- โ Security hardening
- โ Signal handling improvements
- โ Platform abstraction enhancements
- โ Not business logic (belongs in domain)
- โ Not application logic (belongs in application layer)
Cross-Platform Foundation | Secure by Default | Production-Ready