Skip to main content
Every repository has layering rules. They live in a README, or in someone’s head, and nothing checks them — so they drift. A layering rule is also a question Bazel can answer: which targets in this layer depend on that layer? If the answer is empty, the rule holds.

Run it

Now break one. The repository ships a patch that makes lib/validate — a foundation library — depend on lib/log:
Exit code 1, which is all CI needs.

How it works

Open .aspect/policy.axl. The rules are a list:
A name, the layer being constrained, and what it may not depend on. One query each:
Read it left to right: everything that depends on the denied layer, narrowed to the constrained layer, minus the denied targets themselves — they depend on themselves, which is not interesting. Adding a rule is adding a tuple.

Your turn

Add a fourth rule: lib/ may not depend on internal/domain/.
It fails, and the failure is real — //lib/api imports domain packages. That is the point of writing rules down: you find out what your repository already does.
Next: stop asking Bazel questions, and start watching it work.