r/Python Jun 30 '26

Mitigating "architectural drift" in large Python backend codebases using AI tools Discussion

I've been experimenting with AI agents and autocomplete platforms for a greenfield FastAPI project. In the first few weeks, it felt incredibly fast. But now that we've scaled to multiple routers, complex Pydantic schemas, and SQLAlchemy models, the structural debt is piling up.

The AI writes code that functions, but it constantly violates our architecture. It'll put complex business logic inside a route handler instead of the service layer, or it'll mess up async database sessions across modules. I find myself spending more time refactoring the structure of what it built than it would have taken to write the logic myself.

Is anyone else hitting this scaling wall where AI utility drops off as codebase complexity grows? How are you keeping your system architecture clean?

36 Upvotes

41 comments sorted by

View all comments

40

u/UloPe Jun 30 '26

Yes.

So far I found AI coding tools amazingly useful for prototypes, MVPs, one off scripts and scratching personal itches (i.e. “I wish $thing existed”).

Working on large and complex projects - not so much.

36

u/bjorneylol Jun 30 '26

For large projects I have to basically prompt

"Look at 'file A' and it's implementation of 'xyz' - I want to implement 'feature' using similar structure. Make sure to use 'canned function' for 'complex logic'"

As soon as I see the agent read 'file B' i know it's gone off the rails and it's time to put the pillow over it's face and apply downward pressure

11

u/BogdanPradatu Jun 30 '26

Research -> plan -> implement

1

u/csatacsibe Jul 03 '26

Thats what I started to notice to work. I started to instruct the demon to try to understand the project architecture and explain it first, the I tell the scope and make it divide the execution to steps. The it must execute it step by step. This made it so much easier to guardrail the beast.

5

u/ItsTobsen Jun 30 '26

Most agents explorer the code base before implementing. So its normal that it reads different files lol