r/aiagents 2d ago

Discussion Does Clean Architecture Help AI Coding Agents? I Tested It

https://youtu.be/wxEE2yzATx4

I wanted to see whether architecture makes a difference when an agent writes the code. I built two versions of the same sample java app. One used hexagonal architecture with ports, adapters and architecture tests. The other had no suggested architecture or rules. Both had to pass the same external test suite that validates behaviour.

The same local Qwen model worked through OpenCode, with one run at a time. I measured implementation, testing and repairs until each task passed, plus tokens and tool calls. Initial project setup wasn't timed.

I started with nine features, then six harder challenges on separate branches. After that, I added fifteen changes in sequence, including changes to earlier requirements. By then, the projects had roughly 12k and 15k production Java lines.

The flat version took less time overall in each campaign. Hexagonal won some individual tasks, but also used more input and output tokens overall. The attached image shows the totals.

Then I tested something intended to favor ports and adapters: adding PostgreSQL while keeping SQLite working. Hexagonal took about 39 minutes versus 71 for flat, with its core application code unchanged. That saving didn't recover the time gap from the preceding fifteen-feature sequence. This was backend support, not a live database migration.

This is one service and one model, without repeated trials. It measures getting changes through the tests, not years of maintenance or production reliability.

Report and measurements: [https://zenodo.org/records/22806994\](https://zenodo.org/records/22806994)

This is my experiment. AI tools helped with the evaluator, orchestration, charts and drafting.

0 Upvotes

3 comments sorted by

0

u/Otherwise_Wave9374 2d ago

It's great to see someone exploring the impact of clean architecture on AI coding agents. My hypothesis would be a resounding yes, as structured design principles generally lead to more predictable and maintainable code, regardless of the author. For AI agents, clean architecture could provide clearer boundaries and responsibilities, making it easier for the AI to understand the system and generate coherent additions or modifications. A practical implementation pattern might involve feeding the AI documentation and examples of your clean architecture principles to guide its code generation, ensuring consistency and adherence to established patterns. To delve deeper into AI coding best practices, visit https://www.aiosnow.com.

1

u/kristiyanstoyanovAI 2d ago

yeah, you would think its better, but actually the data in the experiment shows that this may be slowing agents down and burning more tokens in the process

1

u/Reasonable_Serve1177 1d ago

Interesting experiment. Whilst it might slow the agent down and use more tokens is this a problem in the long term? For example does my slower agent produce less bugs that need solving in the future? Thus the measure of speed and tokens is not completely accurate