Skip to main content

fabryk_graph/
lib.rs

1//! Knowledge graph infrastructure for Fabryk.
2//!
3//! This crate provides graph storage, traversal algorithms, and
4//! persistence using petgraph and optional rkyv caching.
5//!
6//! # Features
7//!
8//! - `graph-rkyv-cache`: Enable rkyv-based graph persistence with
9//!   content-hash cache validation
10//! - `test-utils`: Export mock types for testing in downstream crates
11//!
12//! # Key Abstractions
13//!
14//! - `GraphExtractor` trait: Domain implementations provide this to
15//!   extract nodes and edges from content files
16//! - `Relationship` enum: Common relationship types with `Custom(String)`
17//!   for domain-specific relationships
18//! - `NodeType` enum: Distinguishes domain vs user-query nodes
19//! - `GraphData`: Core graph structure with runtime mutation support
20
21pub mod algorithms;
22pub mod builder;
23pub mod extractor;
24pub mod persistence;
25pub mod query;
26pub mod stats;
27pub mod types;
28pub mod validation;
29
30// Re-exports — algorithms
31pub use algorithms::{
32    CentralityScore, NeighborhoodResult, PathResult, PrerequisitesResult, calculate_centrality,
33    find_bridges, get_related, neighborhood, prerequisites_sorted, shortest_path,
34};
35
36// Re-exports — builder
37pub use builder::{BuildError, BuildStats, ErrorHandling, GraphBuilder, ManualEdge};
38
39// Re-exports — extractor
40pub use extractor::GraphExtractor;
41
42// Re-exports — persistence
43pub use persistence::{
44    GraphMetadata, SerializableGraph, is_cache_fresh, load_graph, load_graph_from_str, save_graph,
45};
46
47// Re-exports — query
48pub use query::{
49    CategoryCount, EdgeInfo, GraphInfoResponse, NeighborInfo, NeighborhoodResponse, NodeSummary,
50    PathResponse, PathStep, PrerequisiteInfo, PrerequisitesResponse, RelatedConceptsResponse,
51    RelatedGroup, RelationshipCount,
52};
53
54// Re-exports — stats
55pub use stats::{DegreeDirection, GraphStats, compute_stats, quick_summary, top_nodes_by_degree};
56
57// Re-exports — types
58pub use types::{Edge, EdgeOrigin, GraphData, Node, NodeType, Relationship};
59
60// Re-exports — validation
61pub use validation::{ValidationIssue, ValidationResult, is_valid, validate_graph};
62
63#[cfg(any(test, feature = "test-utils"))]
64pub use extractor::mock::{MockEdgeData, MockExtractor, MockNodeData};
65
66#[cfg(feature = "graph-rkyv-cache")]
67pub use persistence::rkyv_cache;