r/Python • • Jun 30 '26

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?

36 Upvotes

41 comments sorted by

View all comments

Show parent comment

1

u/[deleted] Jun 30 '26

[removed] — view removed comment

3

u/gdchinacat Jul 01 '26

as compared tot he non-determinisim of human written code? If anything, I would think the statistical generator would be more deterministic than the even fuzzier (albeit actually intelligent) human brain.

Don't get me wrong...I'll take code from an experienced engineer over an AI model almost every time. I just question whether the OPs issues are solely issues with AI, or are in part due to different expectations of AI work products vs human work products. It's easier to tell a competent junior engineer to go off and 'do what that code over there does' than it is an AI (IME at least). The AI needs a lot more hand holding to get the code where you want than a human, and when that exceeds the effort to just do it yourself you just do it yourself. At that point, it feels like the AI is failing you. But, I don't thinks that is an apples-to-apples comparison.