#How to design services and controllers in multi-part application?

2 messages · Page 1 of 1 (latest)

tight pumice
#

My application consists of 2 parts:

  • admin
  • platform

Let's imagine we have a Cats entity, which we want to allow to CRUD on both sites. It means we need a service for it.
We also need controllers (note that DTO would be different in both sites). I think a good idea is to keep admin-related and platform-related controllers separately. So, I come up with the following structure:

- controllers
  - admin
    - cats.controller.ts
    - ...
    - admin.module.ts (contains all admin-related controllers and imports of required services)
  - platform
    - cats.controller.ts
    - ...
    - platform.module.ts (contains all platform-related controllers and imports of required services)
  - controllers.module.ts (contains admin and platform controller modules)
- services
  - ....

The structure seems organized enough for me so far, but I have seen a recommended nestjs way is to keep entity, controller, service and module together in the same directory, but I didn't find a nice way to do so under the requirements. Is the structure above alright? Is there any other better way to achieve what is needed?

inland adder
#

Is the structure above alright?
I mean, if it works for you it weorks for you.

That said 90% of the time I highly suggest grouping files by feature rather than by type, as most of the time it'll save you headache down the road