All Projects → guilherme-v → flutter-clean-arch

guilherme-v / flutter-clean-arch

Licence: other
A flutter's implementation of a "clean architecture"

Programming Languages

dart
5743 projects
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to flutter-clean-arch

flutter preload videos
Preloading videos in Flutter 💙
Stars: ✭ 42 (-71.81%)
Mutual labels:  provider, bloc
Flutter Roadmap
This is a flutter roadmap and documentation repository. If anyone is interested you can join the party to help the community and make flutter great again.
Stars: ✭ 47 (-68.46%)
Mutual labels:  provider, bloc
bloc redux
bloc meets redux in flutter world
Stars: ✭ 52 (-65.1%)
Mutual labels:  bloc
flutter-Anniversary
一款界面优美,功能简洁的纪念日APP
Stars: ✭ 57 (-61.74%)
Mutual labels:  provider
Cycle.swift
An experiment in unidirectional architecture inspired by Cycle.js. https://cycle.js.org
Stars: ✭ 24 (-83.89%)
Mutual labels:  architecture
documentation
🍰 Architectural design methodology for Frontend projects
Stars: ✭ 359 (+140.94%)
Mutual labels:  architecture
windows-Credential-Provider-library
This repository will be updated with all the examples and links that I can find with relevant knowledge & information about CP in MS Windows vista up to version 10.
Stars: ✭ 122 (-18.12%)
Mutual labels:  provider
openverse-api
The Openverse API allows programmatic access to search for CC-licensed and public domain digital media.
Stars: ✭ 41 (-72.48%)
Mutual labels:  architecture
ddd-example-ecommerce
Domain-driven design example in Java with Spring framework
Stars: ✭ 73 (-51.01%)
Mutual labels:  architecture
RentMyCPU
💰 An app that allow to earn money by executing computational work from other nodes
Stars: ✭ 156 (+4.7%)
Mutual labels:  provider
fyi
Map & Explore your organization's System Architecture
Stars: ✭ 28 (-81.21%)
Mutual labels:  architecture
react-mvp
Model-View-Presenter Proof of Concept in React
Stars: ✭ 38 (-74.5%)
Mutual labels:  architecture
archi-modelrepository-plugin
coArchi - a plug-in to share and collaborate on Archi models.
Stars: ✭ 104 (-30.2%)
Mutual labels:  architecture
Perfect-Server-Side-Swift iOS-App
A family tree API server implementation with iOS client. Server has been implemented with Perfect: Server-Side Swift And iOS client is in pure Swift.
Stars: ✭ 15 (-89.93%)
Mutual labels:  architecture
XNU
Research into porting the XNU kernel to ARM devices.
Stars: ✭ 76 (-48.99%)
Mutual labels:  architecture
awesome-flutter-provider
😎 A curated list of stuff related to the Flutter Provider library
Stars: ✭ 22 (-85.23%)
Mutual labels:  provider
devonfw4flutter-mts-app
Large-Scale Flutter Reference Application. An Extension of DevonFw's My Thai Star Project
Stars: ✭ 54 (-63.76%)
Mutual labels:  architecture
SherwoodArch
The Sherwood Architecture is a custom 64-Bit RISC based CPU architecture.
Stars: ✭ 13 (-91.28%)
Mutual labels:  architecture
RouterService
💉Type-safe Navigation/Dependency Injection Framework for Swift
Stars: ✭ 212 (+42.28%)
Mutual labels:  architecture
silky
The Silky framework is designed to help developers quickly build a microservice development framework through simple code and configuration under the .net platform.
Stars: ✭ 146 (-2.01%)
Mutual labels:  architecture

app

Flutter Clean Architecture Proposal

Goals

  • Keep code clean
  • Keep code testable
  • Keep codebase easily extensible and adaptable
  • Test different State Managaments libraries (currently: BLOC, Provider, States Rebuilder and State Notifier)

Architecture Overview

architecture

As described in Uncle Bob's webpage, clean architecture enforces the separations of concerns dividing the software into layers. Each one of these layers focuses on doing one single thing, so it follows the Single Responsibility Principle. They also have their own Model representations and any communication needed with external layers are made through the use of abstractions.

