"I know who you are and because of that I know what you do." This knowledge is a dependency that raises the cost of change.
-- Sandi Metz, Practical Object-Oriented Design in Ruby
Packwerk is a Ruby gem used to enforce boundaries and modularize Rails applications.
Packwerk can be used to:
Packwerk needs Zeitwerk enabled, which comes with Rails 6.
Packwerk supports MRI versions 2.7 and above.
Watch a 1-minute video demo on how Packwerk works.
gem 'packwerk'
Execute:
$ bundle install
Or install it yourself as:
$ gem install packwerk
bundle binstub packwerk
to generate the binstubbin/packwerk init
to generate the configuration filesRead USAGE.md for usage once Packwerk is installed on your project.
"Packwerk" is pronounced [ˈpakvɛʁk].
Various third parties have built tooling on top of packwerk. Here's a selection of some that might prove useful:
rspec
and FactoryBot
integration, for packages arranged in a flat list. packs-rails is quite convenient, but for autoloading we recommend to use Rails::Engine
s instead.packwerk
itself.After checking out the repo, run bin/setup
to install dependencies. Then, run rake test
to run the tests. You can also run bin/console
for an interactive prompt that will allow you to experiment.
With Ruby being a very dynamic language, static analysis tools such as Packwerk are bound to have limitations. To reduce the impact of those limitations, Packwerk is designed to avoid false positives (reporting references as violations that are actually fine) at any cost, and we pay the cost by accepting a small number of false negatives (failing to report actual violations).
require
) often doesn't follow these conventions.Bug reports and pull requests are welcome on GitHub at https://github.com/Shopify/packwerk.
Read and follow the guidelines in CONTRIBUTING.md.
The gem is available as open source under the terms of the MIT License.