| Crates.io | fob-graph |
| lib.rs | fob-graph |
| version | 0.5.0 |
| created_at | 2025-11-29 19:07:43.532664+00 |
| updated_at | 2025-12-29 18:19:23.721557+00 |
| description | Fob graph - Pure graph data structures for module dependency graphs |
| homepage | |
| repository | https://github.com/foxworth-uni/fob |
| max_upload_size | |
| id | 1957278 |
| size | 531,734 |
Pure graph data structures for module dependency graphs.
This crate provides the core graph primitives and ModuleGraph implementation without any I/O or analysis logic. It's designed to be lightweight and WASM-compatible.
Arc for efficient shared ownership┌─────────────────────────────────────────────────────────────┐
│ ModuleGraph │
│ (Arc-based, thread-safe, WASM-compatible) │
└────────────────────┬────────────────────────────────────────┘
│
┌────────────┼────────────┐
│ │ │
▼ ▼ ▼
┌───────────┐ ┌───────────┐ ┌───────────┐
│ Module │ │ Import │ │ Export │
│ (Node) │ │ (Edge) │ │ (Edge) │
└───────────┘ └───────────┘ └───────────┘
│ │ │
└────────────┼────────────┘
│
▼
┌──────────────────────┐
│ SymbolTable │
│ (Intra-file │
│ analysis) │
└──────────────────────┘
Add to your Cargo.toml:
[dependencies]
fob-graph = { path = "../fob-graph" }
use fob_graph::{ModuleGraph, Module, ModuleId, SourceType};
use std::path::PathBuf;
// Create a new graph
let graph = ModuleGraph::new()?;
// Add a module
let module_id = ModuleId::new("src/index.ts")?;
let module = Module::builder(module_id.clone(), PathBuf::from("src/index.ts"), SourceType::TypeScript)
.entry(true)
.build();
graph.add_module(module)?;
// Add dependencies
let utils_id = ModuleId::new("src/utils.ts")?;
graph.add_dependency(&module_id, &utils_id)?;
// Query the graph
let dependencies = graph.dependencies(&module_id)?;
println!("Dependencies: {:?}", dependencies);
use fob_graph::semantic::analyze_symbols;
use fob_graph::{SourceType, SymbolTable};
let source = r#"
const used = 42;
const unused = 100;
console.log(used);
"#;
let table: SymbolTable = analyze_symbols(source, "example.js", SourceType::JavaScript)?;
// Find unused symbols
let unused = table.unused_symbols();
println!("Unused symbols: {:?}", unused);
use fob_graph::ModuleGraph;
let graph: ModuleGraph = /* ... */;
// Find all circular dependency chains
let circular = graph.dependency_chains_to(&target_module_id)?;
for chain in circular {
if chain.has_cycle() {
println!("Circular dependency: {}", chain.format_chain());
}
}
The main graph structure. Provides methods for:
Represents a single module in the graph:
Tracks symbols within a single module:
The crate uses extension traits to add functionality without modifying core types:
use fob_graph::ModuleGraph;
// Extension traits are automatically available
let unused_exports = graph.unused_exports()?;
let statistics = graph.statistics()?;
let circular = graph.find_circular_dependencies()?;
ModuleGraph uses Arc internally for efficient shared ownership. Multiple threads can safely:
For modifications, use appropriate synchronization (e.g., Mutex or RwLock).
The crate is designed to work in WASM environments:
wasm-bindgen and wasm-packSee the examples/ directory for more detailed usage:
basic_graph.rs - Simple graph constructionsymbol_analysis.rs - Symbol table usagedependency_analysis.rs - Finding dependenciesconcurrent_access.rs - Thread-safe operationsmodule.rs, import.rs, export.rs, module_id.rsmemory/ directorysemantic/ directory (symbol extraction)symbol/ directory (intra-file analysis)quality/ directory (metrics calculation)collection.rs (parsing and collection)See the workspace root for license information.
Contributions are welcome! Please see the workspace contributing guidelines.