The architecture also follows the Dependency Rule, which states that an outer layer can depend on an inner layer, but the other way around is not possible. As result, the application becomes highly decoupled, easy to maintain, to test and to adapt.

Known limitations

  • The initial set up involves dealing with some boilerplate code

Known benefits

  • A/B testing can be applied easily, and it will touch only one layer (the Presentation Layer).
  • Feature toggle can be used easily, both to enable/disable features or to try out new ideas (without needing to release a new version).
  • All layers can be unit tested independently.
  • Unidirectional data flow makes it easy to understand the code.
  • We can use different State Managements libraries (Provider, BLOC, States Rebuilder, State Notifier...) on the Presentation layer, or even try out new ones easily if needed

Details

architecture

MobileUI

Presentation

The application user interface. It depends on the Flutter Framework containing classes responsible for:

  • Build the UI: like Widgets, BuildContexts, and others.
  • Hold the Presentation logic: ChangeNotifier, BLOC, ViewModels, and others.

The presentation logic will receive data from the Domain's use cases, and then it will prepare these data to be presented on the UI. In general, it is the recommended place to format/internationalize things. For example, it can receive from the Domain a DateTime object with the format "1969-07-20 20:18:04Z" and prepare/format this data to be presented on the UI according to the user's device language.

Domain

It represents the domain of the problem we are trying to solve, that is, your business rules. It is the architecture's central layer, therefore, it has no dependencies on external layers and should be a plain dart module. It includes:

  • plain entity classes (like Character entity)
  • usecase classes, that encapsulate all the business logic related to a particular usecase (like GetAllCharacters, SignInUser, and others...)
  • data access abstractions (Repository Interfaces)

A use-case has no clue if the data it'll receive comes from a memory cache, local storage, or the internet. All these details were abstract out by the use of the Repositories' Interfaces, and from the use-case point of view, all that matters is that it'll receive its data.

Data

It is the layer that implements the data access abstractions (Repository Interfaces) defined into the domain. In other words, it is the layer responsible for providing data to those use cases. It is "the brain" that knows how/when to fetch data from the network or local cache, and how/when to cache things. It includes:

  • It is the Implementations of repositories defined by domain layer
  • It'll hold/manage any in memory caches
  • It'll define Data-source abstractions (like RemoteDatasourceInterface, LocalCacheDatasourceInterface)

It works like a "boundary" between our application and the external world in a certain way. It will "translate" how things are "fetched" from/to the internet, or "loaded" from/to the database, to how these same things are represented in our Domain.

Network

Layer responsible for handle the communication to the network. It has the implementation of the remote abstraction (RemoteDatasourceInterface) defined into the Data layer:

  • We define the endpoints we are going to use
  • We configure any interceptors we need
  • We serialize/deserialize the JSON to Data objects

It represents a "boundary" with the external world. We are translating the "language" our API uses to communicate (JSON) to something that we can understand and work better (Data object).

Local

This layer provides access to any kind of local storage: database, shared preferences, files, and others. It implements the abstractions (LocalCacheDatasourceInterface) defined into the Data layer.

It represents a "boundary" with the inner world. I mean, how we store things in our local device. We can use shared-preferences' key-values, serialize/deserialize things into files, read/write from the database, etc.

The point is: Each method has its way to "save" and "read" things, and this layer will translate this way to objects that our Data Layer knows how to handle.

Generic Error Handling and Data Layer

The Data layer will encapsulate all kinds of try-catches, from this layer upwards there will be no special flow to handle errors. Repositories will return Either a Failure (in case of any error) or a Value in case of success (Either<Failure, Value>).

We will also use two generic classes to represent any kind of error that may occur on the Network layer and LocalCache layer - ServerFailure, and CacheFailure respectively.

If any of these errors occur, Data Layer will also log the event properly. Example:

  1. A use-case asks for all characters available
  2. The repository verify that the Device is online, and it goes on and tries to fetch data from Network
  3. Network layer tries to fetch data from remote API, but an unexpected problem occurs and we've got back an Error 500
  4. The repository catches the error
  5. The repository logs it on Analytics
  6. The repository answers back to use case an Either<ServerFailure, null> object

References

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].