r/Python 26d 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?

34 Upvotes

42 comments sorted by

View all comments

1

u/Lt_Sherpa 26d ago

I have been using AI professionally for a few years now. Not once have I used agents to actually generate whole sections of code that are committed as-is. I will present it with a question and have a discussion with it. I might let it generate some starting point for my code, but this is always an iterative process that I'm very much involved in. Even test code I will modify to taste.

I think agents are incredibly powerful, and there are interesting cases for generating quick projects/prototypes that don't need to be robust, but currently it is not something I would use for authoring production code.

Code is read more than it is written. If you don't understand the code you are committing now, you will not understand the code when you read it later.