This message was imported from the Ruby/Rails Modularity Slack server. Find more info in the import thread.
Message originally sent by slack user U73KUSJ2V5Q
Hello, need some support of the initial configuration of “packs” gem (or I need just packwerk?). My app is already a pretty big monolith and we want to start moving some code into components/packs, just to split domains.
Basically, I’m facing now an issue with how to validate that private code from pack cannot be used in the existing codebase (app/models for example)
my Config (I also tried enforce_privacy: true or strict)
And I have such code in app/models/some_file.rb
(CalculateExpectedShipmentData not in public)
def predicted_delivery_details
Rails.cache.fetch("delivery_promise_predicted_delivery_details_id_#{merchant.id}_#{warehouse.id}",
expires_at: Time.current.end_of_day) do
ExpectedShipmentData::CalculateExpectedShipmentData.new(warehouse:1, merchant:1).call
end
end
rubyatscale/packs is a bit more complex under the hood and more opinionated, which has advantages (more convenience) and disadvantages (less flexibility). I’d personally lean towards the simpler solution.
There are also two blog posts from Shopify that talk about the danger of privacy enforcement in an otherwise tightly entangled monolith:
I’d recommend starting with disentangling the dependencies. That’s also the reason why privacy enforcement was removed from packwerk itself and moved into an extension.
Furthermore, packwerk and the rubyatscale/packs tooling is geared towards making the monolith easier to think about, gradually. If you think you can go from the current state to fully isolated (maybe in small parts) in a few weeks, you probably want to take a slightly different approach, for example starting with separated test suites. Packwerk can help you gradually get closer to that goal but because of its focus on static dependencies you shouldn’t overestimate its ability to keep code from executing together.
Just a few more questions:
• do you know if there is an example app with few components (a little bit more complex then 1 mentioned in 1m video, but even that app full source code is not available)
• is it possible to catch a package dependency from a component used inside a regular model (outside any component)?
PS: maybe some of the answers in the resources above, but still want to check.
Sadly I don’t know of an example app. Maybe I should try to create one. I don’t have a concrete reason though other than convincing people that it’s possible
To your second question - it sounds like you should just start experimenting!
If you set up packwerk, you can drop a package.yml into any folder and see what happens. Any folder with a package.yml is a package.
You‘ll see that packwerk initialisation creates a package.yml in the root folder of your app, which means that everything is in the root package by default.