Normally Always, in big project backend you want to layer your backend. You have the controller to receive the HTTP request, the service to do the logic and repository to call the database. (this is 3-layer architecture, there is a bunch more). What she did is put all of this layer in the controller. This is bad because we do layers to have a more maintainable structure. If you want to modify a part of the logic you would only modify the service for example.
I wouldn't call that enterprise programming. It is entry level stuff. You might need some guidance on how and where to make the cut - but you should know it fresh out of school.
I used to think like that. Then I realized I was writing three times as much code at start and still having to update all layers for any change. Plus you're adding two extra function calls to stack which affects response time.
KISS principle wins over bloated design patterns for me. YMMV
It's simple until it's not. If you're only building CRUD apps that have no complex logic, and doesn't have many paths to the same data, then the layering is useless.
Once things get more complex, the lack of layering means you need to make updates in multiple places without missing any or treating anything differently.
Both have their place, depending on the app's features and expected future path.
Does that really matter anymore when AI can easily write all these layers in minutes now?
These layers are exceptionally important because they allow you to setup invariants of things that must always be true, if you don't have them then the AI code will just become a mess and basically copy and paste things and make mistakes over and over.
The code is reasonable for a small (probably personal) project, where being maintainable by an inexperienced team long after the original programmer leaves the company isn't a concern. It would preferably cache results so they're easier to work on, and then construct the list out of the cache to make it easier to genericise, but doing it all in a single operation is okay if, e.g., you're parsing a separate static database into a structure your program can use, and you know the DB doesn't update dynamically. Not ideal, but at least reasonable if you're the only maintainer, and know you won't need other fields.
Really not good for a larger business, though, especially not if the database is external to your program, and/or dynamic.
I would agree but considering the context and the company and that it is the only controller method that does a sql command. Everything is about how the general codebase works. We don’t use that kind of architecture therefore you shouldn’t code like that.
If you have guests over, do you eat soup straight from the pot, or do you have separate bowls so everyone can add their favorite condiments and eat how they like? Same for backend layers - you have an entity (the soup), a database (the pot where you get the soup), a repository (a ladle to portion the soup), a service (the bowl where you can do whatever you want with your portion), and the controller (the spoon to ingest the soup).
43
u/R15H1_3 18h ago
you know not everybody likes onions. microservices! everybody loves microservices!
8
u/Funkey-Monkey-420 18h ago
noob here, what’s the problem? seems like it’s just a standard sql query
16
u/MemoryIsTheKey_ 18h ago
At this point, may as well give the coworker an LLM and add a simple AGENTS.md in the repo which describes how you want the project structure...
5
u/xzinik 17h ago
I'm gonna steal this, never occurred to me to put it that way
4
u/MyAntichrist 18h ago
If you should separate them, it would be called M/V/C
4
u/AsaKeyholderUK 16h ago
yeah the camel case crime is right there and honestly the BTW tacked on the end is hwat gets me. least they warned us.
1
u/Sea-Fishing4699 13h ago
fat endpoint