rust-crate-architecturelisted
Install: claude install-skill po4yka/rust-skills
# Rust Crate Architecture
This skill covers the shape of a Rust workspace: which crates exist, which
crate is allowed to depend on which, and how modules are laid out inside a
crate. `cargo-workflows` covers the mechanics of the manifests, profiles, and
build commands. Use both together.
## Establish ground truth first
A workspace changes faster than its documentation. Before you move any crate,
read the current graph from cargo, not from a diagram.
```bash
# Authoritative machine-readable inventory of the workspace members.
cargo metadata --locked --no-deps --format-version 1
# Forward dependencies of one crate: what it is allowed to know.
cargo tree --locked -p <crate> -e normal
# Reverse dependencies of one crate: who is allowed to know it.
# Pass the crate as the value of -i, and keep --workspace, or the inverted
# tree is scoped to that crate alone and shows no dependents.
cargo tree --locked --workspace -i <crate>
```
Rules:
- Treat any hand-written architecture document as stale until `cargo metadata`
agrees with it. Fix the document in the same change that moves a crate.
- Do not hardcode a crate count in documentation. Derive it from
`cargo metadata`.
- Run every command from the directory that holds the workspace `Cargo.toml`,
or pass `--manifest-path <workspace-root>/Cargo.toml`.
## The layer model
Give every crate exactly one layer. The layer says what the crate is allowed to
know. Names of layers matter less than the direction between them.
| Lay