Layered Architecture (N-Tier)

Organize code into horizontal layers.

“Presentation -> Business -> Persistence -> Database”

The traditional enterprise monolith.

graph TD
    UI[Presentation Layer] --> BL[Business Logic Layer]
    BL --> DA[Data Access Layer]
    DA --> DB[Database]

When to use

  • Simple CRUD Apps: Standard structure.
  • Enterprise Apps: Java Spring, .NET.

Explanation

  • Strict Layering: A layer can only call the layer directly below it.
  • Separation: Changes in UI shouldn’t affect DB.

Pros and Cons

Pros Cons
  • Easy to understand
  • “Sinkhole” anti-pattern (requests pass through empty layers)
  • Standard
  • Tight coupling between layers (often)
  • Code example

    Typescript