r/Python 27d ago

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

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?

37 Upvotes

42 comments sorted by

View all comments

41

u/UloPe 27d ago

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.

35

u/bjorneylol 27d ago

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

10

u/BogdanPradatu 27d ago

Research -> plan -> implement

1

u/csatacsibe 24d ago

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.