MCPcopy Index your code
hub / github.com/PSeitz/dep_graph_rs

github.com/PSeitz/dep_graph_rs @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
101 symbols 246 edges 11 files 8 documented · 8%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

dep_graph_rs

dep_graph_rs generates a dependency graph for the internal modules of a Rust crate.

It uses the syn crate to parse Rust source code and analyzes use crate::... statements to build a directed graph of dependencies between modules or files. The graph is then output in the DOT language.

Note: This tool visualizes dependencies within a single crate. It does not show dependencies on external crates from Cargo.toml.

Example

One of the main motivations for this tool is to assist refactoring and understand dependencies.

My use case is to analyze the dependencies of a module before extracting it into a separate crate. In this case, extracting tantivy/src/directory into a new tantivy-directory crate.

In this case we want to see on which other modules the directory module depends:

dep_graph_rs tantivy_folder --source "directory.*" > tantivy_directory_deps.dot

Fantastically beautiful graph for the tantivy 'directory' module

Features

  • Generates dependency graphs from Rust source code.
  • Outputs in DOT format for use with Graphviz.
  • Group dependencies by file or by module.
  • Filter the graph by source, destination, or item (e.g., function name).
  • Use an advanced query language with AND/OR/NOT to filter edges.
  • Clusters nodes by their root module for better readability.

Usage

You can install the tool using cargo:

cargo install dep_graph_rs

To generate a dependency graph, run the tool with the path to your crate's root (src/lib.rs or src/main.rs):

dep_graph_rs <path-to-your-project|path-to-entry-file> > graph.dot

This will output the graph in DOT format to graph.dot.

Rendering the Graph

You can render the generated graph.dot file in a few ways:

  1. Online Viewer: Paste the content of graph.dot into an online viewer like GraphvizOnline.
  2. Local Installation: If you have Graphviz installed locally, you can use the dot command to render the graph to an image: bash dot -Tpng graph.dot -o graph.png

Options

  • --mode <file|module>: Group the graph by file or by module (default: module).
  • --source <regex>: Filter by source module/file.
  • --destination <regex>: Filter by destination module/file.
  • --item <regex>: Filter by the name of the imported item (e.g., a function or struct).
  • --query, -q <expr>: Advanced query. Example: source:*agg* AND destination:*segment*. Supports AND, OR, NOT, parentheses, and fields source|destination|item|any. * is a wildcard; quotes allow spaces. The arrow shorthand a->b expands to source:a AND destination:b.

For example, to only show dependencies originating from the graphics module:

dep_graph_rs ./test_proj1 --source "graphics" > graph.dot

TODO

  • [ ] Better support * imports
  • [ ] Plain Output for cli usage
  • [ ] Go more into rust_analyzer territory, e.g. find_references etc.?

Core symbols most depended-on inside this repo

skip_whitespace
called by 15
src/query.rs
add
called by 14
src/graph.rs
parse_to_string
called by 14
src/query.rs
is_match
called by 9
src/main.rs
push
called by 7
src/module.rs
consume_literal
called by 7
src/query.rs
check_edge
called by 6
src/main.rs
bump
called by 6
src/query.rs

Shape

Function 48
Method 40
Class 10
Enum 3

Languages

Rust100%

Modules by API surface

src/query.rs42 symbols
src/main.rs35 symbols
src/graph.rs12 symbols
src/module.rs7 symbols
test_proj1/src/mod3.rs2 symbols
test_proj1/src/mod2/mod.rs1 symbols
test_proj1/src/mod1/mod.rs1 symbols
test_proj1/src/graphics/plattform/ps1.rs1 symbols

For agents

$ claude mcp add dep_graph_rs \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact