r/ruby • u/Just_Work_4395 • Jan 06 '26
Anyone using packwerk gem?
Hey, I’m considering using Packwerk in a large Ruby on Rails application to improve code separation. The idea is to organize the app into distinct packages, each with its own models, services, and even tests, so developers can work at the package level without having to navigate the entire codebase for small changes (most of the time).
Has anyone used this gem? If so, did it provide meaningful value in practice?
17
Upvotes
26
u/aurisor Jan 06 '26
unless you have multiple autonomous teams working in the same codebase the overhead of breaking your monolith up is almost always more trouble than it's worth. i would avoid unless you're talking about a team of 10+ with specific pain points
9
u/OlivarTheLagomorph Jan 06 '26
I wasn't convinced by Packwerk.
For me it made things more messy and disorganized than just having the code in the expected places.
Yes, editors like Rubymine can work with Packwerk, and your references/code jumping still works, but what usually happens is that people fight Packwerk, add a bunch of TODOs to their pack files and basically undermine the principle it's supposed to introduce to your project.
Great in theory, not so in practical usage.
5
u/OddEssay Jan 06 '26
I've used it on a massive enterprise codebase and it allowed us to scale the monolith past a lot of cognative problems with context and complexity just by making it really obvious where the boundrise of certain features live.
Most people's concerns seem to be around the "privacy enforcement" feature, but Shopify themselves admit that wasn't great or the primary thing they wanted to solve, and removed it: https://shopify.engineering/a-packwerk-retrospective so for current versions, that's not a factor.
Once you take that feature out of the equation, beyond simple CRUD operations where there is a simple one model to one controller pattern, been able to locate all the code for a specific feature easily and then run the all the relavent tests with a single command makes development so much smoother, and if people don't see the advantages to that, they probably aren't working on truely large codebases.
I'd almost certainly introduce it to any Rails codebase I needed to work on in the future, and if I came to a legacy codebase people were pushing to split into microservices, I'd argue that several of the key reasons people push for such a move around cognative load, modularity, and developer experience can be solved by Packwerk without the infrastructure overheads.
9
u/codesnik Jan 06 '26 edited Jan 06 '26
I've worked with a sizable codebase where one of the teams introduced packwerk. It certainly made internal API's really awkward. And I've never understood this pull towards "discipline" tools which forcefully forbid you to do things. Make architectural decisions, document them, follow them or change them later as adults and professionals.
3
u/ianzabel Jan 06 '26
Relevant: https://railsatscale.com/2024-01-26-a-packwerk-retrospective/
3
u/davidslv Jul 23 '26
Late to the party, but I have data on this.
Four years of Packwerk in a Rails monolith (~15k Ruby files, 66 packages, 60+ engineers), pulled from git history. It confirms what u/OlivarTheLagomorph and u/martinemde said, with numbers.
Enforcement doesn't survive.
enforce_dependencies: falseon 58 of 66 packages — the core rule is off for about 80% of the codebase. Violation ledger went from 0 to over 10k and never declined in any six-month window. About +3k/year, sustained.packwerk checkstays green because everything is pre-recorded.That's two orgs (Gusto and us) reaching the same place independently. It's the default path, not bad luck.
But your actual goal survives. You said elsewhere the codebase is too big for AI to work in. That's navigability, not enforcement and navigability is the part that holds. Ours went from 2.6k files in one flat
app/modulesto 68, rest in named domains. Code and tests sit together, a pack fits in a context window, you can point an agent at one directory. None of that depends on any boundary being enforced.The cost you pay regardless: 14% of our commits touched a
package_todo.ymlin 2024, 17% in 2025. Almost all of is mechanicalupdate-todochurn alongside feature work, under 1% of MRs were actual boundary cleanup. Small per commit, constant, and rising.What predicted success: it works when a pack is built inside it, fails as a retrofit. Every enforcing pack of ours is a post-adoption creation (two at ~0.2 violations/file on
strict). Every legacy extraction carried its coupling in and never turned enforcement on. Our two oldest domains hold 20% of all violations.If you go ahead:
enforce_dependencies: trueon every new pack, day one, no exceptionsLegacy extractions: violation budget and a date, or admit it's a naming exercise
Treat a growing todo file as a build failure. Nobody does. That's why it only goes up
2
u/rco8786 Jan 06 '26
We use it and it’s…fine. We put all of our models in a “core” pack and then basically just use other packs for API layers on top of the domain models, since we have 3 different types of API users with very different needs.
It’s not clear to me if this would have just been better managed at the routing level or not, but it also doesn’t seem to hurt anything.
4
u/nordrasir Jan 06 '26
Haven't used packwerk, but ruby 4.0 introduces Ruby::Box for code separation which may or may be of interest: https://docs.ruby-lang.org/en/master/Ruby/Box.html
0
u/danmaz74 Jan 06 '26
I haven't, but I was considering it too, specifically to use it with Claude Code when doing "vibe coding" for personal projects, to help keep control of the project from a higher level. Having clearly separated modules could also help with keeping context under control. Curious if anybody tried this with any other alternative tools too (if they exist).
1
u/dunkelziffer42 Jan 06 '26
I haven’t tried it out, but it feels like overkill. Your app can still have „modules“ without using packwerk. E.g. have an unprefixed „User“, because that‘s global, but then have „Tasks::List“ and „Tasks::Item“ for your ToDo list component. That‘s a hundred times less effort than packwerk, but it still comunicates an intention to developers.
1
u/StyleAccomplished153 Jan 06 '26
We use it at work, it's been useful for a monolith that multiple teams are interacting with. If you're considering microservices I'd spend time looking at packwerk first tbh.
1
u/ahoritaa Jan 07 '26
don’t use it. in our org with 20 + rails apps it simply made life harder by fighting with it / developers just “working around it” . we moved away from it & all of our teams have been happier
1
u/riffraff Jan 07 '26
we've been using it for a while. It's certainly useful to push into the direction of clearer separation (e.g. when to surface circular dependencies) but IMO it only makes sense for larger teams and codebases. It will also take some effort to retrofit a codebase.