rails-architecture
Installation
SKILL.md
Rails architecture
The core tension in Rails: the convention "fat models, thin controllers" is correct about controllers and frequently wrong about models. Both failure modes are common.
Where code belongs
| Change in shape | Put it in |
|---|---|
| One model, a few fields | A scope or a model method |
| Behavior involving one model, no others | A model method or a PORO |
| Behavior spanning 2+ models | A service object |
| Behavior that must run outside a request | A background job |
| Pure computation, no persistence | A PORO or value object |
| Authorization decision | A policy object |
Thin controllers is right. A controller should: authorize, load, call one other object, and respond. When a controller grows a conditional, a loop, or business rules, that logic belongs elsewhere.