Stivo2y ago

Right way to structure your code when using tRPC?

I was wondering how you properly structure your tRPC ruter code? Writing all the code in the routers can become messy quickly. Do you split it up in controller and service files (MVC)?
2 Replies
isaac_way2y ago
Our backend devs have separate router files to break down the api into manageable chunks, and those use services which are classes that do related DB operations I wouldn’t call it MVC, there’s no “view” inherent to the system. It’s a routing layer, and then a service layer and that’s the whole backend.
mark salsbery
mark salsbery2y ago
I use a a master router file that imports and merges namespaced routers, like the first example here:
Merging Routers | tRPC
Writing all API-code in your code in the same file is not a great idea. It's easy to merge routers with other routers.