Skip to main content

agent-arch

agent-arch: five architecture layers inside a shield

Deterministic codebase architecture guardrails & sub-15ms topology indexer for AI coding agents.

CI PyPI version Python versions Code style: Ruff Latency SLA Token Cost License: MIT

繁體中文說明

AI coding agents (such as Claude Code, Codex, and Cursor) often edit files with local context only. This causes architectural erosion:

  1. Low-level modules import high-level UI modules to save time.
  2. Refactoring steps silently break exported symbols and APIs.
  3. Reading whole repositories wastes tens of thousands of tokens per turn.

agent-arch solves this problem. It builds a fast, deterministic architectural topology map in sub-15ms, and enforces strict layering rules before code submission.

Five example layers with downward imports and an AST shield that blocks upward imports

The diagram uses example layer names. Configure layer ranks for your project.

The sub-15ms figure applies to cache reads. Local architecture checks use zero LLM tokens. These checks cover layering and public APIs. They do not prove that all code is correct. See the benchmark report and image prompts and settings.


Features

  • Sub-15ms Index Latency: Deterministic AST scanning with compact JSON caching.
  • Zero Token Verification: Check architectural rules locally with zero LLM API cost.
  • No Reverse Imports: Prevent lower layers from importing upper layers.
  • Public API Safety Net: Detect breaking changes and require backward-compatible facade shims.
  • Zero External Dependencies: Pure standard library Python with optional orjson acceleration.

Comparison with Existing Tools

Tool Primary Purpose Latency Token Cost Architecture Guardrails Agent Surgical Query
agent-arch (This tool) AI Agent Orientation & Guardrail < 15 ms 0 tokens YES (Layering & API shims) YES (< 30 lines Markdown)
Aider repo-map Whole-repo symbol ranking for prompts 500 ms - 2 s High (prompt bloat) NO (Architecture-blind) NO (Dumps bulk symbols)
Tach / Import Linter CI boundary enforcement for monoliths 200 ms - 3 s 0 tokens YES (Module boundaries) NO (No query API for agents)
ast-grep (sg) Single-file AST structural pattern matching < 50 ms 0 tokens NO (No global dependency graph) NO (File-local only)
arch-analyzer LLM-based architecture review wrapper 30 s - 3 min Very High (10k+ tokens) Fuzzy / Probabilistic NO (Heavy report generator)

Key Differences

  1. vs Aider repo-map: Aider ranks symbols with PageRank to feed large context into LLM prompts, but it does not prevent architectural erosion. agent-arch enforces strict single-direction layering and API compatibility checks.
  2. vs Tach / Import Linter: Tach and Import Linter target human CI pipelines with terminal error outputs. They lack a sub-15ms surgical query interface for agents to look up upstream dependencies and downstream callers on-demand.
  3. vs ast-grep: ast-grep is a powerful single-file CST pattern matcher, but it cannot resolve imports across files or detect circular dependency cycles.
  4. vs arch-analyzer / LLM Reviewers: Wrapping LLMs to review code is slow, expensive, and non-deterministic. agent-arch uses deterministic, zero-token local AST analysis that runs on every git commit.

Installation

Run directly with uvx (no prior installation needed):

uvx agent-arch --query <symbol_or_module>
uvx agent-arch-guard --strict

Or install via uv / pip:

uv add --dev agent-arch
# or
pip install agent-arch

Usage

0. One-Click Guardrail Installation (--init)

Enforce guardrails on any repository with a single command:

uvx agent-arch --init

This command automatically:

  1. Installs a Git pre-commit hook (.git/hooks/pre-commit) that physically blocks any git commit violating architectural rules.
  2. Appends architectural guidelines to AGENTS.md so AI agents (Claude Code, Codex, Cursor) know the constraints before writing code.
  3. Initializes .agent_arch/ cache and default pyproject.toml settings.

1. Query Codebase Topology (Surgical Agent Orientation)

Display a clean architectural summary of your codebase:

agent-arch

Query a specific module to inspect its layer, classes, upstream imports, and downstream callers:

agent-arch --query relabel.py

Locate a symbol across the entire repository:

agent-arch --query UserEntity

2. Verify Architecture Integrity (CI & Preflight Guardrails)

Run layering and compatibility checks:

agent-arch-guard

Compare API compatibility across Git revisions:

agent-arch-guard --base origin/main

Compare two files directly:

agent-arch-guard --compare-files old_module.py new_module.py

Configuration

Add an optional [tool.agent-arch] section to your pyproject.toml to customize layers and scanned directories:

[tool.agent-arch]
scan_dirs = ["src"]
exclude_dirs = [".git", ".venv", "tests", "dist"]
cache_path = ".agent_arch/index.json"
cache_ttl = 300.0

[tool.agent-arch.layers]
0 = { name = "Domain", description = "Base entities and types", match = ["domain", "models", "types"] }
1 = { name = "Storage", description = "Database and file I/O", match = ["storage", "io", "db"] }
2 = { name = "Core", description = "Business logic and algorithms", match = ["services", "core", "algorithms"] }
3 = { name = "Workflow", description = "Controllers and handlers", match = ["controllers", "handlers"] }
4 = { name = "UI", description = "User interface and entrypoints", match = ["ui", "views", "cli", "main"] }

Benchmarks

See BENCHMARK_AND_VERIFICATION.md for stress test records across 2,300+ modules and sub-1ms cache latency measurements.


License

MIT License.

Metadata

Release files for agent-arch 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agent-arch 0.1.0
File Size Uploaded Provenance
agent_arch-0.1.0.tar.gz 70.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for agent-arch 0.1.0
File Interpreter ABI Platform
agent_arch-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 92.9 kB

Release files / agent_arch-0.1.0.tar.gz

Download URL agent_arch-0.1.0.tar.gz
Size 70.7 kB
Tags Source
SHA-256 checksum
How to use checksums
dcc5753a90d7f64f29c9edb6f2b2ebd19e9bcae029b2a6a92b6ee97c0294dbf2
BLAKE2b-256 checksum
How to use checksums
67bc9cac38d545de9edf01c4d12467ac84717b9dc7681c20cef98ac516f7c5cd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / agent_arch-0.1.0-py3-none-any.whl

Download URL agent_arch-0.1.0-py3-none-any.whl
Size 22.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
29fe203723f4f2811c82dd2505c81d3f774bc246e255648949ba72c19a52e194
BLAKE2b-256 checksum
How to use checksums
68cd423bf8598fcb40f31eadb3b6037d25bec18d0f6474e6ef3c20857d432081
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.0 {"installer":{"name":"uv","version":"0.13.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for agent-arch 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page