adaptive_pipeline_domain/
entities.rs

1// /////////////////////////////////////////////////////////////////////////////
2// Adaptive Pipeline
3// Copyright (c) 2025 Michael Gardner, A Bit of Help, Inc.
4// SPDX-License-Identifier: BSD-3-Clause
5// See LICENSE file in the project root.
6// /////////////////////////////////////////////////////////////////////////////
7
8//! # Domain Entities
9//!
10//! This module contains the domain entities - objects with distinct identity
11//! that can change state over time while maintaining their identity. Entities
12//! represent the core business objects in the pipeline processing domain.
13//!
14//! ## Entity Characteristics
15//!
16//! Domain entities in this system have the following characteristics:
17//!
18//! - **Identity**: Each entity has a unique identifier that persists through
19//!   changes
20//! - **Mutability**: Entities can change state while maintaining their identity
21//! - **Lifecycle**: Entities have creation, modification, and potentially
22//!   deletion lifecycles
23//! - **Business Logic**: Entities encapsulate business rules and invariants
24//! - **Equality**: Two entities are equal if they have the same identity,
25//!   regardless of state
26//!
27//! ## Core Entities
28//!
29//! ### Pipeline
30//! The central entity representing a complete file processing workflow.
31//! Contains ordered stages and manages the overall processing logic.
32//!
33//! **Key Features**:
34//! - Unique pipeline identifier for tracking and management
35//! - Ordered collection of processing stages
36//! - Pipeline configuration and requirements
37//! - State management throughout execution
38//! - Validation of stage ordering and dependencies
39//!
40//! **Use Cases**:
41//! - File compression and encryption workflows
42//! - Multi-stage data transformation pipelines
43//! - Configurable processing chains
44//! - Auditable processing workflows
45//!
46//!
47//! ### PipelineStage
48//! Represents an individual processing step within a pipeline.
49//! Each stage performs a specific transformation on the data.
50//!
51//! **Key Features**:
52//! - Unique stage identifier and ordering
53//! - Stage-specific configuration and parameters
54//! - Input/output type specifications
55//! - Stage execution status tracking
56//! - Error handling and recovery
57//!
58//! **Stage Types**:
59//! - Compression stages (Zlib, Zstd, Brotli)
60//! - Encryption stages (AES-256-GCM, ChaCha20-Poly1305)
61//! - Validation stages (checksum, integrity)
62//! - Custom transformation stages
63//!
64//!
65//! ### ProcessingContext
66//! Maintains the runtime state and context for pipeline execution.
67//! Tracks progress, metrics, and execution state.
68//!
69//! **Key Features**:
70//! - Unique context identifier for tracing
71//! - Current execution state and progress tracking
72//! - Performance metrics collection
73//! - Error tracking and reporting
74//! - Resource usage monitoring
75//!
76//! **Tracked Information**:
77//! - Bytes processed and remaining
78//! - Current pipeline stage
79//! - Elapsed processing time
80//! - Memory and CPU utilization
81//! - Error history and recovery attempts
82//!
83//!
84//! ### SecurityContext
85//! Manages security-related information and permissions for processing
86//! operations. Enforces access control and security policies.
87//!
88//! **Key Features**:
89//! - User identity and authentication
90//! - Permission-based access control
91//! - Security level enforcement
92//! - Audit trail generation
93//! - Session management and expiration
94//!
95//! **Security Levels**:
96//! - Public: No authentication required
97//! - Authenticated: Valid user authentication
98//! - Confidential: Enhanced permissions required
99//! - Secret: Highest level access control
100//!
101//!
102//! ### ProcessingMetrics
103//! Collects and aggregates performance and operational metrics during
104//! processing. Provides insights into system performance and resource
105//! utilization.
106//!
107//! **Key Features**:
108//! - Real-time performance metric collection
109//! - Throughput measurement (bytes/second)
110//! - Latency tracking (operation duration)
111//! - Resource utilization monitoring
112//! - Error rate calculation
113//!
114//! **Collected Metrics**:
115//! - Total bytes processed
116//! - Processing throughput (MB/s)
117//! - Average/min/max latencies
118//! - Memory consumption
119//! - CPU utilization percentage
120//! - Stage-specific performance data
121//!
122//!
123//! ## Entity Lifecycle Management
124//!
125//! Entities follow a well-defined lifecycle:
126//!
127//! 1. **Creation**: Entities are created with valid initial state
128//! 2. **Validation**: All state changes are validated against business rules
129//! 3. **Modification**: Entities can be modified through controlled methods
130//! 4. **Persistence**: Entity state can be persisted and restored
131//! 5. **Cleanup**: Resources are properly cleaned up when entities are no
132//!    longer needed
133//!
134//! ## Business Rules and Invariants
135//!
136//! Entities enforce important business rules:
137//!
138//! - **Pipeline Rules**: Pipelines must have at least one stage, stages must be
139//!   ordered
140//! - **Security Rules**: Security contexts must be validated, permissions must
141//!   be checked
142//! - **Processing Rules**: Processing context must track accurate metrics and
143//!   state
144//! - **Data Integrity**: All data modifications must maintain consistency
145//!
146//! ## Testing Entities
147//!
148//! Entities are designed to be easily testable:
149//!
150//! ```rust
151//! # #![allow(unused)]
152//! # use uuid::Uuid;
153//! #[derive(Debug, Clone, PartialEq, Eq)]
154//! struct EntityId(Uuid);
155//! #[derive(Debug, Clone)]
156//! struct Device {
157//!     id: EntityId,
158//!     name: String,
159//! }
160//! impl Device {
161//!     fn new(name: impl Into<String>) -> Self {
162//!         Self {
163//!             id: EntityId(Uuid::new_v4()),
164//!             name: name.into(),
165//!         }
166//!     }
167//!     fn rename(&mut self, name: impl Into<String>) {
168//!         self.name = name.into();
169//!     }
170//! }
171//! let mut d = Device::new("Sensor-A");
172//! d.rename("Sensor-A1");
173//! assert!(matches!(d.id, EntityId(_)));
174//! ```
175
176pub mod pipeline;
177pub mod pipeline_stage;
178pub mod processing_context;
179pub mod processing_metrics;
180pub mod security_context;
181
182// Re-export all entity types for convenient access
183pub use pipeline::Pipeline;
184pub use pipeline_stage::{Operation, PipelineStage, StageConfiguration, StagePosition, StageType};
185pub use processing_context::ProcessingContext;
186pub use processing_metrics::ProcessingMetrics;
187pub use security_context::{SecurityContext, SecurityLevel};