Folder organization discussion proposal

I just stumbled across this topic after brainstorming this idea as well. I think it makes a lot of sense and I’m going to look whether I can tweak my Hanami project to support this. It makes way more sense intuitively IMO. Just to spell out what Victor is suggesting, the project directory would look something like:

apps/web/
  products/
    index/
      partials/
        product/
          product.html.erb
          product.css
      index_action.rb
      index_view.rb
      index.html.erb
      index.css
      index.js
      images/
        an_image.jpg
  customers/
    etc...

So rather than structuring around functionality you structure around features / parts of the application. We don’t mental map an application by functionality and go through, say, each controller one by one, and then each view one by one, and then templates and then assets. We reason about and browse through the application by features / sections of the interface.

The huge benefit from this is it encourages developers to modularize their code and separate their concerns well. As it stands right now, when we categorize by functionality, the boundaries don’t feel clear because there are disparate subdirectories that depend on each other (for example controllers/home/index.rb interacts with views/home/index.rb, as opposed to home/index/index_action.rb and home/index/index_view.html.erb sitting side by side).

If anyone knows of any gotchas I should look out for when I tweak hanami to support this please let me know.

1 Like