Home

What I Learned Reading 37signals' Code

· 2 min read

Most of us learn Rails from tutorials and then spend years learning it again from production. Reading code written by the people who made Rails is a shortcut I wish I'd taken earlier.

37signals released the source of Campfire and Fizzy, and I spent a few weekends reading them like books. A few things stuck with me.

Rich models, thin everything else

There are no service objects with names ending in "Service." Behavior lives on the models, split into small concerns named after what they do: Card::Closeable, Card::Assignable. A model reads like a list of capabilities.

class Card < ApplicationRecord
  include Assignable, Closeable, Golden, Watchable
end

Controllers are boring on purpose

Instead of custom actions, they create new resources. Closing a card isn't CardsController#close, it's Cards::ClosuresController#create. Every controller ends up with the same seven verbs, so you always know where to look.

Fewer dependencies than you'd expect

Hotwire for the front end, the database for jobs and caching, and very few gems. Every dependency you skip is one you never have to upgrade at 2am.

The code wasn't clever. It was obvious, and that's much harder to write.

I don't copy everything. A large accounting system has different pressures than a small product. But the core lesson travels well: when in doubt, choose the boring option that a new teammate will understand on day one.