Layered (N-Tier) Architecture
Organise code into horizontal layers (Presentation, Business Logic, Data Access) where each layer only calls the one below it.
★★★★★5/5Inside a codebase — classes, modules, files
Interactive visualization
LiveThe Golden Rule
Each layer only calls the layer directly below it. A request travels downward; a response returns upward. No layer skips another; no inner layer knows about the outer ones.
How it works
Layered architecture is the most widely used architectural pattern. It divides an application into logical layers, each with a well-defined role. The classic three-tier model: Presentation (UI), Business Logic (Services), and Data Access (Repositories/DAOs).
Requests flow downward through layers; responses travel back up. Strict layering means a layer only calls the layer directly beneath it. Relaxed layering allows skipping layers for performance.
Why it matters
Layered architecture is the default starting point for most applications — it's easy to reason about, maps to common team structures, and is supported by every major framework.
✓ When to use
- →Standard web applications and APIs
- →Teams organised by technical function (frontend, backend, data)
- →Applications with clear separation between UI and data logic
✗ When NOT to use
- →When layers become meaningless pass-throughs with no logic
- →High-performance systems where inter-layer calls add unacceptable overhead
Trade-offs
Simple, universally understood structure
Can lead to 'sinkhole anti-pattern' — empty layers just passing calls
Easy to test each layer independently
Changes to data model often cascade through all layers
In production
Spring MVC, Django, Rails all enforce layered patterns by convention
ERP systems built on strict three-tier client/server architecture
Industry adoption
Related principles
Clean Architecture
LiveOrganise code into concentric dependency rings so business logic never depends on frameworks, databases, or UI.
Domain-Driven Design
Model software around the core business domain using a shared language between developers and domain experts.