1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//! # Link Graph Analysis
//!
//! Link graph implementation for Obsidian vault relationships using petgraph.
//!
//! Provides:
//! - Directed graph of vault files and links
//! - Link resolution (wikilinks, aliases, folder paths)
//! - Backlink queries
//! - Related notes discovery (BFS)
//! - Orphan detection
//! - Cycle detection
//! - Graph statistics
//! - Vault health analysis
//! - Broken link detection
//!
//! ## Quick Start
//!
//! ```no_run
//! use turbovault_graph::prelude::*;
//! use std::path::PathBuf;
//! use std::sync::Arc;
//!
//! #[tokio::main]
//! async fn main() -> Result<()> {
//! // Create a new link graph
//! let graph = LinkGraph::new();
//!
//! // Add notes to the graph
//! let note1 = PathBuf::from("notes/note1.md");
//! let note2 = PathBuf::from("notes/note2.md");
//! graph.add_node(¬e1).await?;
//! graph.add_node(¬e2).await?;
//!
//! // Create links between notes
//! graph.add_link(
//! ¬e1,
//! ¬e2,
//! turbovault_core::models::LinkType::WikiLink
//! ).await?;
//!
//! // Get graph statistics
//! let stats = graph.stats().await?;
//! println!("Total nodes: {}", stats.total_nodes);
//! println!("Total edges: {}", stats.total_edges);
//!
//! // Analyze vault health
//! let health = graph.analyze_health().await?;
//! println!("Health score: {}", health.health_score);
//!
//! Ok(())
//! }
//! ```
//!
//! ## Core Concepts
//!
//! ### Nodes and Edges
//! - **Nodes**: Represent vault files (notes)
//! - **Edges**: Represent links between files
//! - **Directed**: Links flow from source to target
//!
//! ### Graph Operations
//!
//! - **Backlinks**: Find all notes linking to a given note
//! - **Forward Links**: Find all notes linked from a given note
//! - **Related Notes**: Discover related notes through BFS traversal
//! - **Orphans**: Find isolated notes with no links in or out
//!
//! ### Vault Health Metrics
//!
//! The health analyzer provides:
//! - **Health Score**: Overall vault connectivity (0-100)
//! - **Connectivity Rate**: Percentage of connected notes
//! - **Link Density**: Ratio of existing links to possible links
//! - **Broken Links**: Links to non-existent targets
//! - **Orphaned Notes**: Isolated notes with no relationships
//!
//! ## Advanced Usage
//!
//! ### Finding Broken Links
//!
//! ```no_run
//! use turbovault_graph::prelude::*;
//!
//! # async fn example() -> Result<()> {
//! let graph = LinkGraph::new();
//! let health = graph.analyze_health().await?;
//! let broken_links = health.broken_links;
//! for link in broken_links {
//! println!("Broken: {} -> {}", link.source_file.display(), link.target);
//! }
//! # Ok(())
//! # }
//! ```
//!
//! ### Graph Statistics
//!
//! ```no_run
//! use turbovault_graph::prelude::*;
//!
//! # async fn example() -> Result<()> {
//! let graph = LinkGraph::new();
//! let stats = graph.stats().await?;
//! println!("Avg links per node: {}", stats.avg_degree);
//! println!("Density: {}", stats.density);
//! println!("Cycles: {}", stats.cycle_count);
//! # Ok(())
//! # }
//! ```
//!
//! ## Modules
//!
//! - [`graph`] - Main LinkGraph implementation
//! - [`health`] - Vault health analysis
//!
//! ## Performance Characteristics
//!
//! Built on `petgraph` for optimal performance:
//! - Graph construction: O(n + m) where n = nodes, m = edges
//! - Backlink queries: O(degree) with caching
//! - Orphan detection: O(n)
//! - Cycle detection: O(n + m)
//! - Health analysis: O(n + m)
pub use ;
pub use ;
pub use *;