Open the editor

Layered (n-tier) architecture

Presentation, business logic and data access stacked so each layer calls only the one below.

Layered (n-tier) architecture diagram: Presentation layer, Business layer, Persistence layer, Database, Cross-cutting concerns

A layered architecture stacks the code in horizontal layers, each with one job: presentation handles input and output, the business layer holds the rules, the persistence layer talks to the database. A layer calls only the layer directly below it, so a change to the database code does not ripple into the UI.

When the layers also run on separate machines it is called an n-tier architecture, such as the classic three-tier web application. It is the structure most frameworks give you by default, which is why it is so common.

The parts of the pattern

Presentation layer
Pages, API controllers and input validation. No business rules here.
Business layer
The rules of the domain: pricing, permissions, workflows.
Persistence layer
Repositories or an ORM that turn objects into rows and back.
Database
Where the data lives, reached only through the persistence layer.
Cross-cutting concerns
Security, logging and caching, used by every layer, usually through middleware or aspects.

How it works

  1. A request arrives at a controller in the presentation layer.
  2. The controller validates the input and calls a business service.
  3. The business service applies the rules and asks a repository for data.
  4. The repository queries the database and the result travels back up the layers.

When to use it, and when not to

Good fit

  • Most CRUD applications and internal tools.
  • Teams that want a familiar, framework-supported structure.
  • You want to swap or test one layer (for example the database code) without touching the others.

Think twice

  • The business rules are complex: the domain ends up depending on the database layer. Hexagonal or clean architecture invert that.
  • Every feature touches every layer anyway, so layers become ceremony: organise by feature instead.
  • Layers are skipped "just this once" until the boundaries mean nothing.

Edit this diagram

Click Open the diagram in the editor to get your own copy, saved in your browser. Rename the boxes to match your system, swap the generic boxes for technology icons from the palette, then export a PNG, SVG or PDF, or share a link. No sign-up.