The project will be organized into multiple modules to separate the different architectural layers of the application. This helps to ensure that the is not directly connected to the , and that all communication between these layers must go through the .
1. Create the Flutter root project
Copy flutter create note_app --org=com.example
2. Create the submodules
Create a folder called modules
in the root of the project. Inside this folder, create the following submodules:
Copy flutter create presentation --template=module --org=com.example
flutter create domain --template=module --org=com.example
flutter create infrastructure --template=module --org=com.example
After creating the modules, your project should look something like this:
Copy root/
└── modules/
├── domain/
├── infrastructure/
└── presentation/
3. Interlink the submodules
Specify the interconnections between submodules by importing the necessary modules for each pubspec.yaml
file.
3.1. Update the domain pubspec.yaml
The domain does not depend on any other modules. Nonetheless, we can simplify the note_app/modules/domain/pubspec.yaml
:
Copy name: domain
description: The domain layer of the application.
version: 1.0.0+1
publish_to: none
environment:
sdk: '>=3.0.6 <4.0.0'
dependencies:
flutter:
sdk: flutter
flutter:
module:
androidX: true
androidPackage: com.example.domain
iosBundleIdentifier: com.example.domain
3.2. Update the Infrastructure pubspec.yaml
Add the domain
submodule to the note_app/modules/infrastructure/pubspec.yaml
:
Copy name: infrastructure
description: The infrastructure layer of the application.
version: 1.0.0+1
publish_to: none
environment:
sdk: '>=3.0.6 <4.0.0'
dependencies:
flutter:
sdk: flutter
domain:
path: ../domain
flutter:
module:
androidX: true
androidPackage: com.example.infrastructure
iosBundleIdentifier: com.example.infrastructure
3.3. Update the presentation pubspec.yaml
Add the domain
submodule to the note_app/modules/presentation/pubspec.yaml
:
Copy name: presentation
description: The presentation layer of the application.
version: 1.0.0+1
publish_to: none
environment:
sdk: '>=3.0.6 <4.0.0'
dependencies:
flutter:
sdk: flutter
domain:
path: ../domain
flutter:
uses-material-design: true
module:
androidX: true
androidPackage: com.example.presentation
iosBundleIdentifier: com.example.presentation
3.4. Update the main pubspec.yaml
Add all the submodules to the root note_app/pubspec.yaml
:
Copy name: note_app
description: The root module of the application.
publish_to: none
version: 1.0.0+1
environment:
sdk: '>=3.0.6 <4.0.0'
dependencies:
flutter:
sdk: flutter
presentation:
path: modules/presentation
domain:
path: modules/domain
infrastructure:
path: modules/infrastructure
flutter:
uses-material-design: true
4. Create the submodule base directories and files
Before proceeding, delete the default main.dart
and widget_test.dart
in each submodule as they will not be needed.
Once done, apply the following base folders and files per module:
4.1. Create the files and folders in the domain submodule
Copy root/
└── modules/
└── domain/
└── lib/
├── note/ # feature directory
| ├── entities/
| ├── failures/
| ├── repositories/
| ├── use_cases/
└── domain.dart # barrel file
4.2. Create the files and folders in the infrastructure submodule
Copy root/
└── modules/
└── infrastructure/
└── lib/
├── data_sources/
├── note/ # feature directory
└── infrastructure.dart # barrel file
4.3. Create the files and folders in the presentation submodule
Copy root/
└── modules/
└── presentation/
└── lib/
├── note/ # feature directory
└── presentation.dart # barrel file