clean_framework 0.5.0
clean_framework: ^0.5.0 copied to clipboard

Clean Architecture components library, inspired on the guidelines created by Uncle Bob.

Clean Framework #

pub package licence

Clean Architecture components library, inspired on the guidelines created by Uncle Bob.

Learning Resources #

  1. Introduction, to understand the relationship between the components of the framework.
  2. Navigating with CFRouter, to start using high level Navigator 2.0 APIs bundled with Clean Framework.
  3. Mockoon Installation, since the tests in the example folder require an instance of Mockoon running.

Installation #

1. Depend on it #

Add this to your package's pubspec.yaml file:

    clean_framework: ^0.4.0

2. Install it #

You can install packages from the command line: with Flutter:

$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it #

Now in your Dart code, you can use:

import 'package:clean_framework/clean_framework.dart';

Folder Structure #

Whatever name is used for feature_name can replace feature in the file names of the feature's directory

|-- feature_name
|   |-- api
|   |   |-- feature_service.dart
|   |   |-- feature_service_request.dart
|   |   |-- feature_service_response.dart
|   |-- bloc
|   |   |-- feature_bloc.dart
|   |   |-- feature_service_adapter.dart
|   |   |-- feature_usecase.dart
|   |-- model
|   |   |-- feature_entity.dart
|   |   |-- feature_view_model.dart
|   |-- ui
|   |   |-- feature_widget.dart
|   |   |-- feature_presenter.dart
|   |   |-- feature_screen.dart

Layers #


The API module defines the logic for your API services, request, and response. The module defines the logic for REST API request and response that will be consumed by the Bloc.


  • Every Feature Service class should extend EitherService<JsonRequestModel, JsonResponseModel> from clean_framework_defaults.dart


  • Every Feature ServiceRequest class should extend Equatable and implement JsonRequestModel from clean_framework_defaults.dart
  • Every Feature ServiceResponse class should extend Equatable and implement JsonResponseModel from clean_framework_defaults.dart

Bloc #

The Bloc module represents the logic of data flow within the application. It is the middle layer between the API and UI layers. The Bloc is responsible for updating the pipe when the data changes.

Bloc Class

  • Every Feature Bloc class should extend Bloc from clean_framework.dart
  • Responsible for updating the ViewModel as the data coming from the API changes


  • Every Feature ServiceAdapter should extend ServiceAdapter from clean_framework.dart
  • Responsible for connecting the contents of the API and the UseCase
  • Called when a UseCase requests data or sends data


  • Every Feature UseCase should extend UseCase from clean_framework.dart
  • Contains app-specific rules/commands
  • Responsible for the flow of data within the app

Model #

The Model module defines the business logic of the application. This module consists of two main classes: Entity and ViewModel. The Entity class determines how the model class will be represented in the Repository (in locator.dart). The ViewModel class represents how the data is passed through to the UI. The Presenter passes the ViewModel to the Screen when the Presenter is called in the Widget.


  • Every Feature Entity class should extend Entity from clean_framework.dart
  • Made up of classes that represent the data in the Repository


  • Every Feature ViewModel class should extend ViewModel from clean_framework.dart
  • Made up of classes that represent how the data is presented to the UI

UI #

The UI module is responsible for all things UI, from triggering the bloc to update the UI, to painting the screen with data send from the UI.


  • Every Feature Widget should extend StatelessWidget
  • Responsible for kickstarting the Bloc and return the Presenter
  • Is called in main.dart when the feature is the first screen, or in a Navigator when switching to that feature


  • Every Feature Presenter should extend Presenter from clean_framework.dart
  • Responsible for calling appropriate methods as data reaches different stages


  • Every Feature Screen should extend Screen from clean_framework.dart
  • Responsible for building UI widgets; should not include any logic other than UI
pub points

Clean Architecture components library, inspired on the guidelines created by Uncle Bob.

Repository (GitHub)
View/report issues


API reference


BSD-3-Clause (LICENSE)


equatable, flutter, flutter_riverpod, flutter_test, http, meta, provider


Packages that depend on clean_framework