Search code examples
structure

How can I create a less redundant project structure?


Currently I'm working on a webapp that has a structure roughly like this:

  • model
    • user
    • robot
  • service
    • user
    • robot
  • web
    • controller
      • user
      • robot

I'm noticing a lot of redundancy in this structure. Is there any way that I could create a project structure that is less redundant?


Solution

  • The main idea behind folders in a project is to encourage separation of concerns. Each folder should group code into separate functionalities.

    Your folder structure seems fine, but I would suggest changing the name of the files so that you know exactly what you're dealing with.

    Perhaps more like:

    • model
      • user
      • robot
    • service
      • userService
      • robotService
    • web
      • userController
      • robotController

    This way you know immediately that:

    • model files show structure of entities but no functions or logic
    • services deal with business logic only
    • controllers deal with API interfaces