Agent/Assistant can't build app in modular way

I need to describe a serious issue.
I try to build an app which is moderately complex. Once i reached in about 80% of my total implementation i couldn’t continue because the route.ts file was significanlty large (2700 lines) and the dev process was slow or almost zero, it took over 10min to agent/assistant to respond. I try to split this file, but at that time was impossible.
I started again giving instructions to agent/assistant to build each component in a modular way to avoid creating large files that can’t be managed. I face significant issues also with this approach.
It seems agent/assistant have their own way of doing things and they can’t build an app in a really modular way. They follow practices that lead to create large files which can’t be managed when the complexity is increasing.

Has anyone face the same issue? How can we deal with that? The solution “start building by giving simple prompts” after a while does not work.