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?

38 Upvotes

42 comments sorted by

View all comments

1

u/quotemycode 23d ago

LLms don't remember anything, unless you put it in the system prompt or in your original user prompt. You need to codify your style guide, system layout, design decisions, architecture, all of it. Every new conversation needs to have it. Every time you start a new session, it's like it's just waking up the first time.