This is a simple e-commerce project built with Flutter, utilizing a modular architecture with separate packages for authentication, products, and cart/checkout functionality.
The project follows the MVC pattern with providers for state management, and uses Flutter Flow for navigation within packages and Go Router for overall app navigation.
It also includes fake API calls with services.
This project has been set up using Melos, a Dart package manager that allows for managing multiple packages within a single repository.
It has been inspired by the Flutter Modular Architecture aka Lego Style by Anna and Oleksandr Leushchenko.
The idea is to have a single repository with multiple packages, each containing a feature or a module of the app.
This allows for better separation of concerns, easier code maintenance, and faster development.
├── app/
│ └── main_app/
├── core/
├── feature/
│ ├── auth/
│ ├── products/
│ └── cart_checkout/
app/main_app
: The main Flutter application that ties everything together.core
: Shared modules and utilities (if any).feature
: Contains individual feature packages:auth
: Authentication package.products
: Products package.cart_checkout
: Cart and checkout package.
-
Create the project directory:
mkdir ecommerce_project
cd ecommerce_project
-
Create subfolders:
mkdir -p app/main_app core feature/{auth,products,cart_checkout}
-
Initialize the main app:
cd app/main_app
flutter create .
cd ../..
-
Initialize the feature packages:
cd feature/auth
flutter create .
cd ../products
flutter create .
cd ../cart_checkout
flutter create .
cd ../..
-
Set up dependencies in each package's
pubspec.yaml
file. Remember to assign package versions as any
To work on a specific feature package:
-
Navigate to the package directory: cd feature/auth
-
Run
flutter pub get
to fetch dependencies. -
If using code generation (e.g., freezed, injectable), run the necessary commands:
flutter pub run build_runner build --delete-conflicting-outputs
-
You can create a small test app within the feature package for isolated testing.
-
Navigate to the
main_app
directory:cd app/main_app
-
Run
flutter pub get
to fetch dependencies. -
Start the app:
flutter run
Melos will ensure all features have the same package version. Read more about it here.
Here are some useful commands when using melos with fvm.
melos clean --sdk-path .fvm/flutter_sdk
melos bootstrap --sdk-path .fvm/flutter_sdk
melos pub-run:all --sdk-path .fvm/flutter_sdk