bylaw-core 0.1.0

Analyzer-independent architecture graph and rule engine for Cargo Bylaw
Documentation

Cargo Bylaw

Cargo Bylaw is an architecture enforcement framework for Rust. It provides a Rust test API and a cargo bylaw command backed by the same semantic dependency graph and rule engine.

Rules can constrain dependencies between modules, workspace crates, and external crates, define allowed layer directions, and reject dependency cycles.

version = 1

[selectors.domain]
modules = ["shop::domain::**"]

[selectors.persistence]
modules = ["shop::persistence::**"]

[[rule]]
id = "domain-is-internal"
kind = "forbid-dependencies"
from = "domain"
to = "persistence"
scope = "actual"
cargo bylaw check

The same rule model is available from normal Rust tests:

use bylaw::prelude::*;

#[test]
fn architecture_is_valid() -> Result<(), Box<dyn std::error::Error>> {
    let graph = bylaw::analyzer::analyze_workspace(&Default::default())?;
    rules()
        .forbid_dependencies(
            "domain-is-internal",
            modules(["shop::domain::**"]),
            modules(["shop::persistence::**"]),
        )
        .actual_dependencies()
        .check(&graph)?
        .assert();
    Ok(())
}

See examples/model-boundaries for a complete domain, persistence, contract, API, and composition-root example.

Documentation site

The guide is an mdBook deployed through GitHub Pages. Build it locally with:

cargo install mdbook --version 0.5.4 --locked
mdbook serve --open

Documentation

License

Licensed under either of:

at your option.