Layering decoupled and cohesive applications

Something I wish I had known earlier in my career is that all applications consist of four layers with specific responsibilities:

  • Presentation layer: UI (views).
  • Application layer: orchestration (routers, controllers, input validation).
  • Domain layer: business logic and invariants.
  • Infrastructure layer: persistence, data transfer, low-level operations.

And there’s an implicit order of dependencies: higher layers should depend on classes/functions from lower layers. If a lower layer needs to communicate with a higher layer, it should do so through events.

This has greatly helped me understand and design highly decoupled, cohesive, applications.