Flutter Architecture CLI
A production-grade command-line tool designed to generate and scale clean architecture codebases in Flutter. It eliminates repetitive setup, enforcing a modular, highly scalable, and team-friendly project structure powered by RxDart streams and Provider.
Tip
Read the complete setup and detailed architectural guide on Medium: Stop Writing Boilerplate: Scaffold a Flutter Clean Architecture App in 60 Seconds!
Table of Contents
- Quick Start
- Features
- Folder Structure
- Usage Guide
- Architecture Flow
- Contributing
- Support & Donations
Quick Start
This package is a Command Line Interface (CLI) tool. You do not need to add it to your project's pubspec.yaml dependencies.
Simply activate it globally on your machine:
dart pub global activate flutter_architecture_cli
Once activated, you can run all commands directly from your terminal using the flutter_architecture_cli command.
Alternative: Add as a Dev Dependency
If you prefer not to install it globally, you can add it as a development dependency inside your Flutter project:
flutter pub add --dev flutter_architecture_cli
Then, run commands inside your project folder using dart run:
dart run flutter_architecture_cli <command>
Features
- Zero-Configuration Architecture Setup: Instant scaffolding covering storage, networking, localizations, utility helpers, and dependency injection.
- Stream-Based State Management: Seamless state handling inside Blocs using RxDart's
BehaviorSubjectandCompositeSubscription. - Centralized Networking: Custom
ApiClientpowered byDiowith automatic logging, secure token handling, and robust exception-handling interceptors. - Unified UI State: Standardized
BaseUiStateclass for mapping screen loading, success, and error states. - Common Widget Toolkit: Reusable components such as
AppText,AppImage,AppTextField,AppButton,AppLoader,AppShimmer, andAppNetworkStatusWidget. - JSON-Based Localization: Fully configured translations with convenient context translation extensions (
context.tr(...)).
Folder Structure
Generating a project produces this structured, clean tree:
lib/
├── common/
│ ├── extensions/ # BuildContext, String, DateTime and Widget extensions
│ ├── helpers/ # Bottom sheets, dialogs, snackbars, and navigation helpers
│ └── widgets/ # Highly reusable common widgets (AppButton, AppLoader, etc.)
├── core/
│ ├── base/ # BaseBloc, BaseMapper, and BaseUiState
│ ├── constants/ # Api endpoints, dimensions, route names, regex, etc.
│ ├── localization/ # Localization service and JSON delegates
│ ├── network/ # ApiClient configurations, interceptors, and custom exceptions
│ ├── storage/ # SharedPreferences manager and secure storage
│ ├── theme/ # AppThemeData, custom borders, shadows, and text styles
│ └── utils/ # Validators, connectivity helpers, pickers, and logger
├── src/
│ └── users/ # Pre-generated dummy feature showcasing architecture
│ ├── bloc/ # RxDart user_bloc.dart
│ ├── data_source/ # user_datasource.dart
│ ├── mapper/ # user_mapper.dart (BaseMapper implementation)
│ ├── model/
│ │ ├── request/ # Empty folder placeholder for request parameters
│ │ ├── response/ # user_response.dart (Raw network DTO)
│ │ └── ui_entity/# user_ui_entity.dart (UI data model)
│ ├── presentation/
│ │ ├── view/ # user_screen.dart
│ │ └── widget/ # Feature-specific sub-widgets
│ ├── repository/ # user_repository.dart
│ └── state/ # user_state.dart & user_provider.dart
└── main.dart # Application root bootstrapper
Usage Guide
1. Creating a New Application
Generate a fully bootstrapped Flutter project matching the architecture style:
flutter_architecture_cli create <app_name>
Example:
flutter_architecture_cli create my_awesome_app
2. Creating a Feature
Instantly scaffold a complete feature directory with its nested folders (bloc, data_source, mapper, model/request, model/response, model/ui_entity, presentation/view, presentation/widget, repository, state):
flutter_architecture_cli create_feature <feature_name>
Example:
flutter_architecture_cli create_feature products
3. Creating a Screen
Add a new screen to the presentation layer of a specific feature:
flutter_architecture_cli create_screen <screen_name> -f <feature_name>
Example:
flutter_architecture_cli create_screen product_detail -f products
4. Creating Models
Generate model response DTOs and matching UI Entity classes:
flutter_architecture_cli create_model <model_name> -f <feature_name>
Example:
flutter_architecture_cli create_model category -f products
5. Creating Data Sources
Generate a data source class in the specified feature:
flutter_architecture_cli create_datasource <name> -f <feature_name>
Example:
flutter_architecture_cli create_datasource product -f products
6. Creating Repositories
Generate a repository class to bridge your data source and domain layer:
flutter_architecture_cli create_repository <name> -f <feature_name>
Example:
flutter_architecture_cli create_repository product -f products
Architecture Flow
The generated structure focuses on a single directional data flow:
- DataSource: Fetches raw JSON data using
ApiClientand parses it into a Response DTO (model/response/). - Mapper: Inherits from
BaseMapperto transform the Response DTO into a clean UI Entity (model/ui_entity/). - Repository: Requests data from
DataSourceand runs the mapped results up to the Bloc layer. - Bloc: Standardizes UI state management by converting repository streams into
BaseUiState(Loading -> Completed/Error) emitted viaBehaviorSubject. - Presentation (View): Listens to the Bloc subjects using
StreamBuilderand renders loading, success, or error screens automatically.
Roadmap / Future Goals
We plan to expand the CLI tool to support multiple popular state management architectures. Future updates will include flags to generate project structures for:
- flutter_bloc: Support for Bloc/Cubit architectures.
- Riverpod: Support for modern declarative state management and providers.
- GetX: Support for lightweight and high-performance reactive programming.
- Custom templates: Ability to load user-defined boilerplate structures.
Contributing
Contributions are welcome! If you want to suggest an improvement, report a bug, or add new command options:
- Fork the repository:
https://github.com/Dharti1623/flutter_architecture_cli - Create your feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request detailing your changes.
Support & Donations
If this CLI generator saved you time and made your Flutter development easier, consider supporting the project:
- ☕ Buy Me A Coffee: https://buymeacoffee.com/dhartichauhan
- ⭐ Star the Repository: Show your support by giving our Github repository a star!
Libraries
- flutter_architecture_cli
- Flutter Architecture CLI Package.