adr-drift turns your architecture decisions into tests: define layers and constraints once, and adr-drift check fails CI when the code drifts from them.
pip install git+https://github.com/calasdan-sketch/adr-drift && adr-drift init
Needs Python 3.10 or newer. Standard library only. Not on PyPI yet; install from GitHub as above, or run python3 -m adr_drift from a checkout.
Real output from a small throwaway repo with one rule (forbid-import: handlers -> db.drivers), after adr-drift init:
$ adr-drift check
✗ 1 architecture violation(s):
src/handlers/api.py
src/handlers/api.py:1: imports src.db.drivers
rule: handlers must not import db.drivers (arch.yaml)
(exit 1)
- Language-agnostic. Python is checked exactly with
ast; JS/TS, Go, Rust, Java, Ruby and PHP use a heuristic import extractor (see Languages: exact support). - Rules live next to the decisions. Write them in
arch.yamlor in any ADR's## Constraintssection. A rule that does not parse is an error, never silently dropped. - Adoptable on a messy repo.
baselinegrandfathers existing violations, anddrift --since REFreports only what a change introduced.
The problem
"The moment an ADR gets merged, it decays into a passive historical record unless something mechanical forces it to stay alive."
Developers, and now AI coding agents, merge boundary violations because nothing checks decisions against code. ArchUnit is built for Java and deptrac for PHP (as of November 2026; ports and similar tools exist for other languages). ADR Drift covers several languages from one rule file, runs repo-local and is CI-friendly; only Python imports are checked exactly.
Quickstart
pip install git+https://github.com/calasdan-sketch/adr-drift # provides `adr-drift`
cd your-repo
adr-drift init # scaffold arch.yaml + sample ADR from folder layout
# enable a rule in arch.yaml and/or add ## Constraints to your ADRs
adr-drift check # verify; exit 1 on violations (CI-ready)
# repo already has legacy violations? grandfather them, then enforce:
adr-drift baseline # record current violations
adr-drift check --baseline .adr-baseline.json
Or run without installing: python3 -m adr_drift from the repo root (use it in place of adr-drift above).
Limits up front
- A repo with no rules at all fails (exit 2): a green check that enforces nothing is worse than a red one. Use
--allow-emptywhile adopting. - Only Python imports are exact. Every other language uses a heuristic extractor: path aliases, computed paths and macros are not seen (see Limitations).
- Rules are only as good as the constraints you write;
initscaffolds layers and writes no rule for you. driftneeds a git repository with enough history.
Commands
| Command | What it does |
|---|---|
init |
Infer layers from folder layout, write arch.yaml + sample ADR + index (a README.md of yours is kept) |
check |
Verify the repo against arch.yaml + every ADR's ## Constraints (--baseline FILE grandfathers recorded violations; --strict fails on warnings; --allow-empty accepts a repo with no rules) |
baseline |
Write current violations to .adr-baseline.json (default) for check --baseline |
drift --since HEAD~5 |
Report violations introduced between a git ref and HEAD, plus violations fixed in that range (pre-existing ones ignored) |
new "title" |
Create the next-numbered ADR from a template |
index |
Regenerate the ADR index (docs/adr/README.md); a README.md adr-drift did not write is left alone unless you pass --force |
Every command takes --root DIR (the repository; default: the working
directory) and --adr-dir DIR (where the ADRs are, see below), before or
after the command name: adr-drift --root app check and
adr-drift check --root app are the same.
The constraint DSL
Rules live in arch.yaml and in any ADR's ## Constraints section:
forbid-import: handlers -> db.drivers # layering: handlers may not import drivers
forbid-pattern: src/**.py !~ \beval\( # no eval() anywhere in src/
require-pattern: src/handlers/**.py =~ authenticate\( # handlers must authenticate
from/to match layer names or module prefixes (db.drivers matches
db.drivers.pg); * wildcards supported. Comments start with #.
Python relative imports resolve against the file's package
(from ..db.drivers import pg in src/handlers/ is src.db.drivers.pg),
and from app.db import drivers counts as importing app.db.drivers.
JS/TS relative specifiers resolve against the importing file with the
extension dropped ("../db/config.js" matches a config.ts module).
To-side patterns resolve against layer paths too, whichever way the code
spells the import: a db layer mapped to src/myapp/db/** is reached by
import myapp.db.conn (src/ is the import root), import src.myapp.db.conn
and, in a flat layout, import db.conn - a rule naming the layer (db) or
any of those spellings matches all of them. Only the layer's leading
directories are stripped, never its own, so conn alone matches nothing.
Where the ADRs are
Every *.md file in the ADR directory and in its subdirectories is read
(docs/adr/2024/0007-use-kafka.md counts), except README.md files and
anything under a hidden directory or node_modules. Without --adr-dir the
directory is the first of docs/adr, doc/adr (adr-tools),
docs/decisions (MADR), docs/architecture/decisions, adr and
decisions that exists. With --adr-dir DIR exactly that directory is read;
repeat the option to read several:
--adr-dir docs/adr --adr-dir services/api/adr. new, index and init
write into the first --adr-dir, else into the directory found, else
docs/adr.
Reading no ADRs must never pass for "all ADRs hold". These are warnings
(--strict makes them exit 2): no ADR file found at all, an --adr-dir that
does not exist, a directory that cannot be read, and another candidate
directory whose ADRs were not read because an earlier one was used (pass
every directory you want with --adr-dir). The all-clear line says how many
ADRs were read - all ADRs hold (4 read), or 0 ADRs read (only the rules in
arch.yaml were checked) - and drift ends its line with the same count. With
--format json stdout stays the bare array of violations; the warnings are
on stderr.
The index, the sample ADR and the statuses
index writes a table of the ADRs (number, title, status) to README.md
in the ADR directory, under a first line that says adr-drift generated it.
A README.md without that line - one you wrote - is never overwritten:
index says so and exits 2, and index --force replaces it. (The index
written by 0.1.1 and earlier has no such line; it is still recognised as
long as it is only the table.) index needs the ADR directory to exist
(exit 2 otherwise).
init writes the index the same way but keeps a README.md of yours
(it says so; --force on init only overwrites arch.yaml). It numbers
the sample ADR, record-architecture-decisions, after the highest ADR in
the directory and adds none when the directory has one already (adr-tools
writes the same one).
The title is the first # heading (after any front matter). The status is
the first line of a ## Status section; else the status: of the front
matter (MADR); else a Status: line between the title and the first ##
heading (* Status: accepted, **Status:** accepted). No status shows
as a dash.
Rules are strict: nothing is dropped silently
A rule that is quietly ignored leaves a repo looking enforced when it is not,
so a rule that does not parse is an error (exit 2, file:line on stderr),
and every problem in every file is listed in one run:
- In
arch.yamla rule is one list item; quoting it is optional (- forbid-import: a -> bworks). - In an ADR,
## Constraintsis read line by line. A rule may be plain, a list item (-,*,1.,1)), a task box (- [ ]), in`backticks`or**bold**, optionally followed by a sentence of explanation. Ordinary prose is ignored, and so is anything after a#. - A line that looks like a rule but is not one is an error: a misspelt
name (
forbid_import:,forbid-patern:), a name with nothing after the colon, a barea -> bitem, a rule name buried in the middle of a line. - Each side of a
forbid-importis one layer name or module prefix; spaces in it (handlers -> db because layering) are an error - explain after a#. - Unknown keys in
arch.yaml(path:forpaths:) are errors with a did-you-mean. Prefix a key withx-to keep a note there, at the top level or in a layer (x-owner: platform team). - A heading such as
### Constraintsis not## Constraints, so the rules below it would not be read: that is a warning. - A repo with no rules at all fails (exit 2) unless you pass
--allow-empty: a green check that enforces nothing is worse than a red one.
How it checks
- Python is parsed with the real
ast— no regex false positives from comments or strings. Files are read as bytes, so a UTF-8 BOM and a# coding:cookie work as they do for Python itself. A file Python cannot parse (syntax error, NUL byte, nested too deeply, out of memory) is reported asunparsableon stderr - a warning, or exit 2 under--strict: its imports cannot be checked, but pattern rules still run on its text. - JS/TS/Go/Rust/Java/Ruby/PHP use a heuristic extractor (a small
tokenizer, not a parser): comments and string literals are ignored and
multi-line statements are read whole, in time linear in the size of the
file whatever it holds. A Rust or PHP file whose
uselists are nested more than 16 deep, or are so tangled that they would need far more work than that, is reported asunparsablelike a Python file that Python cannot parse. See Languages: exact support below;--strict-py-onlydisables the extractor. driftcompares commits: the violations atHEADagainst those at the base ref, both read out of git (git diff -z,git cat-file) - it never touches your working tree, uncommitted edits are ignored, and file names with non-ASCII characters work. Renamed files are followed.git blametags each new violation with its introducing commit. When--root(or the working directory) is a folder inside a larger repository - a package in a monorepo -driftlooks only at the files under it and names them from it, exactly ascheckdoes; changes next door are neither counted nor checked, and a file moved across the boundary counts as added or deleted.- A git problem (unknown ref, a shallow clone without the history, fewer
commits than the default
--since HEAD~5, git missing) is anerror:with ahint:and exit 2 - never a traceback and never exit 1. In GitHub Actions,driftneedsactions/checkoutwithfetch-depth: 0.
What counts as "the same violation"
check --baseline and drift identify a violation by its file, rule and
what was found (the imported module for forbid-import, the rule's pattern
for the pattern rules) - not by its line number. Adding a docstring above a
grandfathered import, or renaming the file, does not turn it into a new
violation. When a file has several identical violations they are counted: a
second eval( in a file that had one is reported as one new violation (which
of the two is the new one is a best guess). A baseline written by 0.1.0 keeps
working; a hand-made entry without detail still matches by exact file, line
and rule.
Languages: exact support
forbid-import needs to know a file's imports. Python is exact (ast:
import x, import x.y as z, from x import y, relative imports resolved
against the file's package; importlib and __import__ calls are not
seen). The rest is a heuristic extractor - read what it covers:
| Language | Files | Recognised | Not recognised |
|---|---|---|---|
| JavaScript / TypeScript | .js .jsx .ts .tsx .mjs .cjs |
import x from "m", import { a, b } from "m" (also over several lines), import * as ns from "m", import type ... from "m", import "m", export ... from "m", export * from "m", import("m"), require("m"), import x = require("m"); relative specifiers resolve against the file |
path aliases (tsconfig paths, bundler aliases), non-literal import(x) / require(x), .vue / .svelte files |
| Go | .go |
import "m", aliased / . / _ imports, grouped import ( ... ), raw-string paths; the module path in the root go.mod is removed from the repo's own packages (github.com/acme/app/internal/db is internal/db) |
a go.mod below the root (multi-module repos), build tags |
| Java | .java |
import a.b.C;, import static a.b.C.m;, wildcards (a.b.* is a.b) |
uses of a class in the same package (there is no import), fully qualified names in code |
| Rust | .rs |
use a::b;, nested trees use a::{b::{c, d}, e as f, self}, globs, pub use, pub(crate) use, extern crate, mod x;; crate::, self:: and super:: resolve against the file's module |
macro-generated use, #[path = "..."] modules, paths used in code without a use |
| PHP | .php |
use A\B;, use A\{B, C as D}, use function / use const, require / include (_once) of a literal path or __DIR__ . 'path' |
dirname(__FILE__), dynamic includes, a namespace spelt in a different case than its directory |
| Ruby | .rb |
require, require_relative, load, autoload with a string literal, at the start of a line |
a require after other code on the same line, computed paths |
Rust and PHP names are matched dotted (crate::db::x is db.x,
App\Models\User is App.Models.User); the other languages are matched as
written, with / and . interchangeable. Layers are matched the same way
as for Python, with their leading directories optional: a Java layer at
src/main/java/com/acme/db/** is reached by com.acme.db.Conn.
When forbid-import rules exist and none of a language's files contains an
import the extractor recognises, check warns once for that language: the
extractor is probably not seeing this codebase, and a rule that cannot see
imports enforces nothing. --strict makes that an error.
Exit codes, warnings and output
| Exit | Meaning |
|---|---|
| 0 | no violations (and, with --strict, no warnings) |
| 1 | violations found (--fail-on none makes every run report-only: exit 0) |
| 2 | the configuration or the invocation is wrong: unparsable rule, no rules, bad baseline, --strict with warnings |
stdout carries only the report. With --format json it is always a bare
array of violations ([] when clean) - or empty when the exit code is 2 -
so adr-drift check --format json | jq never meets prose. Every warning and
error goes to stderr as warning: ... / error: ....
Warnings flag rules and layers that cover nothing, which usually means a typo:
a layer whose paths match no scanned source file, a forbid-pattern or
require-pattern glob that matches no scanned file, the from side of a
forbid-import that matches no layer name or path, a to side that looks
like a misspelt layer, an unparsable or unreadable source file, and an ADR
directory that is missing, empty or not the only one (see Where the ADRs
are). Pattern rules apply to the scanned source files only
(.py .js .jsx .ts .tsx .mjs .cjs .go .rs .java .rb .php). --strict turns
any warning into exit 2.
CI
- run: python3 -m adr_drift check --format json --fail-on violations
Or use the bundled composite action (needs Python on the runner):
- uses: actions/checkout@v4
- uses: calasdan-sketch/adr-drift@main
with:
args: --adr-dir doc/adr --baseline .adr-baseline.json # optional
The action runs python -m adr_drift check <args>, so args takes anything
check takes, including --root and --adr-dir (they are accepted after the
command name). The text is split on spaces without any quoting, so a path
with a space in it cannot be passed.
--fail-on none reports without failing. With no rules at all, check
exits 2 (nothing is enforced) unless you pass --allow-empty (in the action:
args: --allow-empty), which is meant for adopting gradually: right after
init, until the first rule is enabled.
drift needs history. actions/checkout fetches a single commit by default,
so give it fetch-depth: 0 (otherwise drift exits 2 and says so). For a
pull request compare against where the branch left the base:
adr-drift drift --since "$(git merge-base origin/main HEAD)".
Limitations
- Only files with a source extension are scanned (
.py .js .jsx .ts .tsx .mjs .cjs .go .rs .java .rb .php), and not inside.git,node_modules,__pycache__,.venv,venv,dist,build,.toxorvendor. Aforbid-patternon YAML, Markdown or shell files matches nothing (you get a warning). - Python is exact; every other language is a heuristic extractor (see
Languages: exact support): path aliases, computed paths and macros are
not seen. In Python,
importlib.import_module()and__import__()are not seen either; everyimportstatement counts, also inside functions andif TYPE_CHECKING:blocks. forbid-patternis matched line by line (it cannot span lines);require-patternsearches the whole file.- A file belongs to the first layer whose paths match it.
- Pattern violations are identified by file and rule, counted: swapping one
violation for another in the same file is not seen, and with several
identical violations in a file
driftknows how many are new, not always which. driftcomparesHEADwith the ref itself, not with the merge base, and ignores uncommitted edits. It needs a git repository with enough history;checkworks anywhere.- Go: only the
go.modat the repo root is read. - Windows: files are always read and written as UTF-8, and on a console that
can't show the check marks (cp1252 pipes) the report falls back to
[ok]/[x]. - Rules are only as good as the constraints you write -
initscaffolds layers from the folder layout and writes no rule for you.
Tests
python3 -m unittest discover -s tests (or python -m pytest -q)
License
MIT — see LICENSE.
Made by Calas Automations (CAL-us). Need help? Call Cara 431-244-9026.
Metadata
Release files for adr-drift 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| adr_drift-0.1.2.tar.gz | 57.4 kB | Without provenance | Details for adr_drift-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| adr_drift-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for adr_drift-0.1.2-py3-none-any.whl |
Total release size: 112.1 kB
Release files / adr_drift-0.1.2.tar.gz
| Download URL | adr_drift-0.1.2.tar.gz |
|---|---|
| Size | 57.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c55e5d4cb8888d9bdb19fdde8c86dd3c54d662771f02b1461457de6932d4ed08
|
|
BLAKE2b-256 checksum How to use checksums |
bf9ceed7eab7eb6ef6e3e1efa1e854cdd3d817ca8bc89bc9c8464776b7da553c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Release files / adr_drift-0.1.2-py3-none-any.whl
| Download URL | adr_drift-0.1.2-py3-none-any.whl |
|---|---|
| Size | 54.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b9833c58277f405adf4d557c76ff8b894c0a3fe36275eff1b742f0b4b7f2b1a6
|
|
BLAKE2b-256 checksum How to use checksums |
d9e06c292200c93c237f371028af4a33e32d8b66aaa94fa47dc7e58a6c9e7c14
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.10
|
Security for adr-drift 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.