Skip to main content

Architecture contract for AI coding agents: a curated, human-edited ARCHITECTURE.md with drift detection in CI.

Project description

archdrift

Architecture contract for AI coding agents. A curated ARCHITECTURE.md that agents read, humans edit, and CI enforces — so your architecture docs never rot.

CI PyPI Python Zero deps


The problem

Tools like Repomix and CodeGraph are descriptive: they read your code and tell agents what exists. But no tool captures what your architecture is supposed to be — the intent behind it. So agents guess, ARCHITECTURE.md files rot within weeks, and nobody notices until an agent (or a new dev) builds on top of stale assumptions.

The idea

archdrift makes your ARCHITECTURE.md normative:

  1. Generated map — folder tree, detected stack, responsibilities table. Curated for token efficiency: code files listed, assets collapsed.
  2. Human curation that survives — edit any description in the responsibilities table, add ADRs and notes anywhere outside the managed sections. Regeneration never destroys your edits.
  3. Drift detection in CIarchdrift check exits 1 when reality diverges from the documented contract. The doc can't rot, because rot breaks the build.
┌─────────────┐   generate    ┌─────────────────┐   read    ┌────────────┐
│  Filesystem │ ────────────▶ │ ARCHITECTURE.md │ ────────▶ │  AI agent  │
└─────────────┘               │  (you curate)   │           └────────────┘
       ▲                      └─────────────────┘
       │                               │ check (CI)
       └───────── drift? exit 1 ◀──────┘

Quick start

uvx archdrift .          # or: pipx run archdrift .

This generates ARCHITECTURE.md (the contract) and structure.json (the graph, for tooling). Folders without a known role get marked _(preencher)_ — fill them in, they're preserved forever.

Then enforce it in CI:

# .github/workflows/ci.yml
- name: Architecture drift check
  run: uvx archdrift check .

Now every PR that adds an undocumented folder, deletes a documented one, or changes structure without regenerating the map fails the build until someone updates the contract.

How merging works

Managed sections are delimited by markers:

<!-- map:begin tree -->
...regenerated by the tool...
<!-- map:end tree -->

## ADR-001                      ← yours, never touched

<!-- map:begin contract -->
| Folder | Responsibility |
| `src/models` | Prisma entities — NEVER import from controllers |  ← your edit, preserved
<!-- map:end contract -->

Priority for each folder's description: your edit > name-based heuristic > pending placeholder.

Why not just use a repo packer / knowledge graph?

Use both. Repomix, CodeGraph, aider's repo-map are excellent at telling agents what the code is. archdrift covers the piece they can't infer: what the architecture is meant to be — and keeps that promise honest via CI. It's dependency-cruiser energy, rethought for the agent era, in a single zero-dependency Python file.

Roadmap

  • Managed sections + merge (human curation survives regeneration)
  • check mode — drift detection with meaningful exit codes for CI
  • Stack detection, token-efficient tree (type-aware truncation)
  • AGENTS.md integration (pointer section into the emerging convention)
  • Declarative rules (src/controllers must-not-import src/repositories)
  • MCP server mode
  • Semantic graph: declared dependencies vs. real imports — the diff is the product

Development

pip install -e ".[dev]"
pytest -v

MIT licensed. Issues and PRs welcome.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

archdrift-0.1.0.tar.gz (15.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

archdrift-0.1.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

Details for the file archdrift-0.1.0.tar.gz.

File metadata

  • Download URL: archdrift-0.1.0.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for archdrift-0.1.0.tar.gz
Algorithm Hash digest
SHA256 52909d149dbb52c84c25a220f0060649956e170443855870b0f9d942ce550fa5
MD5 0d89c65900f1ad9509b6b3f002088a69
BLAKE2b-256 7cbd1995a6488881f87d01725f02c5b624c89e13d000c1c7eacabb9e00ed708a

See more details on using hashes here.

File details

Details for the file archdrift-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: archdrift-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for archdrift-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 66fa97192cd3d606ae07a413d8aedec0db53e6d9b8bd436b64a7b4532fd35dac
MD5 18cbb154ac6fb84054fbfbf112bd775a
BLAKE2b-256 e11e2480c50b7f83d0d243f069347a15bcc1b9f62449e892fb7a5a183c0a69a5

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page