Skip to content
sefluePublic

About

No description, website, or topics provided.

Resources

Stars

36 stars

Watchers

0 watching

Forks

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 arc 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

Hotspot Map

cargo arc hotspots shows which files are large and change often, the files that usually cost the most to maintain. It ranks them by lines of code times commits and draws the workspace as nested circles, sized by lines and colored by commits. cargo arc ui serves the map beside the arc diagram, so a hotspot can be looked up there to see what depends on it.

In the Editor

The arc 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. In the other direction, the arc diagram selects the node of the file the editor shows. 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 analyzed. 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 and Bun.

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

36 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages