flutter_architecture_cli 1.0.0
flutter_architecture_cli: ^1.0.0 copied to clipboard
A command-line tool to generate a production-ready clean architecture in Flutter using RxDart and Provider.
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.
Table of Contents #
- Features
- Folder Structure
- Installation
- Usage Guide
- Architecture Flow
- Contributing
- Support & Donations
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
Installation #
Activate the package globally to make the command available system-wide:
dart pub global activate flutter_architecture_cli
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>
6. Creating Repositories #
Generate a repository class to bridge your data source and domain layer:
flutter_architecture_cli create_repository <name> -f <feature_name>
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.
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!