Layered Architecture
Organise an application into horizontal layers (presentation, business logic, data access) where each layer only talks to the one below it.
Description
The most familiar structure: a presentation layer handles HTTP or UI, a business layer holds the rules, and a data access layer talks to the database. Each layer depends only on the layer directly beneath it, so a change to the UI doesn't ripple into SQL.
It's easy to understand and a sensible default for small and medium applications. Its weakness shows as the system grows: features cut across every layer, so one change touches three folders, and business logic tends to depend on database details unless you're careful.
System design
Layered Architecture system design diagram
- Browser (client).
- Presentation (gateway): controllers, views.
- Business logic (service): services, rules.
- Data access (function): repositories.
- Database (database).
- Step 1: Browser → Presentation: HTTP request.
- Step 2: Presentation → Business logic: placeOrder(dto).
- Step 3: Business logic → Data access: save(order).
- Step 4: Data access → Database: SQL.
- A request arrives at the presentation layer, which parses input and formats output.
- It calls the business layer, where the rules live: is the order valid, what does it cost?
- The business layer asks the data access layer to persist the result.
- Only the data access layer knows SQL and the database. Each layer calls the one directly below it, never upwards.
When to use it
Use it when
- Small to medium applications, especially CRUD-heavy ones, built by one team.
- A team that needs a simple, widely understood structure to start with.
- Prototypes and internal tools where speed of development matters more than long-term flexibility.
Avoid it when
- The domain is complex and you want business logic fully independent of frameworks and databases. Hexagonal architecture isolates it better.
- Several teams work on different features at once. Organise by feature (modular monolith) instead of by technical layer.
Pitfalls
- The anemic domain: business layer methods that just pass data from controller to repository, with real rules scattered in controllers or SQL.
- Skipping layers (UI calling the database directly) "just this once", eroding the structure.
- Business logic depending on ORM entities and database types, so swapping storage or testing in isolation is hard.
- Every feature change touching every layer, which slows teams as the app grows.
Alternatives
Hexagonal Architecture
Choose it when business logic should be the centre, independent of UI, database and frameworks.
Modular Monolith
Choose it when you want to split the codebase by business capability, with layers inside each module if you like.
Microservices
Choose it when separate teams need to deploy separate capabilities independently.