Weavatrix Graph
weavatrix-graph is a small Rust library for deterministic, typed,
evidence-carrying graphs. It is the graph foundation of Weavatrix, but it is
usable by repository analyzers, architecture tools, dependency explorers, and
other applications without depending on Weavatrix itself.
The crate owns graph integrity and serialization. It does not walk files, parse programming languages, execute commands, access the network, or provide an MCP/CLI transport.
Properties
- typed nodes and edges with custom extension kinds;
- strongly typed, non-empty node identifiers;
- source spans, optional language labels, evidence kind, confidence, and extractor provenance;
- structured node and edge attributes for parser-specific metadata;
- deterministic node and edge order independent of insertion order;
- idempotent insertion of identical nodes and edges;
- rejection of conflicting nodes, dangling edges, and invalid source spans;
- validated deserialization that cannot bypass graph invariants;
- compatibility conversion from Weavatrix's legacy
{ nodes, links }graph; - no unsafe code and one runtime dependency:
serde.
Example
use ;
let repository = new?;
let file = new?;
let mut builder = new;
builder.add_node?;
builder.add_node?;
builder.add_edge?;
let graph = builder.build?;
assert_eq!;
assert_eq!;
# Ok::
Extension Kinds
Known relation and node kinds are enum variants. Ecosystem-specific kinds remain
forward-compatible through Custom values. Language taxonomies intentionally
belong to analyzers, not the graph core; nodes carry language as a validated
string label.
use NodeKind;
let kind = custom?;
assert_eq!;
# Ok::
Weavatrix compatibility
The core graph format intentionally keeps canonical nodes and edges, but the
crate can ingest the current JavaScript Weavatrix { nodes, links } shape:
use ;
let legacy: LegacyGraph = from_str?;
let graph: Graph = legacy.into_graph?;
assert_eq!;
# Ok::
Legacy metadata such as line, compileOnly, typeOnly, specifier,
usage, source_range, and unknown extension fields is preserved as structured
attributes.
Quality Gates
Local checks:
The test suite includes architecture and duplicate-contract ratchets: source
files stay below 300 lines, model and kind remain focused folder modules,
runtime dependencies remain limited, and canonical kind strings cannot collide.
CI also runs measured Rust coverage with cargo-tarpaulin and fails below 85%.
Weavatrix architecture verification is backed by .weavatrix/architecture.json.
License
MIT