Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Layered Architecture

โญโญ intermediateโณ 13 min read๐Ÿ“ Lesson 106 of 180

Controller โ†’ service โ†’ repository, the arrows-point-down rule, and what each layer tests like.

Layered architecture

Three layers cover most services:

Controller/UI  โ†’  parses input, calls service, maps result
        โ†“ depends on
Service        โ†’  business rules, orchestration, transactions
        โ†“ depends on
Repository     โ†’  persistence (Module 11)

The dependency rule: arrows point down only. A service never calls a controller; a repository never calls a service. Cross-layer calls flow through narrow interfaces.

Why layers earn their keep:

  • business rules live in ONE place (the service), not scattered in UI and SQL
  • each layer tests differently: fast unit tests for services, contract tests for repositories
  • swapping delivery (CLI โ†’ REST) doesn't touch the service

The failure mode this prevents is the god class โ€” 1,200 lines that parse, validate, compute, persist, and print, none of it testable in isolation.