Layered: Package by Feature, Layer Inside It

Layered: Package by Feature, Layer Inside It An architecture diagram generated by Archify. controllers/ · protocol, auth, mapping · Package by layer: a feature is smeared controllers/ protocol, auth, mapping services/ · use case, transaction boundary · Package by layer: a feature is smeared services/ use case, transaction boundary repositories/ · queries, row mapping · Package by layer: a feature is smeared repositories/ queries, row mapping feature: discounts · one change, four directories · Package by layer: a feature is smeared feature: discounts one change, four directories checkout/ · handler, service, repository · Package by feature: layers live inside checkout/ handler, service, repository billing/ · handler, service, repository · Package by feature: layers live inside billing/ handler, service, repository public interface Package by layer: a feature is smeared Package by feature: layers live inside Legend Backend Database External

The rot

  • • Layers are technical, features are not
  • • services/ becomes a drawer of 1,200-line classes named after nouns
  • • Logic drifts into controllers and into SQL because both were closer

Rule one

  • • Package by feature, layer inside it
  • • Layers are an excellent rule within a module
  • • This buys most of the benefit people go looking for in fancier styles

Rule two

  • • The application layer owns the transaction
  • • Drift upward and HTTP tangles with commit semantics
  • • Drift downward and you get partial writes nobody can reason about