architecture-violation
A package depends on one that the project's declared architecture does not let it use.
- Group
- Code
- Runs
- Optional: run it with
ur lint --rule architecture-violation - Level
- warning
- Reads
- Every file
- Fix
- None: whether the code moves or the architecture changes is a design choice
Why
The [architecture] table in .ur/ur.toml declares the project's architecture at once: its components, each the packages its patterns name by directory or by name, layers, the components that are layers, highest first, and for each component the other components it uses, the packages outside the project it owns, and whether its packages are independent of each other. A package may depend on packages of its own component unless the component is independent, of the layers below its own, of the components it uses, and of no component; and on any package outside the project that no other component owns. Anything else is reported where its manifest declares it, and so is a chain through packages of no component, with the packages it passes. kinds limits the architecture to some kinds of dependency, such as ["normal", "build"] to leave test-only dependencies out. A pattern that names no package is reported in .ur/ur.toml, and with exhaustive = true so is every package of no component, where its manifest names it. A component's reason says what it is for, and each finding about its declaration repeats it. A pattern's segment <name> captures the directory it matches: packages of different captures of one component may not depend on each other, and a dependency between components that capture the same name keeps to one value of it.
The fix, as Ur suggests it: move what the package needs into a component it may use, or declare the use in [architecture] if the design allows it.
For agents
Before adding a dependency to a package, check the [architecture] table in .ur/ur.toml, and depend only on what the package's component may use; move code down instead of reaching up.
Example
.ur/ur.toml[architecture]
layers = ["web", "orders", "pricing"]
[architecture.components]
web = "web"
orders = "orders"
pricing = "pricing"
web/pyproject.toml[project]
name = "shop-web"
dependencies = ["shop-orders"]
orders/pyproject.toml[project]
name = "shop-orders"
dependencies = ["shop-pricing"]
pricing/pyproject.toml[project]
name = "shop-pricing"
dependencies = ["shop-web"]
pricing/shop_pricing/labels.pyfrom shop_web.format import money
def label(cents):
return money(cents)
$ ur lint --rule architecture-violation
warning[architecture-violation]: `shop-pricing` in `pricing` depends on `shop-web` in `web`, a higher layer; `pricing` may use no other component
--> pricing/pyproject.toml:3:1 `shop-pricing` depends on `shop-web`
= hint: move what the package needs into a component it may use, or declare the use in `[architecture]` if the design allows it
0 clone classes and 1 `architecture-violation` finding in 2 files
Example
.ur/ur.toml[architecture]
layers = ["cli", "core"]
[architecture.components]
cli = { packages = "crates/cli", owns = ["clap"] }
core = "crates/core"
crates/cli/Cargo.toml[package]
name = "shop-cli"
version = "0.1.0"
edition = "2024"
[dependencies]
clap = "4"
shop-core = { path = "../core" }
crates/core/Cargo.toml[package]
name = "shop-core"
version = "0.1.0"
edition = "2024"
[dependencies]
clap = "4"
crates/core/src/lib.rspub fn verbose() -> bool {
clap::Command::new("shop")
.arg(clap::arg!(--verbose))
.get_matches()
.get_flag("verbose")
}
$ ur lint --rule architecture-violation
warning[architecture-violation]: `shop-core` depends on `clap`, which only `cli` may use
--> crates/core/Cargo.toml:7:1 `shop-core` depends on `clap`
= hint: move what the package needs into a component it may use, or declare the use in `[architecture]` if the design allows it
0 clone classes and 1 `architecture-violation` finding in 2 files
Example
.ur/ur.toml[architecture.components]
features = { packages = "features/*", independent = true }
features/cart/package.json{
"name": "@shop/cart",
"dependencies": {
"@shop/search": "workspace:*"
}
}
features/search/package.json{
"name": "@shop/search"
}
features/cart/index.jsimport { suggest } from "@shop/search";
export function emptyCartMessage(query) {
return `Your cart is empty. Try ${suggest(query)}.`;
}
$ ur lint --rule architecture-violation
warning[architecture-violation]: `@shop/cart` in `features` depends on `@shop/search` in `features`, but the packages of `features` are independent
--> features/cart/package.json:4:5 `@shop/cart` depends on `@shop/search`
= hint: move what the package needs into a component it may use, or declare the use in `[architecture]` if the design allows it
0 clone classes and 1 `architecture-violation` finding in 2 files