codematrix-rust is a Rust CLI tool that scans a Rust crate and produces a code matrix model as JSON, Mermaid, or Graphviz DOT. The generated JSON model can be visualized with the Code Matrix viewer (hypernetix/codematrix).
- From source (this repository):
cargo build --releaseThis will build the codematrix-rust binary in target/release/.
Alternatively install it globally for your user:
cargo install --path .
codematrix-rust --help
The CLI expects the path to the crate root (the folder containing Cargo.toml) as the first positional argument.
Other options can appear before or after the path.
codematrix_rust <PATH_TO_CRATE_ROOT> [--out <OUTPUT_JSON>] [--format <json|mermaid|dot>] [--include-private]PATH_TO_CRATE_ROOT: required positional argument; path to the Rust crate to scan.--out: output file path for the generated JSON model (only used when--format json, default:codematrix_rust.json).--format: output format:json(default),mermaid, ordot.--include-private: include non-public items on a best-effort basis; by default only public items are modeled.
Examples:
# Generate a JSON code matrix for the current crate (see `codematrix_rust.json`)
codematrix-rust .
# Generate a JSON code matrix for another crate and write to a custom file
codematrix-rust /path/to/other/crate --out my_code_matrix.json
# Generate Mermaid class diagram to stdout
codematrix-rust . --format mermaid
# Generate Graphviz DOT to stdout including private items
codematrix-rust . --format dot --include-privateTo produce the JSON file that can be consumed by external tools:
-
Build the CLI (from this repo):
cargo build --release
-
Run the scanner against your crate (from anywhere):
/path/to/codematrix-rust/target/release/codematrix-rust <PATH_TO_CRATE_ROOT> --out codematrix_rust.json --format json
This creates
codematrix_rust.jsonin the current working directory.
The generated JSON model is designed to be consumed by the Code Matrix viewer.
You can use the viewer from the hypernetix/codematrix project to explore the graph:
- Repository: hypernetix/codematrix
Follow the instructions in that repository to load the codematrix_rust.json file and visualize your Rust codebase.
- Add official codematrix format extension and specification
- Add unit tests