Skip to main content

drasi_lib/component_graph/
mod.rs

1// Copyright 2025 The Drasi Authors.
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15//! Component Dependency Graph — the single source of truth for DrasiLib configuration.
16//!
17//! The `ComponentGraph` maintains a directed graph of all components (Instance, Sources,
18//! Queries, Reactions, BootstrapProviders, IdentityProviders) and their bidirectional
19//! relationships. The DrasiLib instance itself is the root node.
20//!
21//! All three managers (SourceManager, QueryManager, ReactionManager) share the same
22//! `Arc<RwLock<ComponentGraph>>`. Managers register components in the graph **first**
23//! (registry-first pattern), then create and store runtime instances. The graph is the
24//! authoritative source for component relationships, dependency tracking, and lifecycle
25//! events.
26//!
27//! # Event Emission
28//!
29//! The graph emits [`ComponentEvent`]s via a built-in `broadcast::Sender` whenever
30//! components are added, removed, or change status. Subscribers (ComponentGraphSource,
31//! EventHistory, external consumers) receive events directly from the graph.
32//!
33//! # Status Update Channel
34//!
35//! Components report status changes via a shared `mpsc::Sender<ComponentUpdate>`.
36//! A dedicated graph update loop (spawned externally) receives from this channel and
37//! applies updates to the graph, emitting broadcast events. This decouples components
38//! from the graph lock — status reporting is fire-and-forget.
39//!
40//! Structural mutations (`add_component`, `remove_component`, `add_relationship`) and
41//! command-initiated transitions (`Starting`, `Stopping`) are applied directly by
42//! managers, which hold the graph write lock on the cold path.
43
44mod graph;
45mod node;
46mod transaction;
47mod wait;
48
49#[cfg(test)]
50mod tests;
51
52pub use graph::*;
53pub use node::*;
54pub use transaction::*;
55pub use wait::*;