adaptive-pipeline-domain
Pure business logic and domain model for the Adaptive Pipeline - A reusable, framework-agnostic library following Domain-Driven Design principles.
๐ฏ Overview
This crate contains the pure domain layer of the Adaptive Pipeline system - all business logic, entities, value objects, and domain services with zero infrastructure dependencies. It's completely synchronous, has no I/O, and can be reused in any Rust application.
Design Philosophy
- โจ Pure Rust - No async, no tokio, no I/O dependencies
- ๐จ Domain-Driven Design - Entities, value objects, aggregates, domain services
- ๐ Type Safety - Leverages Rust's type system for compile-time guarantees
- โป๏ธ Reusable - Can be used independently in any Rust project
- ๐งช Testable - Pure functions and immutable values make testing trivial
๐ฆ Installation
Add this to your Cargo.toml:
[]
= "1.0"
๐๏ธ Architecture
This crate implements the Domain Layer from Clean Architecture:
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Domain Layer (This Crate) โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Entities โ โ
โ โ - Pipeline โ โ
โ โ - PipelineStage โ โ
โ โ - ProcessingContext โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Value Objects โ โ
โ โ - PipelineId (ULID) โ โ
โ โ - FileChunk โ โ
โ โ - ChunkSize โ โ
โ โ - Algorithm โ โ
โ โ - FilePath (validated) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Domain Services (Sync) โ โ
โ โ - CompressionService โ โ
โ โ - EncryptionService โ โ
โ โ - ChecksumService โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Infrastructure Ports (Traits) โ โ
โ โ - FileIOService โ โ
โ โ - PipelineRepository โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Key Components
Entities (with identity)
- Pipeline - Main aggregate root with pipeline configuration
- PipelineStage - Individual processing stage in a pipeline
- ProcessingContext - Maintains state during file processing
Value Objects (immutable, no identity)
- PipelineId / StageId / SessionId - ULID-based identifiers
- FileChunk - Immutable data chunk with metadata
- ChunkSize - Validated chunk size with adaptive sizing
- FilePath - Type-safe file path with validation
- Algorithm - Compression/encryption algorithm configuration
Domain Services (CPU-bound, synchronous)
- CompressionService - Brotli, Zstd, LZ4 compression
- EncryptionService - AES-GCM, ChaCha20-Poly1305 encryption
- ChecksumService - SHA-256 integrity verification
Infrastructure Ports (I/O-bound, async traits)
- FileIOService - Async trait for file operations
- PipelineRepository - Async trait for pipeline persistence
- FileProcessorService - Async trait for file processing
๐ Usage Examples
Creating a Pipeline Entity
use ;
use PipelineId;
// Create pipeline with stages
let mut pipeline = new;
// Add compression stage
let compress_stage = new;
pipeline.add_stage;
// Add encryption stage
let encrypt_stage = new;
pipeline.add_stage;
Working with Value Objects
use ;
// Type-safe chunk size with validation
let chunk_size = from_mb?; // 8 MB chunks
// Validated file path
let input_path = new?;
// Immutable file chunk
let chunk = new;
Using Domain Services
use ;
use FileChunk;
// Compression service (sync)
let compression = new?;
let compressed_chunk = compression.compress?;
// Encryption service (sync)
let encryption = new?;
let encrypted_chunk = encryption.encrypt?;
// Checksum service (sync)
let checksum = new?;
let hash = checksum.calculate?;
Processing Context
use ProcessingContext;
let mut context = new;
// Track processing state
context.add_metadata;
context.add_metadata;
// Access during processing
let ratio = context.get_metadata;
๐ง Design Patterns
Repository Pattern (Ports)
The domain defines repository traits that infrastructure implements:
Service Pattern (Domain Logic)
Domain services encapsulate CPU-bound business logic:
๐ฏ Key Features
Type-Safe Identifiers
All identifiers use ULIDs for:
- Time-ordered - Sortable by creation time
- Globally unique - 128-bit collision-resistant
- URL-safe - Base32 encoded strings
use PipelineId;
let id = new;
println!; // 01H2X3Y4Z5W6V7U8T9S0R1Q2P3
Validated Value Objects
All value objects enforce domain invariants:
use ChunkSize;
// Valid chunk sizes: 1MB to 64MB
let chunk = from_mb?; // โ
Valid
// Invalid sizes are rejected at construction
let invalid = from_mb?; // โ Error: exceeds maximum
Immutable Domain Events
Domain events capture important business occurrences:
use ;
let event = new;
// Events are immutable and serializable
let json = to_string?;
๐งช Testing
Domain logic is easy to test because it's pure:
๐ Dependencies
This crate has minimal dependencies to keep it pure:
- serde - Serialization support
- uuid / ulid - Unique identifiers
- thiserror - Error handling
- chrono - Timestamps (domain concern)
- sha2 - Checksums (domain logic)
- regex - Validation (domain rules)
No async runtime, no I/O libraries, no database dependencies.
๐ Related Crates
- adaptive-pipeline - Application layer and CLI
- adaptive-pipeline-bootstrap - Platform abstraction and entry point
๐ License
BSD 3-Clause License - see LICENSE file for details.
๐ค Contributing
This is a pure domain layer - contributions should:
- โ Add business logic or domain concepts
- โ Enhance type safety and validation
- โ Remain synchronous and I/O-free
- โ Not add async/await
- โ Not add I/O dependencies
- โ Not add framework-specific code
Pure Domain Logic | Framework-Agnostic | Highly Reusable