DEV Community

loading...
Cover image for Layered architecture

Layered architecture

devtalker profile image Dimitrov ・2 min read

Layered architecture is the first architectural pattern that we are going to explore. If you haven’t read my article about software architecture, I suggest you do it before continuing with this one.

What is a layered architecture?

Simply put, the layered architecture pattern’s main idea is to group and isolate system concerns while defining strict communication direction between them.

Each group of related modules/classes we call layer. Different layers are encapsulated and depend on each other through abstraction and well-defined interfaces.

Layers in this architecture pattern are stacked. The request direction is from the upper layers to the lower layers. In the best-case scenario, a layer can request a layer that is only directly below it.

In sporadic cases, an upper layer is allowed to request a layer two-level or more levels below, but in general, it is considered bad practice.

Alt Text

Layered architecture is widespread. We can find it the simple client->server pattern or OSI network model. Also, many enterprise applications implement that pattern.

In the following examples, we do not discuss cross-cutting concerns and their implementation.

What is the difference between layered architecture and N-tier architecture?

There is none significant one. By tier, we consider a physical layer (like SQL server, for example). N describes the number of layers/tiers you have.

In general, both names refer to the principles we discuss in this article.

Enterprise application example

Most of the layered architecture implementations consist of four layers (ok, three layers, and a tier).

They are:

  • Presentation layer
  • Business layer
  • Data Access layer
  • Data Storage tire

Their names are explanatory enough, but let’s discuss them in detail.

Presentation layer

In the presentation layer, you can find user interface components.

In a standard ASP.NET Core application, these are the Views. The presentation layer, of course, is not limited to any technology. You can have anything that a user can interact with. CLI, SPA, etc.

The presentation layer should not contain business logic and should not access database data directly.

Its only task is to visualize data and dispatch the user’s input. That’s why the presentation layer requests data and sends commands from/to the business layer.
You can read the full article on my programming blog -> Layered architecture

Discussion

pic
Editor guide