0

I have a user feature. user feature also has other subfeatures user application details and user contact information.

Usually, because application details and contact information are part of user feature, we are dealing with one-to-one relation, I would put application details and contact information within user folder on the system. I see those two as an extension of the user feature.

So we would have a structure similar to:

  • app/Models/User.php
  • app/Models/User/ApplicationDetail.php
  • app/Models/User/ContactInformation.php
  • app/Services/User.php
  • app/Services/User/ApplicationDetail.php
  • app/Services/User/ContactInformation.php

I had one individual put forward an idea that we should think of user application details and user contact information as individual services (features_, due to which both of them can and should be located in the main folder and regarded us features of their own.

So we would have a structure similar to:

  • app/Models/User.php
  • app/Models/UserApplicationDetail.php
  • app/Models/UserContactInformation.php
  • app/Services/User.php
  • app/Services/UserApplicationDetail.php
  • app/Services/UserContactInformation.php

This seems like a very silly thing to ask on here, but I am trying to give this individual a chance and hence I am trying to evaluate the benefit of what was put forward. However, from my experience, we will end up with a folder that has too many files, which may feel very overwhelming even for those who know how the system is structured.

1
  • Why so complicated? app/users/*, app/users/services/*. Take a look to the next question
    – Laiv
    Commented Jan 1, 2019 at 1:21

1 Answer 1

1

Be pragmatic. What is more convenient for day to day tasks like:

  • Find class file. What place would astonish you the least?
  • Find class by looking at Project files
  • Use autocomplete what pops up first?
  • Move/rename/change one class what other classes might be affected?
  • Creating new classes

In my opinion:

  • It is reasonable to have those classes in models and services but if there are more than 1 class related to user it would be more convenient to search in user folder.
  • If I would open models or services folder it would be hard to find anything. Users folder is a reasonable choice here.
  • If you would type "User" you would get everything that is related to user. On the other hand typing "ContactInformation" you would get far fewer choices.
  • Having "User" folder immediately points to classes that might be affected.
  • Creating new class also is more convenient since you see what other "User" related classes there are. Seeing those different classes gives you clues whether you can reuse something.

It would be more consistent if "User" class would belong to "User" folder in 1st version. For convenience it might be reachable from "models" or "services" if needed.

Flat is sometimes better than nested but you have to weight different options and find what works best for you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.