Guidelines for Structuring Modules and Services in NestJS

  Kiến thức lập trình

I am new to NestJS and I am having trouble understanding the guidelines for creating new modules versus creating new services within the same module. Specifically, I am unsure when to decide to create a new module or keep functionality within an existing module.

For example, I have the following methods:

  • findUserById()
  • createUser()
  • deleteUserById()
  • updateUserById()
  • signin()
  • signup()
  • logout()
    My initial thought was that the first four methods are CRUD operations for the User entity, so they should be in a module called UserModule. The registration and authentication methods should be in a separate module called AuthenticationModule.

However, I noticed that there is shared logic between signup() and createUser(), since signing up involves creating a new user. This made me wonder if they should be included in the same service or if I should keep them in separate modules but import the UserModule into the AuthenticationModule and add the UserCrud service to the providers section of the AuthenticationModule.

In React, there is a section in the docs called “Thinking in React,” which provides guidelines on structuring components. I am looking for similar guidance for NestJS but have not found a good resource.

Question:
What are the guidelines for deciding when to create a new service versus creating a new module in NestJS?

Theme wordpress giá rẻ Theme wordpress giá rẻ Thiết kế website

LEAVE A COMMENT