Skip to content

Repository files navigation

cargo-arc

Crates.io CI

cargo arc draws a Cargo workspace as a collapsible arc diagram in SVG, a tree of your crates and their modules connected by arcs that trace the use dependencies between them. cargo arc check holds the same workspace against architecture rules you write down, and fails the build when one breaks.

Installation

cargo install cargo-arc

Requires a stable Rust toolchain.

Quick Start

# In any Cargo workspace:
cargo arc -o deps.svg   # the diagram
cargo arc check         # the architecture rules

Open the generated SVG in a browser.

What You See

Your workspace shows up as a tree — crates with their modules nested inside. Arcs between nodes show where dependencies exist.

  • Boxes — crates and modules, nested by hierarchy
  • Arcs — dependencies between any two nodes
  • Collapse a node to fold its children — individual dependencies merge into summary arcs
  • Select a node or arc to highlight its relationships
  • Cycles — circular dependencies are detected and highlighted

In the Editor

The diagram can live beside the code. cargo arc ui serves it for an editor plugin, and a click on a node or a reference opens the file in the editor. Plugins exist for Neovim, VS Code and RustRover.

Architecture Rules

Circular dependencies are forbidden by default, and a workspace without a rules file is checked against that one rule. arc-rules.toml states which crate may depend on which, which modules or crates may never depend directly on which, and where circular dependencies are permitted after all. cargo arc check reports what it finds, and a reported error makes it exit non-zero, so it belongs in CI next to the test suite.

A workspace that has grown for years rarely comes out clean on the first run. cargo arc check --generate-baseline freezes what exists today, so the run turns green and reports everything added after it.

What the Run Does Not See

cfg attributes are currently not evaluated, so the graph is the union over all configurations. A module under #[cfg(feature = "hydrate")] or #[cfg(target_os = "windows")] is walked on any machine and under any feature set. Two modules whose attributes exclude each other are currently reported as one tangle, although the reported circular dependency exists in no build. Modules under #[cfg(test)] are the exception and stay out unless --include-tests is passed.

A mod declaration inside a macro invocation is not analysed. Where a crate writes feature_gate! { pub mod runtime; }, runtime and every module below it are missing from the graph, and a rule naming it reports unmatched-pattern.

A pattern reaches the crates under analysis and the modules in them. A crate the workspace only depends on is not a node, so a rule about a third-party crate matches nothing.

A green run says the rules held over the modules the run walked, and a module a macro declares is not one of them.

Documentation

Similar Projects

  • cargo tree — built-in textual dependency tree (crate-level)
  • cargo-modules — module tree and dependency visualization
  • cargo-depgraph — crate-level dependency graph as DOT with color-coded dependency kinds
  • cargo-coupling — coupling analysis based on Khononov's framework

References

The arc diagram layout is inspired by Martin Wattenberg's Arc Diagrams: Visualizing Structure in Strings (IEEE InfoVis 2002).

Development

See docs/ARCHITECTURE.md for project structure and architecture decision records.

Requires Just as task runner.

just build
just test    # Rust + JS
just lint    # clippy + format check
just fmt

License

MIT OR Apache-2.0

About

No description, website, or topics provided.

Resources

Stars

34 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages