๐ ๏ธ CI and Coverage
- CI workflow:
.github/workflows/ci.yml- Runs format check, clippy (deny warnings), build, tests, docs.
- Coverage workflow:
.github/workflows/coverage.yml- Installs
cargo-tarpaulinand uploadslcov.info.
- Installs
Run coverage locally:
๐ rust-relations-explorer โ Rust Knowledge Graph System
A fast, lightweight tool to parse Rust projects into a knowledge graph and run insightful queries over code structure. Generate DOT/SVG visualizations, persist graphs to JSON, and explore code relationships via a clean CLI. โจ
โก Quick install
๐ Links
- crates.io: @web https://crates.io/crates/rust-relations-explorer
- docs.rs: @web https://docs.rs/rust-relations-explorer
- CI status: @web https://github.com/automataIA/rust-relations-explorer/actions/workflows/ci.yml
- Releases: @web https://github.com/automataIA/rust-relations-explorer/releases
โจ Features
- โ
Graph builder from source (
KnowledgeGraph::build_from_directory) - โ
Incremental builds with cache (reuse unchanged files;
--no-cache,--rebuild) - โ Relationship analysis (imports, heuristics for calls)
- โ JSON persistence (save/load)
- โ DOT generation with styling (rankdir, splines, rounded, theme, clusters, legend)
- โ SVG enhancement (interactive highlights, clickable nodes)
- โ
CLI powered by
clap - โ
Queries
connected-filesโ files related to a target fileitem-infoโ show item metadata, code, and relations by ItemIdfunction-usageโ callers/callees of a functioncyclesโ detect file-level cyclespathโ shortest path between two fileshubsโ top-N files by degree centrality (in/out/total)module-centralityโ top-N modules (directories) by degree centralitytrait-implsโ list types and files implementing a given trait
- ๐ง Pretty table output for terminal
- ๐ง Advanced analyses and config system
๐งฐ Installation
Install from crates.io:
Build from source:
# from repo root
Run checks and tests:
๐ Usage
Build a graph from a Rust project and export artifacts:
# Build and save artifacts (uses cache by default)
# Force parsing all files without using cache
# Rebuild cache from scratch (clears previous cache file)
# Apply options from a configuration file
# Bypass ignore rules (include files even if ignored)
Run queries (builds the graph on-the-fly unless --graph is provided):
# Connected files for a given file
# Show detailed info for an item by ItemId (text or JSON)
# Function usage: who calls `foo` (callers) or who does `foo` call (callees)
# Detect cycles
# Shortest path between files
# Hubs: top-N by degree centrality
# Module centrality: top-N modules by degree
# Trait implementations for Display
# Any query can also bypass ignore rules when building on-the-fly
Use a prebuilt graph for faster queries:
๐ Examples
Run the included examples to see the library API in action:
# Build all examples
# Basic graph build and stats
# Print connected files to a target (defaults to src/lib.rs if present)
Example sources:
examples/basic_build.rsexamples/query_connected.rs
๐งญ Typical Workflows
-
Build and save graph to JSON
-
Programmatic DOT/SVG generation
# Produces graph.dot and graph.svg- Requires Graphviz
dotexecutable on PATH. Install via your OS package manager. - Options like clusters, theme, rankdir, splines are in
visualization::DotOptionsandvisualization::SvgOptions.
- Requires Graphviz
-
Bypass ignore rules for one-off analyses
-
Save and load graph JSON
# Save # Query using saved graph (faster)
๐ข Releasing
Create a GitHub release using notes from CHANGELOG.md via GitHub CLI:
# Mark as latest and use notes from CHANGELOG.md [0.1.0]
# Without marking latest
Requirements:
-
GitHub CLI installed and authenticated:
- gh auth login -w
-
Existing tag
v<version>pushed (e.g.,v0.1.0). -
CHANGELOG.mdincludes a section like## [0.1.0] - YYYY-MM-DD. -
Programmatic save/load JSON
use KnowledgeGraph; use CacheMode;Note:
KnowledgeGraphimplementsserde::Serialize/Deserialize.
๐งช CLI Quick Examples
Build graph with DOT and SVG outputs:
Connected files for a target file (JSON):
Function usage: callers of function foo (JSON):
Shortest path between two files (JSON):
Top hubs by total degree (top 10):
Top modules (directories) by in-degree (top 5):
Types implementing a trait (e.g., Display):
๐ง Caching Modes
- Default (Use) โ reuse unchanged files from
.knowledge_cache.jsonand only reparse changed/added files. - --no-cache (Ignore) โ do not reuse cache; parse all files, then write a fresh cache at end.
- --rebuild (Rebuild) โ remove existing cache file first, then parse all files and write a new cache.
Cache file location: .knowledge_cache.json at the project root passed to --path.
๐๏ธ Ignore Patterns
- File discovery respects
.gitignoreand.ignorefiles. Parent directories are traversed, so nested ignore files apply. - Global git excludes are intentionally disabled for determinism.
- This affects which
.rsfiles are scanned and parsed bybuildand on-the-fly builds forquery.
Determinism: The CLI now passes ignore behavior explicitly to the file walker. This removes reliance on ambient environment state during normal operation.
Examples:
# src/.ignore (or .gitignore)
ignored.rs
# Nested ignore (src/a/.ignore)
skip.rs
# Negation pattern (src/.gitignore)
*.rs
!keep.rs
Bypass ignores (use with care):
# Preferred: CLI flag (explicit)
# Optional: environment variable (legacy/compat)
# Still supported, but not required since the CLI now passes the flag directly.
KNOWLEDGE_RS_NO_IGNORE=1
โ๏ธ Configuration
You can provide a TOML config with --config <path> for both build and all query subcommands.
- Precedence:
- CLI flags override binary defaults.
- Config values are applied on top of CLI defaults to provide convenient project-wide settings (as implemented, config values for DOT/SVG and query format will be applied even if CLI uses defaulted values).
Example rust-relations-explorer.toml:
[]
= true
= false
= "dark" # "light" | "dark"
= "TB" # "LR" | "TB"
= "ortho" # "curved" | "ortho" | "polyline"
= true
[]
= true
[]
= "json" # "text" | "json"
๐ References
- @web https://doc.rust-lang.org/
- @web https://graphviz.org/
- @web https://crates.io/crates/clap
- @web https://serde.rs/
- @web https://docs.rs/regex
๐ค Contributing
Issues and PRs are welcome! Please run cargo fmt, cargo clippy, and cargo test before submitting.
๐ License
Licensed under either of
- Apache License, Version 2.0, see
LICENSE-APACHE - MIT license, see
LICENSE-MIT
at your option.