1pub mod advanced_composition;
76pub mod component_framework;
77pub mod dependency_management;
78pub mod event_system;
79pub mod execution_engine;
80pub mod lifecycle_management;
81pub mod pipeline_system;
82pub mod registry_system;
83
84pub use component_framework::{
86 CapabilityMismatch, CapabilityMismatchSeverity, CompatibilityReport, ComponentCapability,
87 ComponentConfig, ComponentDependency, ComponentEvent as FrameworkComponentEvent,
88 ComponentFactory, ComponentInfo, ComponentMetadata, ComponentMetrics, ComponentNode,
89 ComponentRegistry, ComponentState, ComponentStatus, ConfigValue, EnvironmentSettings,
90 ExecutionCondition, ExecutionConditionType, ExecutionMetadata, ExecutionStatus, HealthStatus,
91 LogLevel, MetricValue, MissingDependency, PluggableComponent, ResourceConstraints,
92 ResourceLimits, ResourceUsage, SecuritySettings, VersionConflict,
93};
94
95pub use registry_system::{
96 ComponentQuery, ComponentRegistrationMetadata, ComponentTypeInfo, ComponentVersionInfo,
97 GlobalComponentRegistry, PluginLoadResult, RegistryConfiguration, RegistryError, RegistryHooks,
98 RegistryStatistics,
99};
100
101pub use lifecycle_management::{
102 ComponentLifecycleState, InitializationResult, LifecycleConfig, LifecycleEvent,
103 LifecycleManager, LifecycleMetrics, ShutdownResult,
104};
105
106pub use event_system::{
107 ComponentEvent, EventBus, EventCategory, EventHandler, EventMetadata, EventPriority,
108 EventProcessingResult, EventRoutingConfig, EventStatistics, RoutingRule, RoutingStrategy,
109};
110
111pub use dependency_management::{
112 CircularDependency, CompatibilityIssue, CompatibilityIssueType, CompatibilityResult,
113 ConflictType, DependencyConflict, DependencyError, DependencyGraph,
114 DependencyInjectionRegistry, DependencyNode, DependencyProvider, DependencyResolutionConfig,
115 DependencyResolver, DependencyState, DependencyStatistics, ResolutionResult, VersionConstraint,
116 VersionConstraintSolver,
117};
118
119pub use pipeline_system::{
120 BackoffStrategy, ConditionalExecution, ErrorHandlingStrategy, ExecutionContext,
121 ExecutionStrategy, ExecutionTrace, ModularPipeline, ModularPipelineBuilder, ParallelBranch,
122 Pipeline, PipelineBuilder, PipelineConfig, PipelineConfiguration, PipelineData, PipelineError,
123 PipelineMetadata, PipelineMetrics, PipelineResult, PipelineStage, PipelineState, PipelineStep,
124 RetryConfig, RetryConfiguration, RetryPolicy, StageMetrics, StageResult, StageType,
125 TimeoutAction, TimeoutConfig,
126};
127
128pub use execution_engine::{
129 ComponentExecutionResult, CompositionContext, CompositionExecutionEngine, CompositionGraph,
130 CompositionNode, CompositionResult, ConcurrentExecution, ContextState, ExecutionEngineConfig,
131 ExecutionEngineError, ExecutionPlan, ExecutionPriority, ExecutionResult, ExecutionScheduler,
132 ExecutionStatistics, ResourceAllocation, ResourceAllocationStrategy, ResourceManager,
133};
134
135pub use advanced_composition::{
136 AdvancedCompositionError, AlgebraicComposer, AlgebraicComposition, AlgebraicOperation,
137 Applicative, ApplicativeFunctor, CategoryMorphism, Composition, CompositionCombinator,
138 CompositionFunction, CompositionMetadata, CompositionType, ConstraintType, FunctionalComposer,
139 FunctionalComposition, Functor, HigherOrderComposer, HigherOrderComposition,
140 HigherOrderTransform, MetaComposition, Monad, MonadTransformer,
141 ParallelBranch as TypedParallelBranch, PatternMatcher, ProductTypeComposition,
142 RecursiveCompositionPattern, SumTypeComposition, TypeConstraint, TypeConstraints,
143 TypePredicate, TypeSafeComposer, TypedComposition, TypedTransformer,
144};
145
146use sklears_core::error::Result as SklResult;
147use std::sync::Arc;
148
149#[derive(Debug)]
154pub struct ComponentFramework {
155 registry: Arc<GlobalComponentRegistry>,
157 dependency_resolver: Arc<DependencyResolver>,
159 lifecycle_manager: Arc<LifecycleManager>,
161 execution_engine: Arc<CompositionExecutionEngine>,
163 event_bus: Arc<std::sync::RwLock<EventBus>>,
165}
166
167impl ComponentFramework {
168 #[must_use]
170 pub fn new() -> Self {
171 let registry = Arc::new(GlobalComponentRegistry::new());
172 let dependency_resolver = Arc::new(DependencyResolver::new());
173 let lifecycle_manager = Arc::new(LifecycleManager::new());
174 let execution_engine = Arc::new(CompositionExecutionEngine::new(
175 registry.clone(),
176 dependency_resolver.clone(),
177 lifecycle_manager.clone(),
178 ));
179 let event_bus = Arc::new(std::sync::RwLock::new(EventBus::new()));
180
181 Self {
182 registry,
183 dependency_resolver,
184 lifecycle_manager,
185 execution_engine,
186 event_bus,
187 }
188 }
189
190 pub fn register_component_factory(
192 &self,
193 component_type: &str,
194 factory: Arc<dyn ComponentFactory>,
195 ) -> SklResult<()> {
196 self.registry.register_factory(component_type, factory)
197 }
198
199 #[must_use]
201 pub fn pipeline_builder(&self) -> PipelineBuilder {
202 PipelineBuilder::new()
203 }
204
205 pub async fn execute_pipeline(
207 &self,
208 pipeline: Pipeline,
209 input_data: PipelineData,
210 ) -> SklResult<execution_engine::ExecutionResult> {
211 let context_id = "default_context";
212 self.execution_engine
213 .execute_pipeline(context_id, pipeline, input_data)
214 .await
215 }
216
217 #[must_use]
219 pub fn type_safe_composer<I, O>(&self) -> TypeSafeComposer<I, O>
220 where
221 I: CompositionType + Send + Sync + 'static,
222 O: CompositionType + Send + Sync + 'static,
223 {
224 TypeSafeComposer::new()
225 }
226
227 #[must_use]
229 pub fn functional_composer(&self) -> FunctionalComposer {
230 FunctionalComposer::new()
231 }
232
233 #[must_use]
235 pub fn algebraic_composer(&self) -> AlgebraicComposer {
236 AlgebraicComposer::new()
237 }
238
239 #[must_use]
241 pub fn higher_order_composer(&self) -> HigherOrderComposer {
242 HigherOrderComposer::new()
243 }
244
245 #[must_use]
247 pub fn get_statistics(&self) -> FrameworkStatistics {
248 FrameworkStatistics {
249 registry_stats: self.registry.get_statistics(),
250 dependency_stats: self.dependency_resolver.get_statistics(),
251 lifecycle_stats: self.lifecycle_manager.get_metrics().clone(),
252 execution_stats: self.execution_engine.get_statistics(),
253 }
254 }
255
256 #[must_use]
258 pub fn registry(&self) -> &Arc<GlobalComponentRegistry> {
259 &self.registry
260 }
261
262 #[must_use]
264 pub fn dependency_resolver(&self) -> &Arc<DependencyResolver> {
265 &self.dependency_resolver
266 }
267
268 #[must_use]
270 pub fn lifecycle_manager(&self) -> &Arc<LifecycleManager> {
271 &self.lifecycle_manager
272 }
273
274 #[must_use]
276 pub fn execution_engine(&self) -> &Arc<CompositionExecutionEngine> {
277 &self.execution_engine
278 }
279
280 #[must_use]
282 pub fn event_bus(&self) -> &Arc<std::sync::RwLock<EventBus>> {
283 &self.event_bus
284 }
285
286 pub async fn shutdown(&self) -> SklResult<()> {
288 self.execution_engine.shutdown().await?;
290
291 if let Ok(mut manager) = Arc::try_unwrap(self.lifecycle_manager.clone()) {
293 manager.shutdown_all_components()?;
294 }
295
296 Ok(())
297 }
298}
299
300#[derive(Debug, Clone)]
302pub struct FrameworkStatistics {
303 pub registry_stats: RegistryStatistics,
305 pub dependency_stats: DependencyStatistics,
307 pub lifecycle_stats: LifecycleMetrics,
309 pub execution_stats: ExecutionStatistics,
311}
312
313impl FrameworkStatistics {
314 #[must_use]
316 pub fn health_score(&self) -> f64 {
317 let registry_health = if self.registry_stats.total_registered_factories > 0 {
318 1.0
319 } else {
320 0.0
321 };
322 let dependency_health = self.dependency_stats.resolution_success_rate();
323 let execution_health = self.execution_stats.success_rate();
324
325 (registry_health + dependency_health + execution_health) / 3.0
326 }
327
328 #[must_use]
330 pub fn total_components(&self) -> u64 {
331 self.registry_stats.total_registered_factories
332 + self.dependency_stats.total_components
333 + self.lifecycle_stats.total_components as u64
334 }
335
336 #[must_use]
338 pub fn total_executions(&self) -> u64 {
339 self.execution_stats.total_executions
340 }
341}
342
343#[derive(Debug)]
345pub struct ComponentFrameworkBuilder {
346 registry_config: Option<RegistryConfiguration>,
348 dependency_config: Option<DependencyResolutionConfig>,
350 lifecycle_config: Option<LifecycleConfig>,
352 execution_config: Option<ExecutionEngineConfig>,
354}
355
356impl ComponentFrameworkBuilder {
357 #[must_use]
359 pub fn new() -> Self {
360 Self {
361 registry_config: None,
362 dependency_config: None,
363 lifecycle_config: None,
364 execution_config: None,
365 }
366 }
367
368 #[must_use]
370 pub fn with_registry_config(mut self, config: RegistryConfiguration) -> Self {
371 self.registry_config = Some(config);
372 self
373 }
374
375 #[must_use]
377 pub fn with_dependency_config(mut self, config: DependencyResolutionConfig) -> Self {
378 self.dependency_config = Some(config);
379 self
380 }
381
382 #[must_use]
384 pub fn with_lifecycle_config(mut self, config: LifecycleConfig) -> Self {
385 self.lifecycle_config = Some(config);
386 self
387 }
388
389 #[must_use]
391 pub fn with_execution_config(mut self, config: ExecutionEngineConfig) -> Self {
392 self.execution_config = Some(config);
393 self
394 }
395
396 #[must_use]
398 pub fn build(self) -> ComponentFramework {
399 ComponentFramework::new()
402 }
403}
404
405impl ComponentFramework {
407 pub fn create_sequential_pipeline(
409 &self,
410 stages: Vec<(&str, ComponentConfig)>,
411 ) -> SklResult<Pipeline> {
412 let mut builder = self.pipeline_builder();
413
414 for (component_type, config) in stages {
415 builder = builder.add_stage(component_type, config);
416 }
417
418 builder.build()
419 }
420
421 pub fn create_parallel_pipeline(&self, branches: Vec<ParallelBranch>) -> SklResult<Pipeline> {
423 self.pipeline_builder().add_parallel_stage(branches).build()
424 }
425
426 pub fn register_factories(
428 &self,
429 factories: Vec<(&str, Arc<dyn ComponentFactory>)>,
430 ) -> SklResult<()> {
431 for (component_type, factory) in factories {
432 self.register_component_factory(component_type, factory)?;
433 }
434 Ok(())
435 }
436
437 #[must_use]
439 pub fn discover_components(&self) -> Vec<ComponentTypeInfo> {
440 self.registry.discover_component_types()
441 }
442
443 #[must_use]
445 pub fn query_by_capability(&self, capability: &str) -> Vec<ComponentQuery> {
446 self.registry.query_components_by_capability(capability)
447 }
448}
449
450impl Default for ComponentFramework {
451 fn default() -> Self {
452 Self::new()
453 }
454}
455
456impl Default for ComponentFrameworkBuilder {
457 fn default() -> Self {
458 Self::new()
459 }
460}
461
462#[allow(non_snake_case)]
463#[cfg(test)]
464mod tests {
465 use super::*;
466 use std::collections::HashMap;
467
468 #[test]
469 fn test_framework_creation() {
470 let framework = ComponentFramework::new();
471 let stats = framework.get_statistics();
472
473 assert_eq!(stats.registry_stats.total_registered_factories, 0);
474 assert_eq!(stats.execution_stats.total_executions, 0);
475 }
476
477 #[test]
478 fn test_framework_builder() {
479 let builder = ComponentFrameworkBuilder::new()
480 .with_registry_config(RegistryConfiguration::default())
481 .with_dependency_config(DependencyResolutionConfig::default());
482
483 let framework = builder.build();
484 assert!(
485 framework
486 .registry()
487 .get_statistics()
488 .startup_time
489 .elapsed()
490 .as_secs()
491 < 1
492 );
493 }
494
495 #[test]
496 fn test_pipeline_builder() {
497 let framework = ComponentFramework::new();
498 let builder = framework.pipeline_builder();
499
500 assert!(builder.is_empty());
502 }
503
504 #[test]
505 fn test_framework_statistics() {
506 let framework = ComponentFramework::new();
507 let stats = framework.get_statistics();
508
509 assert_eq!(stats.total_components(), 0);
510 assert_eq!(stats.total_executions(), 0);
511 assert!(stats.health_score() >= 0.0 && stats.health_score() <= 1.0);
512 }
513
514 #[test]
515 fn test_composers() {
516 let framework = ComponentFramework::new();
517
518 let _functional = framework.functional_composer();
520 let _algebraic = framework.algebraic_composer();
521 let _higher_order = framework.higher_order_composer();
522 }
523
524 #[test]
525 fn test_component_discovery() {
526 let framework = ComponentFramework::new();
527 let components = framework.discover_components();
528
529 assert_eq!(components.len(), 0);
531 }
532}
533
534pub fn _module_docs() {}