Should we rename the "controllers" folder to something else now?

Hi! After working with some Phoenix 1.7 apps recently I was thinking about this…

Should we rename the “controllers” folder to something else? Like, “resources” maybe?

Now that things are collocated in the same folder and there are other things than just controllers, it kinda makes sense, no?

There’s one other thing I’d like to ask: Is there a reason why the layouts are now in the “components” folder? And… Wouldn’t make more sense if we moved it to… let’s say… “resources/layouts_html.ex” and “resources/layouts/*”?

I understand this hasn’t been done probably because of backward compatibility, but since it seems so natural to me, I’d like to as for your opinion as well. Have you thought about this yet?

2 Likes

I’d expect layouts are in components, because they’re used “globally” and not for a specific controller or liveview. I’m not a big fan of the colocated templates, so I still create a views folder, which is used by both controllers and liveviews alike. That imo makes it much clearer that a template is independant of what it’s used for. With phoenix 1.7 it only became even simpler to just use the folder structure you want instead of the one given to you.

@LostKobrakai I was thinking about something like this:

- components/*
- resources/
  |_ blog_live/*
  |_ comment_live.ex
  |_ comment_live.html.heex
  |_ page_html/*
  |_ page_controller.ex
  |_ page_html.ex
  |_ layout_html/
  |_ layout_html.ex

This way, we’d have everything grouped together under “resources” (for instance) and the “components” folder would be free for what we usually consider UI components (like core components and others).

I personally find that if collocation were done like this, it would be very cool! It looks like everything is very well separated and well-identified.

I would also like to hear @chrismccord opinion about it, perhaps he has already thought about doing something like this in the past.

I sort folders to top, so folders and files will never be truely colocated.

1 Like