clean_architecture_with_state_management 1.3.0
clean_architecture_with_state_management: ^1.3.0 copied to clipboard
A package to generate clean architecture files with various state management options.
Clean Architecture with State Management ποΈ #
A powerful, interactive CLI tool for generating clean architecture files with various state management options for Flutter projects.
β¨ Features #
- π― Interactive Mode - Beautiful, user-friendly prompts to guide you through setup
- π¨ Colored Output - Enhanced terminal experience with colored messages and icons
- π Progress Tracking - Real-time feedback on file creation
- π Dry Run Mode - Preview changes before creating files
- β Input Validation - Smart validation to prevent errors
- π Multiple State Management - Support for Provider, Bloc, Cubit, and Riverpod
- π Clean Architecture - Generates proper separation of concerns (Data, Domain, Presentation)
- π§ Dependency Injection - Automatic setup with GetIt
- π Flexible Usage - Works in both interactive and command-line modes
π¦ Installation #
Option 1: Global Installation (Recommended) #
Install globally to use the short cleanarch command anywhere:
dart pub global activate clean_architecture_with_state_management
Then use directly:
cleanarch myFeature -b
Option 2: Local Installation #
Add to your pubspec.yaml:
dev_dependencies:
clean_architecture_with_state_management:
Then run:
dart pub get
And use with:
dart run cleanarch myFeature -b
π Usage #
π― Quick Commands #
# Global installation (shorter!)
cleanarch myFeature -b
# Local installation
dart run cleanarch myFeature -b
Note: All examples below use the global
cleanarchcommand. If using local installation, prefix withdart run.
Interactive Mode (Recommended) #
Simply run without arguments for an interactive experience:
cleanarch
You'll be guided through:
- Entering your feature name (with validation!)
- Choosing whether to add state management
- Selecting your preferred state management solution
- Confirming the summary before generation
Command-Line Mode #
For quick generation or CI/CD pipelines:
# Basic structure without state management
cleanarch myFeature
# With Bloc
cleanarch myFeature -b
# With Cubit
cleanarch myFeature -c
# With Provider
cleanarch myFeature -p
# With Riverpod
cleanarch myFeature -r
Advanced Options #
# Preview without creating files (dry-run)
cleanarch myFeature --dry-run
# Skip git add step
cleanarch myFeature --no-git
# Force interactive mode
cleanarch -i
# Show help
cleanarch --help
π Generated Folder Structure #
Base Structure (No State Management) #
ββ features
β ββ feature_name/
β ββ data/
β β ββ data_sources/
β β β ββ local/
β β β β ββ feature_name_local_data_source.dart
β β β ββ remote/
β β β ββ feature_name_remote_data_source.dart
β β ββ models/
β β β ββ feature_model.dart
β β ββ repositories/
β β ββ feature_name_repository_impl.dart
β ββ domain/
β β ββ entities/
β β β ββ feature.dart
β β ββ repositories/
β β β ββ feature_repository.dart
β β ββ use_cases/
β β ββ feature_use_case.dart
β ββ presentation/
β β ββ screens/
β β β ββ feature_screen.dart
β β ββ widgets/
β ββ inject_feature_name.dart
With Bloc #
β ββ presentation/
β β ββ bloc/
β β β ββ feature_bloc.dart
β β β ββ feature_event.dart
β β β ββ feature_state.dart
β β ββ screens/
β β β ββ feature_screen.dart
β β ββ widgets/
With Cubit #
β ββ presentation/
β β ββ cubit/
β β β ββ feature_cubit.dart
β β β ββ feature_state.dart
β β ββ screens/
β β β ββ feature_screen.dart
β β ββ widgets/
With Provider #
β ββ presentation/
β β ββ provider/
β β β ββ feature_provider.dart
β β ββ screens/
β β β ββ feature_screen.dart
β β ββ widgets/
With Riverpod #
β ββ presentation/
β β ββ riverpod/
β β β ββ feature_notifier.dart
β β β ββ feature_provider.dart
β β ββ screens/
β β β ββ feature_screen.dart
β β ββ widgets/
π― Clean Architecture Principles #
The generated code follows clean architecture principles:
Data Layer #
- Data Sources: Local and remote data sources for accessing data
- Models: Data transfer objects that extend domain entities
- Repositories: Implementation of domain repositories
Domain Layer #
- Entities: Business objects of the application
- Repositories: Abstract contracts for data operations
- Use Cases: Business logic and application-specific rules
Presentation Layer #
- Screens: UI components using your chosen state management
- Widgets: Reusable UI components
- State Management: Bloc/Cubit/Provider/Riverpod files
π‘ Interactive Features #
π¨ Colored Output #
- β Green for success messages
- β Red for errors
- β Yellow for warnings
- βΉ Cyan for information
- Beautiful headers and sections
π Progress Tracking #
- Real-time file creation feedback
- File skip notifications for existing files
- Summary of total files created
π Dry Run Mode #
Preview exactly what will be created without making any changes:
cleanarch myFeature --dry-run
π Override Protection (NEW!) #
If a feature already exists, you'll be asked if you want to override it:
$ cleanarch user -b
β Feature "user" already exists!
Do you want to override the existing feature? βΊ No
βΉ Operation cancelled. Existing feature was not modified.
- Default is No to protect your work
- Choose Yes to completely regenerate the feature
- Easy to cancel and keep existing code
β Input Validation (NEW!) #
- Smart validation works in both interactive and command-line modes
- Feature names must start with a letter (a-z, A-Z)
- Only allows letters, numbers, and underscores
- Empty input prevention
- Helpful error messages with examples
- Automatic retry in interactive mode
Example:
$ cleanarch 123invalid
β Invalid feature name: "123invalid"
βΉ Feature names must:
βΉ β’ Start with a letter (a-z, A-Z)
βΉ β’ Contain only letters, numbers, and underscores
βΉ β’ Example: user, user_profile, myFeature
π― Smart Confirmations #
- Summary review before generation
- Confirmation prompt to proceed
- Override confirmation for existing features
- Easy cancellation at any step
π Example Workflow #
$ cleanarch
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β β
β ποΈ Clean Architecture Generator β
β with State Management β
β β
β Generate clean, scalable Flutter features β
β with your favorite state management β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
π‘ Tips:
β’ Use snake_case or camelCase for feature names
β’ The generator handles naming conventions automatically
β’ Files are automatically added to git
β’ Use --dry-run to preview before creating
βΆ Feature Setup
What is the name of your feature? βΊ user
Do you want to add state management? βΊ Yes
Choose your state management solution:
Provider
β― Bloc
Cubit
Riverpod
βΆ Summary
Feature Name: user
State Management: Bloc
Mode: CREATE FILES
Ready to generate files? βΊ Yes
βΆ Initializing
β³ Setting up injection container...
βΆ Creating Clean Architecture Structure
β Creating directory structure...
β Creating data layer...
β Created: lib/features/user/data/data_sources/local/user_local_data_source.dart
β Created: lib/features/user/data/data_sources/remote/user_remote_data_source.dart
...
ββββββββββββββββββββββββββββββββββββββββββββ
β Feature "user" generated successfully!
Files created: 12
ββββββββββββββββββββββββββββββββββββββββββββ
βΆ Next Steps
β 1. Update your dependency injection in injection_container.dart
β 2. Implement your business logic in the use case
β 3. Add your UI in the presentation layer
β 4. Start coding! π
π οΈ Command-Line Options #
| Option | Short | Description |
|---|---|---|
--help |
-h |
Show help information |
--interactive |
-i |
Force interactive mode |
--dry-run |
-d |
Preview changes without creating files |
--provider |
-p |
Use Provider state management |
--bloc |
-b |
Use Bloc state management |
--cubit |
-c |
Use Cubit state management |
--riverpod |
-r |
Use Riverpod state management |
--no-git |
Skip git add step |
π Best Practices #
-
Feature Naming: Use descriptive names for your features (e.g.,
authentication,user_profile,product_catalog) -
Dependency Injection: After generation, update your
lib/injection_container.dart:Future.wait([ ServiceLocator().setup(), ]).then((value) { runApp(const MyApp()); }); -
State Management: Choose the state management solution that best fits your team's expertise and project requirements
-
Preview First: Use
--dry-runto preview the structure before committing to file creation -
Feature Name Rules: Always start feature names with a letter (not numbers or underscores)
π€ Contributing #
Contributions are welcome! Please feel free to submit a Pull Request.
π License #
This project is licensed under the MIT License.
π Acknowledgments #
Built with β€οΈ for the Flutter community
π Support #
Happy Coding! π