Adopting a Clean Architecture design pattern + suggestions #351
Replies: 1 comment 3 replies
-
|
Thanks for the deep dive!
I am a big fan of Retrofit but in this phase we don't need to do any API call, so useless now.
+1 for that
+1 also for that About the Clean Architecture. I am not a big fan of the Clean Architecture TBH, I would suggest this kind of approach, that basically takes the good part of Clean Architecture, but it remains more flexible. I guess it's called Technical architecture, I don't know, I am not very interested in this kind of naming. Please read all the comments for better context. This is usually my setup, it scales pretty well also for very large apps. Ofc it's a proposal, we can iterate on top of it, and we can merge it with the Clean Architecture one. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Intro
Hello everyone! I just recently joined the project since I learned that it was made with Flutter 😁
I have been using Flutter professionally for 3 years now, while using it for personal projects since 2018 (I feel old saying that 🥲).
For the past year and a half, I have been in a decision-making role within a team of about 10 Flutter developers.
When the project started, I carefully studied the existing design patterns in order to best collaborate concurrently on the same project.
The choice eventually fell on a Clean Architecture (feature-based), which with proper task management brought tremendous benefits in terms of time and development.
1. Why Clean Architecture in Flutter?
Many Flutter projects start with a simple structure, but as they grow, they become difficult to maintain. Some common problems:
Advantages of Clean Architecture:
Comparison with other architectures:
2. Project Structure
In feature-based Clean Architecture, the project is structured by functionality rather than just by layers. Here’s an example folder structure:
✅ Each feature is isolated and independent
✅ Easier to scale by adding/modifying features
✅ Improved testability
3. Domain Layer
The domain layer is the core of business logic and is independent of frameworks or technical details.
Entities
Entities represent the fundamental objects of business logic.
I really suggest to use freezed package to handle entities/models, having the benefits of immutability suggested also by Riverpod itself (see the docs).
4. Data Layer
The data layer implements data sources (API, database, etc.) and repositories.
Instead of manually handling API calls, I suggest using retrofit to define the API client
✅ Less Boilerplate – No need to manually write HTTP requests
✅ Type-Safe API Calls – Enforces structured responses
✅ Automatic Code Generation – Keeps API calls clean and modular
5. Presentation Layer
The presentation layer contains UI and state management.
State Management
For status management, I recommend moving to the code generation version of Riverpod, as it reduces development time and simplifies maintenance.
Conclusion
Adopting this type of architecture would allow moving toward more structured project management, helping in terms of scalability and maintainability.
In addition, I have been able to confirm that this type of architecture is crucial in a project where several people are collaborating at the same time, as it allows working on separate modules while avoiding merge conflicts as much as possible.
I remain available for any questions or to discuss the proposal!
SOCOMUNQUESOOOOOOLDI
Beta Was this translation helpful? Give feedback.
All reactions