I am in discussion with someone who would like to restructure phoenix project file structure so that model, view, controller, and tests will be all in one folder per named “feature” (let’s say “blog”)
I am looking for feedback on what the tradeoffs would be for doing this.
The argument for it is that “everything you need to find for the feature would be in one folder. This should be easier for everyone to find and use these files”. But are there fundamental reasons not to restructure a phoenix project in this way? I know it would lose compatibility with with code generators. However, would this also push people off track in their reasoning about he code? What are the impacts if any, for doing this?
Controller / view code isn’t really this way though. I definitely agree with you that "model" code definitely doesn’t belong to a specific controller. However for controller / view stuff there’s a decent argument for favoring a “pod” structure.
While not exactly the same, LiveView definitely takes more of a “page” oriented structure since with a given live view + leex / heex template you generally have a bunch of functionality all right next to each other.
I don’t disagree but let’s take this to the extreme: should each feature have a copy of the root layout code then?
The stance described in OP seems too extremist and narrow-minded to me. Partially applied it is valuable but I’ve rarely seen people advocate for such things in an moderate manner. It’s usually an all-or-nothing affair. Maybe it was a bad luck on my part, I don’t know.
In practice, it’s never about the extremes though. As there is a ‘data’ App and a separate ‘web’ AppWeb both styles can be used together.
If we look at how the phx generator creates the data app, we see vertical slicing as far as I can remember. Except for migrations which are all in one folder*. It’s the web app that (historically) uses horizontal slicing and although it can be beneficial, I rather use vertical slicing there too.
LiveView seems to move towards vertical slicing, with the template files next to the rest of the code for a page/view.
*Django puts migrations within the ‘feature’. Con: touch two features at once and you have two separated migration files.
I would not favor an all-in-one approach with models next to views, as having both an data app and web app makes a good boundary. So there I draw a line: The data app is meant for handling data requests, the web app for handling web requests. Easy distinction .
It also allows me to have a clear seperation between types of ‘frontend’. For example: