Three-tier Architecture with Flutter
Three-tier architecture is one of the mainly used architecture for developing applications. This architecture is also known as N-tier architecture or multi architecture.
Developers use this method to keep the processing, data management, and presentation functions physically and logically separated. So that these different functions can be stored in separated host servers. This is very useful when scaling the application. In early days we have to copy whole application in every host machine to scale up it. But with this architecture different tiers can be hosted in separated machine to scale up the application.
In three tier architecture these are the main layers,
- Presentation tier : User Interface is implemented here. It is the top most layer. The function of this layer is to translate tasks and results into a form of that user can understand it. Ex: Console , GUI(Graphical User Interface)
- Logic tier: Also known as the domain layer. This tier contains all the business logic of the the application. Algorithms, Data manipulations are implemented here.
- Data tier: This tier store and retrieve data from database or file system. The data from this tier are send to logic layer for processing. API calls are also implemented in this tier
The main Advantage of this architecture is , if we do a change in a tier then it is not affecting to other tiers.
Let’s look at how we can use this Three-tier architecture in Flutter application Development
Presentation layer having the implementation of Widgets, Pages and Presentation Logic holders like BLoC , ChangeNotifiers etc;
The domain layer consist of
- usecases: The use cases consist of classes encapsulated the business logic of a particular business logic of application.
- entities: classes of business entities. Entities are vary from the models in data layer. Entities having the pure implementation of a class data. But in models it may contain some other methods like toJson , fromJson methods. Therefore model and entities should be kept separated.
- repository : The repository should be implemented in both the domain layer as well as the data layer. Because the repository interact with both of those layers.
The data layer consists of ,
- Repository : to connect with the domain layer.
- Models : to handle json,xml data from the data sources. Convert those type of data to a form of class.
- DataSources: Interact with the databases and API. All the http requests ,handling cached data are performed here. This accepts raw data from different resources and send that raw data through a the model.
By using this architecture flutter application can be scale up easily. It is easy when writing the test cases for each features.
Here is a simple flutter application implemented with clean architecture and Test driven development,
It is very helpful for me to improve my knowledge if you can give me some feedback on this blog.