clean_architecture_with_state_management 1.3.0 copy "clean_architecture_with_state_management: ^1.3.0" to clipboard
clean_architecture_with_state_management: ^1.3.0 copied to clipboard

A package to generate clean architecture files with various state management options.

Stand With Palestine

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 #

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 cleanarch command. If using local installation, prefix with dart run.

Simply run without arguments for an interactive experience:

cleanarch

You'll be guided through:

  1. Entering your feature name (with validation!)
  2. Choosing whether to add state management
  3. Selecting your preferred state management solution
  4. 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 #

  1. Feature Naming: Use descriptive names for your features (e.g., authentication, user_profile, product_catalog)

  2. Dependency Injection: After generation, update your lib/injection_container.dart:

    Future.wait([
      ServiceLocator().setup(),
    ]).then((value) {
      runApp(const MyApp());
    });
    
  3. State Management: Choose the state management solution that best fits your team's expertise and project requirements

  4. Preview First: Use --dry-run to preview the structure before committing to file creation

  5. 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! πŸš€

17
likes
140
points
106
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A package to generate clean architecture files with various state management options.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

args, bloc, cli_util, dartz, flutter, flutter_bloc, flutter_riverpod, get_it, interact, provider, riverpod

More

Packages that depend on clean_architecture_with_state_management