rubyatscale / packs-rails

packs-rails establishes and implements a set of conventions for splitting up large monoliths.
MIT License
268 stars 26 forks source link

Question regarding namespacing #4

Closed dipth closed 1 year ago

dipth commented 2 years ago

We've recently started using Packwerk and Stimpack in our organisation and we had a bit of a hard time coming to terms with the expected directory structure needed for everything to work and wondered if you can offer any guidance or input on how you consider the following:

We're running a big Rails monolith that has the classic rails file structure with /app, /spec /lib etc.

When developing new features, we generally take care to namespace these under a unique and descriptive name. For instance a feature for profile pages could be namespaced as ProfilePages resulting in the following directory structure:

packs/
  profile_pages/
    app/
      models/
        profile_pages/
          profile_page.rb
      public/
        profile_pages/
          list_profile_pages.rb
    spec/
      models/
        profile_pages/
          profile_page_spec.rb
          list_profile_pages_spec.rb

This redundant directory structure is necessary for the autoloading to work since profile_page.rb defines ProfilePages::ProfilePage and list_profile_pages defines ProfilePages::ListProfilePages. However, working with the codebase, this structure feels extremely verbose and redundant since all the code is already nested under the packs/profile_pages folder.

Optimally this directory structure would have been more clean and easier to navigate and reason about:

packs/
  profile_pages/
    app/
      models/
        profile_page.rb
      public/
        list_profile_pages.rb
    spec/
      models/
        profile_page_spec.rb
        list_profile_pages_spec.rb

Is this a problem you have dealt with in your daily use of Packwerk and if so what are your thoughts and opinions about it? Do you know if support for something like this structure would be possible to add to Stimpack perhaps by using some of Zeitwerks existing functionality like loader.collapse?

ngan commented 2 years ago

Hey @dipth -- I actually went down this path because I wanted this exact same thing in the early days of creating this gem. However, we are very tied to Packwerk and how packwerk works is based on the assumption that you're using Zeitwerks' directory structure out of the box. Since we can't customize this at the moment, changing this in Stimpack would mean that our Packwerk integrations would fail. I'm going to leave this issue open because I would love to see Stimpack headed in this direction. Just a matter of working with Packwerk to allow us to customize the parser/scanner logic.

TastyPi commented 1 year ago

There's a gem that looks like it is trying to solve this, but I haven't tried it yet https://github.com/gap777/automatic_namespaces

alexevanczuk commented 1 year ago

@dipth Can you let me know if the automatic_namespaces gem covers what you need for now? If so (or if I don't hear back from ya), I'll go ahead and close this issue for now and perhaps add the gem as a reference to the README.

dipth commented 1 year ago

It's ok to close this :)