The biggest risk in software right now isn’t downtime. It’s letting AI coding agents quietly erode your architecture one "fix" at a time. When an LLM gets stuck, it usually doesn’t stop and ask: - “Should this layer even know about that one?” - “Is this dependency direction allowed?” - “Are we introducing a circular dependency here?” It just makes the code work. So routers start importing database code directly. Service layers begin depending on framework internals. Circular dependencies creep in. And six weeks later the codebase still “runs”, but nobody wants to touch it anymore. That’s exactly why I built ArchUnitPython. It lets you enforce architectural rules in Python projects by writing them as simple unit tests. So instead of *hoping* humans or LLMs respect your architecture, you can make those rules executable and enforce them in CI. Example: rule = ( project_files("src/") .in_folder("**/presentation/**") .should_not() .depend_on_files() .in_folder("**/database/**") ) assert_passes(rule) A few things it can do: - enforce dependency direction rules - detect circular dependencies - validate naming conventions - validate PlantUML diagrams against code - calculate architecture/code quality metrics - support custom rules (- special support for FastAPI and Django) The goal is simple: If your team has architectural decisions, they should live in tests, not just in wiki pages, PR comments, or one senior engineer’s head. By putting them in your CI/CD pipeline as tests, they are ensured forever. Feedback and PRs are highly welcome! Repo: https://lnkd.in/dMGDBGkP #Python #SoftwareArchitecture #OpenSource #Testing #FastAPI #Django #Pytest #CodeQuality #AIEngineering #LLM
The boundary enforcement approach in ArchUnitPython solves exactly the problem that catches teams off guard six months into working with AI agents on a codebase. We hit a similar wall on a Phoenix project where Credo and mix quality checks caught individual style issues but not dependency direction violations across bounded contexts. Making architectural rules first-class test citizens that run in CI is the only reliable way to give AI agents a hard constraint they cannot bypass through clever code generation. How does the performance hold up when running these rules against larger codebases, say 100,000 lines or more?
Has anyone tried to produce said architectual rules with an LLM? I think this project has super huge upsides as part of a complex A.I. developer workflow.
I've had this issue on a codebase recently: design progressively became a mess, agents adding hacks over hacks to work around architecture issues. Hopefully we had enough post-deployment tests to provide a safety net. I've been able to totally restructure the project structure in a couple of weeks. Now the projects makes sense and AGENTS.md points to a clear architecture description. Agents are now following the path of least resistance and keeping changes on the good (or at least better) architecture. Lessons that I learnt: * Invest in good structure and documentation early. Agents make the code rot 10x faster. * Reviewing only diffs in PRs is not sufficient. Taking some time to look at project structure as a whole and assess the fitness of the patterns should be in the team hygene. * Defining what good architecture is is still a matter of taste and judgement. Yes we can delegate a lot of implementation to agents, but architecture needs scrutiny and human ownership.
Lukas, the 'codebase still runs but nobody wants to touch it' line is painfully accurate. Great approach making rules executable!
stateful global singleton .... sometime with public properties ... Opus try to do functional, but it still does this ... the problem is that models learned from so much public code where patterns violation exists ... I like the idea of architectural design unit test
Agree, one of the issues with AI coding isn't that agents can't write good architecture, but that developers can't explain it and enforce it. Sometimes just a single file living in the repo can do that, but your rule is a really nice addition on top.
Repo link: https://github.com/LukasNiessen/ArchUnitPython - More: ArchUnit Python - ArchUnitPython is basically "ArchUnit for Python" - for those unaware, ArchUnit is a famous Java library that let's you do the exact same thing as described in my post, just for Java projects instead of Python.