In this article, I will introduce the layers of the application. Java applications have layers like a birthday cake. I will present the three main layers of the application and the auxiliary layer that connects the other layers and the database. Before I start the detailed description, I will explain why it is so important that the application is divided into layers.
Introduction to layers
Dividing applications into layers - classes and packages - is a good practice in programming, it can be said that without it no commercial applications are created, and it's not just about the Java language. Each layer is represented by a separate class placed in a separate package. Packages (folders on disk) logically group classes (files on disk), thereby creating layers. However, a class in a given package represents the implementation of a given layer, which contains the appropriate functionality, i.e. a role or task to be performed.
The figure below shows the layers in a three-layer application.

Examples of layers
A typical Java application consists of the following layers, which I will describe in detail later:
1. Presentation layer, GUI,
2. Business logic layer, service,
3. Data access layer, dao, repository,
4. Intermediate layer, mapper, aggregate,
5. Database.
The above nomenclature may vary depending on the selected technology in which the application was created.
Spring Framework
- Presentation layer
- Service layer
- Repository layer
- Intermediate layer, Mapper
- Database
Java/Jakarta EE
- Presentation layer
- Business logic layer
- DAO layer
- Lack of – intermediate layer
- Database
UML diagram
Below is an example of a three-tier application with classes/objects exchanged between layers using an intermediate layer. To exchange data between layers, we use e.g. Model/DTO, Entity/VO, and mapper, aggregate - described in detail below.

Description of layers
Below is a detailed description of each layer along with examples of their use. In short. The presentation layer is the so-called front-end, which contains elements visible to the user in graphical form, e.g. website, and windows in the graphical user interface. The back-end is the business logic layer, data access layer, and the intermediate layer; these layers are not visible in graphical form to the system user. A database is simply a repository, a data source, or a data warehouse that stores data.
Presentation layer
I will describe this layer based on a website that displays HTML. HTML alone is not enough, you need a web application framework that provides a system of HTML templates. Additionally, such a framework uses the MVC. Why isn't HTML alone enough? HTML is supposed to create static web pages, but Javascript adds interaction with the user in the web browser. Static pages are those that are displayed exactly as they were written in HTML, Javascript operates on HTML elements.
To communicate and share dynamic data returned by the application server, the back-end, we need dynamic HTML, which we obtain using web fremworks with a template system. An example of a presentation layer may be a web form enabling a bank transfer. On this form, we provide the transfer details, amount, and date of the transfer. The collected data is sent to the back-end, the business logic layer.
Business logic layer
Also called service, it contains application logic that enables the processing of incoming data from e.g. www and returns the processing result. This layer contains algorithms, data validation, and calculations on the data. Service is an intermediary between the presentation layer and the data access layer. This layer also includes an intermediate layer, a mapper, and an aggregate.
An example of a business logic, service layer may be the application code verifying a bank transfer ordered by the user via www. Before making a transfer, the back-end will first check whether the customer has available funds in the account and whether the transfer is scheduled for banking day, i.e. the bank's working day. It can also activate anti-money laundering mechanisms and many others. A lot of things happen on the back-end.
Data access layer
This layer is responsible for persisting and saving performed operations to e.g. a database. What does it mean? Let's take the bank transfer above as an example. After the transfer is completed correctly, information is saved about who and when made the transfer, for what amount, and what the balance was after and before the operation. Such data will later be used to display the history of transfers in our bank account and, for example, to generate a chart of our expenses. Without recorded, recorded data, this would not be possible.
Intermediate layer
Can act as a mapper, aggregate is used between:
– the presentation layer and the business logic layer, service,
– the business logic layer and the data access layer.
The relationship between the layers is bidirectional.
Why do we need a mid-layer at all? In most cases, it is used to replace one type of object with another. What does it mean? This means that different layers use different types of objects:
– the presentation layer using MVC, uses classes that are Model/DTO – Data Transfer Object,
– the data access layer uses classes that are Entity/VO – ValueObject.

Above is an example of Mapper for the middle layer. The bank transfer function described earlier will serve asan example of an intermediate layer, mapper, aggregate.
Why do we need DTO, VO, Entity, Model?
As you can see above, in different layers the classes are different from each other, they have more or less fields in the class and this is the first reason why we need an intermediate layer. The second reason is not to mix data validation on different layers. Additionally, the data types in DTO and VO may be different and will require conversion, which is another reason to use a middleware.
When displaying a list of our transfers, we want to ensure that we receive the data unchanged. From the programming side, to achieve this in the data access layer, you should use Entity/VO - Value Object, which guarantees that the values (e.g. transfer amount) in the class will not change while passing through the layers. You can read about Value Object immutability - Value object – Wikipedia. In this layer, the data already has a specific type, unlike the presentation layer.
When entering data via the website, we provide the necessary data to complete the transfer, here we can use DTO and/or Model. The data entered by the user may be incorrect, please verify their correctness and display an appropriate message. Additionally, in most cases, data comes to the presentation layer in the form of text, without a specific type, unlike the data access layer. The presentation layer transfers data to the business logic, service layer using the intermediate, mapper, aggregate layer.
Photo by me, as a background tool IntelliJ IDEA – the Leading Java and Kotlin IDE.