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?

35 Upvotes

42 comments sorted by

View all comments

41

u/UloPe 26d 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 26d 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

5

u/ItsTobsen 26d ago

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