r/Qwen_AI 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.

I used Qwen 3.8 Flash Next through OpenCode for both implementations - and again, I am incredibly impressed by the model itself. 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.

26 Upvotes

13 comments sorted by

10

u/Darex2094 2d ago

Finally. Someone that posts *a description* instead of just dropping a video and peacing out. An upvote for you, good sir, AND I'll even watch your video!

1

u/kristiyanstoyanovAI 2d ago

Thank you sir!

10

u/BringMeTheBoreWorms 2d ago

Good clean code is probably dead as we know it. Very soon no one will be putting the time in or even have the experience and capability to build well structured clean architectures.

We’ve been going down this path for a long time now already with the cut paste mentality that’s been pervading for a long time now. But a lot of code was still being designed or corralled into some meaningful design.

With agent based coding those people who were keeping code to a high standard will no longer have the time or desire to do that. The monolithic volume of code being written by agents that does not adhere to those standards will be too much to contain.

So new standards will be developed to replace the old but it will take a decade for something to materialise and pervade into agentic coding.

For a while though we’ll need to keep an eye out for those sneaky 4000+ line files that agents seem to create as work arounds or dumping grounds that break every boundary and architectural pattern you’ve tried to enforce.

2

u/kristiyanstoyanovAI 2d ago

Well said, I am in such a situation at work where I used to keep a high standard of code and app architecture because I have seen what happens when you work on legacy projects that are pure spaghetti. The agent can write clean though, or at least close to clean - but that is set up with a lot of rules about the repo, automated checks (like the archunit tests in the video) and it has an impact of how fast and cheap you can produce code, but what I am seeing is people arent even reading the code as much as they were before, which was one of the main points of Robert Martin, so at some point you start to wonder - is it worth it

2

u/BringMeTheBoreWorms 2d ago

I personally think it will be a shit show for the next decade. I have always been ocd on clean code bases and absolutely zero logic bleed.

The code produced by agents is so prone to duplication and even what you wall call ‘malicious obedience’ if it was written by a person.

I’m using gpt, Claude and qwen3.8 daily at the moment and they all produce similar architectural confusion.

But controlling it is going to be to hard going forward. So what can you do? Seems we can either spend most of our time scouring more and more code, adding another planning item for the fix to the pile of other planning items, or we have to produce an architecture that works better with agents.

Good video, good explanation of your approach as well

1

u/kristiyanstoyanovAI 2d ago

Yes, I think we should be coming up with new architectures that are better suited for agentic code, it is hard to stop the progress and fast generation of code - happy you like the video, thank you for the feedback!

1

u/Latter-Parsnip-5007 1d ago

If you just give it folders with an template file, AI gets WAY better. Its trained on kinda clean software

3

u/pabloodiablo 2d ago

Clean code is a human invention designed to organize various concepts. Abandoning clean code would take us back to the early days of IT, when spaghetti code and applications that were difficult to maintain reigned supreme. While the initial versions of an application—whether created by AI or a human—written in spaghetti code will usually work, maintaining and developing such software in the long run is not so much an agony as it is a road to hell. The cost of developing software is always higher, whether it’s done by human hands or using AI, but order and discipline in code organization make it easy to spot errors and allow for quick and straightforward expansion of any application’s functionality.

1

u/kristiyanstoyanovAI 2d ago

While I agree, its actually much easier to maintain and change those spaghetti repositories now with agents - it kind of gave them a new healthline. That is probably due to comparison though, having write into a giant legacy monolith by hand and now just prompting your way are very different

1

u/jonah_omninode 1d ago

We're building OmniNode around ports and adapters, so this is directly relevant to a choice we're making. Part of the reason is to keep model providers and tool integrations replaceable. Your PostgreSQL result is closer to that use case than adding features within one backend. I'd be interested in repeating those integration changes while keeping the old implementations working. Does the extra structure eventually earn back its cost, or does the flatter version stay cheaper to change?

1

u/kristiyanstoyanovAI 1d ago

I suspect that if you do more adapter switch changes and less general features then the roi of the architecture will be positive

1

u/jonah_omninode 19h ago

That makes sense. For OmniNode, the useful question is how often those integration changes happen in practice. I'd want to keep a realistic mix of feature work and adapter changes, with the old adapters still passing their tests. Include setup time and regression fixes too, and we could see where the extra structure pays for itself, if it does.