๐ ๏ธ 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:
Defaults & name lookup (quick examples)
# Use env defaults (see Configuration section)
# Name lookup without ItemId
# Short flags and defaults (local dev via cargo)
# Explicit short flags
# Using environment defaults (omit -p and -f)
# Increase verbosity (-v, -vv, -vvv)
# Quiet mode suppresses non-essential logs
# 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 (positional <file>)
# Show detailed info for an item by ItemId (text or JSON)
# Name-only lookup (no ItemId needed)
# Prefer current crate matches; if ambiguous, CLI lists candidates and hints how to disambiguate.
# Narrow by kind to avoid ambiguity (kinds: module|function|struct|enum|trait|impl|const|static|type|macro)
# Example disambiguation flow (pseudo):
# > Multiple items named 'createIcons' were found. Use --kind or --item-id to disambiguate.
# > Candidates:
# > - fn:createIcons:6 src/a.rs
# > - fn:createIcons:12 src/b.rs
# Then run with --kind function or the exact --item-id shown above.
# 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
Output controls (quiet/verbose, pagination)
- Quiet mode suppresses non-essential stderr/info logs:
-
Increase verbosity with repeated
-v(e.g.,-v,-vv,-vvv). Defaults to concise output. -
Paginate large result sets with
--offsetand--limit(supported by all queries exceptitem-info):
# First page (10 rows)
# Next page (rows 10..20)
# JSON output is also paginated by the same flags
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 (highest to lowest):
- CLI flags
- Environment variables
- Config file (
--config) - Binary defaults
Notes:
- Config only backfills when a value is still at its default. It never overwrites values provided by CLI flags or env vars.
- Currently supported config keys: DOT/SVG options for
build, and default query output format for all queries.
Example rust-relations-explorer.toml:
[]
= true
= false
= "dark" # "light" | "dark"
= "TB" # "LR" | "TB"
= "ortho" # "curved" | "ortho" | "polyline"
= true
[]
= true
[]
= "json" # "text" | "json"
Environment variables
RRE_PATHโ default project root for all commands with--pathRRE_GRAPHโ default graph JSON for query subcommandsRRE_FORMATโ default output format for queries (textorjson)
Examples:
# Use a default project root and JSON output for queries
# Point queries to a prebuilt graph by default
# Now flags can be omitted
๐ Shell completions
Generate completion scripts with the built-in subcommand and install them in your shell's completion directory.
-
Bash (user-level):
# If directory doesn't exist, create it and re-source bashrcSystem-wide (requires sudo):
-
Zsh:
fpath+=(/.zsh/completions) && -
Fish:
-
PowerShell (Windows, current session):
rust-relations-explorer completions powershell | Out-String | Invoke-ExpressionPersist for all sessions (PowerShell profile):
$path = "$HOME/.config/powershell/rust-relations-explorer.ps1" rust-relations-explorer completions powershell > $path Add-Content -Path $PROFILE -Value ". $path" -
Elvish:
To test without installing, you can print to stdout:
๐ 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.