cadi_core/graph/
mod.rs

1//! Merkle DAG Graph Store
2//!
3//! Stores chunks and their relationships for O(1) dependency queries.
4//! This is the core data structure that makes CADI efficient for agents.
5//!
6//! ## Architecture
7//!
8//! The graph store uses sled (an embedded database) to maintain:
9//! - **Chunk metadata**: Core information about each atom
10//! - **Forward edges**: chunk -> [things that depend on it]
11//! - **Reverse edges**: chunk -> [things it depends on]
12//! - **Symbol index**: symbol_name -> chunk_id for fast lookups
13//!
14//! ## Example
15//!
16//! ```rust,ignore
17//! use cadi_core::graph::{GraphStore, GraphNode, EdgeType};
18//!
19//! let store = GraphStore::open(".cadi/graph")?;
20//!
21//! // Add a chunk
22//! store.insert_node(GraphNode {
23//!     chunk_id: "chunk:sha256:abc123...".to_string(),
24//!     content_hash: "abc123...".to_string(),
25//!     symbols_defined: vec!["calculate_tax".to_string()],
26//!     symbols_referenced: vec!["TaxRate".to_string()],
27//!     ..Default::default()
28//! })?;
29//!
30//! // Query dependencies in O(1)
31//! let deps = store.get_dependencies("chunk:sha256:abc123...")?;
32//!
33//! // Find who depends on this chunk
34//! let dependents = store.get_dependents("chunk:sha256:abc123...")?;
35//!
36//! // Resolve a symbol to its defining chunk
37//! let chunk = store.find_symbol("calculate_tax")?;
38//! ```
39
40pub mod store;
41pub mod node;
42pub mod edge;
43pub mod query;
44
45pub use store::GraphStore;
46pub use node::GraphNode;
47pub use edge::{Edge, EdgeType};
48pub use query::{GraphQuery, QueryNode, QueryResult, TraversalDirection};
49
50/// Re-export common error types
51pub use crate::error::CadiError;