---
name: 37signals-style
description: Apply 37signals' opinionated Rails style (Fizzy, Campfire, DHH's reviews) - rich models over service objects, state as records instead of booleans, CRUD-only routing, predicate-method authorization, vanilla Rails over gems. Use for Rails coding, refactoring and review in apps that follow 37signals/DHH conventions, or when the user asks to write Rails "the 37signals way".
---

# 37signals Style

The opinionated layer on top of `rails-best-practices-core`. Distilled from 37signals codebases (Campfire, Fizzy) and DHH's review patterns. Not everyone writes Rails this way; apply it where the app already does, or where the user asks for it.

## Rich Models, No Service Layer

- Domain behavior lives in models. No `app/services/`, form objects or decorators.
- **POROs live in `app/models/`**: presentation objects (`Event::Description`), complex operations (`SystemCommenter`), view-context bundles (`User::Filtering`). They're model-adjacent, not controller-adjacent.
- **Slice large models into concerns** named for capability (`Closeable`, `Watchable`, `Assignable`), each self-contained (associations + scopes + methods), ~50-150 lines, cohesive. Prefer nested modules under the model's namespace (`Card::Closeable` in `app/models/card/closeable.rb`) for domain slices; reserve `app/models/concerns/` for genuinely cross-model behavior. Never extract concerns containing only private methods.
- **Association extensions for bulk domain operations:** define `grant_to`/`revise` on the `has_many` proxy; use `insert_all` for bulk creates and `dependent: :delete_all` on join tables with no callbacks.

## State as Records, Not Booleans

Instead of `closed: boolean`, create a `Closure` record with `creator` and timestamps. You get who/when for free, and scoping is trivial:

```ruby
has_one :closure, dependent: :destroy
scope :closed, -> { joins(:closure) }
scope :open, -> { where.missing(:closure) }
```

## Request Context

- **Current attributes** (`Current.user`, `Current.account`), with cascading setters (assigning `session` resolves `identity`, which resolves `user` for the account).
- **Default values via lambdas:** `belongs_to :creator, class_name: "User", default: -> { Current.user }`; `belongs_to :account, default: -> { board.account }`.
- **Human-friendly URLs:** override `to_param` with a per-tenant `number` rather than exposing raw IDs/UUIDs.

## Everything Is CRUD

- Turn verbs into nouns. Close → `resource :closure` (POST closes, DELETE reopens); publish → `resource :publication`. No custom member actions.
- Singular `resource` for one-per-parent state; `scope module:` to group nested controllers (`Cards::ClosuresController`); shallow nesting for deep hierarchies.
- Resource-scoping controller concerns (`CardScoped` sets `@card` via `Current.user.accessible_cards.find_by!(...)`) shared across nested controllers, including shared Turbo render helpers.
- Same controllers serve HTML/Turbo/JSON via `respond_to`; no separate API namespace.

## Authorization Without a Library

- No Pundit/CanCanCan: simple predicate methods on models (`card.editable_by?(user)`, `user.can_administer_board?(board)`).
- Controllers check (`head :forbidden unless ...`), models define what the permission means.
- Declarative controller macros for auth posture: `allow_unauthenticated_access`, `ensure_can_administer`.

## Vanilla Rails Over Gems

Before adding a gem ask: is 50-150 lines in-repo simpler than a dependency? Commonly skipped: Devise, Pundit, ViewComponent, RSpec, FactoryBot, Redis (Solid Queue/Cache/Cable use the DB), service objects, form objects, decorators, GraphQL, SPA frameworks, Tailwind.

Testing in this style: `37signals-testing`. Review in DHH's voice: `dhh`.

## Always Flag

- Service objects replacing straightforward model methods.
- Non-RESTful custom actions when resource modeling is clearer.
- Boolean state columns where a record would capture who/when.
- Authorization gems or policy objects where a model predicate would do.
- Private-only concerns: inline them.
