Hi Flutter devs! π
Are you tired of wrestling with messy codebases, unclear folder structures, and state management headaches? Iβve been there too. Thatβs why I built the Flutter Riverpod Clean Architecture templateβa modern, production-ready starter kit that helps you build robust, scalable, and maintainable Flutter apps, faster than ever.
π What Makes This Template Stand Out?
1. Clean Architecture, Done Right
- Separation of Concerns: Features, core logic, and infrastructure are clearly separated.
- Feature-First Structure: Each feature is isolated, making it easy to add, remove, or refactor without breaking the rest of your app.
- Testability: Business logic is decoupled from UI, so you can write meaningful unit and integration tests.
2. Riverpod 2.0+ for State Management
- Modern & Robust: Riverpod is the go-to for scalable, testable, and reactive state management.
- Provider Organization: All providers are organized by feature, not by type, for maximum clarity.
- Async & Sync Support: Easily handle both synchronous and asynchronous state.
3. Localization & Theming
- Built-in Localization: Add new languages in minutes. All strings are externalized and ready for translation.
- Dark/Light Mode: The template comes with beautiful, accessible themes for both light and dark users.
4. Production-Ready Out of the Box
- CI/CD Scripts: Automated scripts for building, testing, and generating documentation.
- Modern Documentation: The docs site uses glassmorphism, gradients, and dark mode for a stunning developer experience.
- Example Features: Real-world examples (auth, onboarding, etc.) to help you get started.
5. Comprehensive Testing
- Unit, Widget, and Integration Tests: Examples included for every layer.
- Mocking & Dependency Injection: Easily swap out implementations for testing.
ποΈ Folder Structure Overview
lib/
βββ core/ # Shared services, utilities, and cross-cutting concerns (e.g., networking, error handling, theming)
βββ features/ # Each app feature in its own folder, fully isolated
β βββ feature_name/
β βββ data/ # Data sources, models, and repositories (API, DB, etc.)
β βββ domain/ # Business logic: entities, repositories, use cases
β βββ presentation/ # UI widgets, screens, and Riverpod providers
βββ examples/ # Example implementations and UI showcases
βββ l10n/ # Localization files and delegates
βββ gen/ # Generated code (if any)
βββ main.dart # App entry point
β¨ Key Features at a Glance
- β Riverpod 2.0+: Modern, robust state management
- β Clean Architecture: Feature-first, scalable structure
- β Localization: Easy multi-language support
- β Dark/Light Themes: Beautiful, accessible UI
- β Comprehensive Testing: Unit, widget, and integration
- β CI/CD Ready: Automated scripts and workflows
- β Modern Docs: Beautiful, accessible, and interactive
π¦ Quick Start
git clone https://github.com/ssoad/flutter_riverpod_clean_architecture.git
cd flutter_riverpod_clean_architecture
flutter pub get
πΈ Documentation Preview
The documentation landing page is designed for clarity and beauty, with bold gradients, glassmorphism, and full dark mode support.
Code Generation Tools
The template includes several powerful CLI tools to automate repetitive tasks. Let's explore each one with practical examples.
1. Feature Generator (generate_feature.sh
)
The feature generator is the most versatile tool, allowing you to scaffold new features with different architectural patterns.
Basic Usage
./generate_feature.sh --name user_profile
This creates a complete feature with Clean Architecture layers:
- Data layer (repositories, data sources, models)
- Domain layer (entities, repository interfaces, use cases)
- Presentation layer (screens, widgets, UI providers)
- Tests for each layer
- Documentation
Different Feature Types
The generator supports various feature types to match your needs:
Clean Architecture Feature (Default)
./generate_feature.sh --name user_auth
This creates:
lib/features/user_auth/
βββ data/
β βββ datasources/
β β βββ user_auth_remote_datasource.dart
β β βββ user_auth_local_datasource.dart
β βββ models/
β β βββ user_auth_model.dart
β βββ repositories/
β βββ user_auth_repository_impl.dart
βββ domain/
β βββ entities/
β β βββ user_auth_entity.dart
β βββ repositories/
β β βββ user_auth_repository.dart
β βββ usecases/
β βββ get_all_user_auths.dart
β βββ get_user_auth_by_id.dart
βββ presentation/
β βββ providers/
β β βββ user_auth_ui_providers.dart
β βββ screens/
β β βββ user_auth_list_screen.dart
β β βββ user_auth_detail_screen.dart
β βββ widgets/
β βββ user_auth_list_item.dart
βββ providers/
βββ user_auth_providers.dart
Simplified Feature (No Repository Pattern)
./generate_feature.sh --name theme_switcher --no-repository
This creates a simpler structure without the repository pattern:
lib/features/theme_switcher/
βββ models/
β βββ theme_switcher_model.dart
βββ presentation/
β βββ providers/
β β βββ theme_switcher_ui_providers.dart
β βββ screens/
β β βββ theme_switcher_screen.dart
β βββ widgets/
β βββ theme_switcher_widget.dart
βββ providers/
βββ theme_switcher_providers.dart
UI Component Only
./generate_feature.sh --name custom_button --ui-only
Perfect for reusable UI components:
lib/features/custom_button/
βββ models/
β βββ custom_button_model.dart
βββ presentation/
β βββ providers/
β β βββ custom_button_ui_providers.dart
β βββ widgets/
β βββ custom_button_widget.dart
βββ providers/
βββ custom_button_providers.dart
Service Only
./generate_feature.sh --name analytics_service --service-only
Ideal for utility services:
lib/features/analytics_service/
βββ models/
β βββ analytics_service_model.dart
βββ services/
β βββ analytics_service_service.dart
βββ providers/
βββ analytics_service_providers.dart
Additional Options
You can combine options to customize the generated feature:
# Generate without UI (for background services)
./generate_feature.sh --name notification_handler --no-ui
# Skip test files generation
./generate_feature.sh --name quick_prototype --no-tests
# Skip documentation generation
./generate_feature.sh --name internal_utility --no-docs
# Minimal feature (no UI, tests, or docs)
./generate_feature.sh --name formatter --no-ui --no-tests --no-docs
2. Test Generator (test_generator.sh
)
The test generator automates testing workflows and generates coverage reports.
Running All Tests with Coverage
./test_generator.sh
This command:
- Runs all Flutter tests in the project
- Generates a coverage report
- Opens the HTML coverage report in your browser
Testing Specific Features
# Test only the auth feature
./test_generator.sh --target test/features/auth/
# Test a specific file
./test_generator.sh --target test/features/auth/domain/usecases/login_test.dart
Test Options
# Run tests without coverage (faster)
./test_generator.sh --no-coverage
# Generate coverage but don't open the report
./test_generator.sh --no-report
3. Language Generator (generate_language.sh
)
The language generator helps manage translations and internationalization.
Adding a New Language
# Add Spanish localization
./generate_language.sh --lang es
# Add multiple languages
./generate_language.sh --lang fr,de,ja
This will:
- Set up translation files in
lib/l10n/
for each language - Create necessary configuration for Flutter's localization system
- Generate boilerplate translation keys based on existing languages
Extracting Translation Keys
# Extract all translatable strings from the codebase
./generate_language.sh --extract
This scans your codebase for strings wrapped in context.tr()
calls and updates your translation files with new keys.
Generating Translations
# Generate the localization files
./generate_language.sh --generate
This creates the necessary Dart classes for accessing translations in your code.
4. App Renamer (rename_app.sh
)
The app renamer makes it easy to customize the app name, package name, and bundle ID across all platforms.
App Renaming
# Update app name and bundle ID
./rename_app.sh --name "My Awesome App" --bundle com.mycompany.awesomeapp
This updates:
- App name in all platform-specific files
- Package/bundle identifiers in Android and iOS
- Various configuration files
Platform-Specific Options
# Update only certain platforms
./rename_app.sh --name "My Awesome App" --bundle com.mycompany.awesomeapp --platforms android,ios
# Change the iOS bundle ID only
./rename_app.sh --ios-bundle com.mycompany.iosapp
# Change the Android package name only
./rename_app.sh --android-package com.mycompany.androidapp
Real-World Examples
Let's see how these tools work together in a real-world development flow:
Creating a New Feature with Full Testing
# 1. Generate the feature
./generate_feature.sh --name shopping_cart
# 2. Run specific tests for the new feature
./test_generator.sh --target test/features/shopping_cart/
# 3. Add new translations for the feature
./generate_language.sh --extract
Quickly Prototyping a UI Component
# 1. Generate a UI-only component
./generate_feature.sh --name gradient_card --ui-only
# 2. Skip tests during initial development
./test_generator.sh --no-coverage
Adding a New Service with Multiple Language Support
# 1. Generate a service-only feature
./generate_feature.sh --name analytics_tracker --service-only
# 2. Add support for multiple languages
./generate_language.sh --lang fr,de,es,ja
# 3. Run tests for the service
./test_generator.sh --target test/features/analytics_tracker/
Tips and Best Practices
- Use the right feature type: Choose the appropriate feature structure based on complexity:
- Full Clean Architecture for complex business features
- No-repository for simpler features
- UI-only for reusable UI components
- Service-only for utility services
- Run tests frequently: The test generator makes it easy to run tests as you develop:
./test_generator.sh --target test/features/your_feature/
- Generate documentation: Always generate documentation for features to keep the codebase easily maintainable:
# Generate a feature with documentation
./generate_feature.sh --name feature_name
- Extract translations early: Extract translatable strings frequently to avoid missing any:
./generate_language.sh --extract
- Combine commands in scripts: Create custom scripts that combine these tools for your workflow:
# Example: create_and_test_feature.sh
#!/bin/bash
./generate_feature.sh --name $1
./test_generator.sh --target test/features/$1/
./generate_language.sh --extract
π‘ Why Use Clean Architecture + Riverpod?
- Maintainability: Add features and refactor with confidence.
- Testability: Write meaningful tests for every layer.
- Scalability: Grow your app and your team without chaos.
- Community-Driven: Built with real-world feedback and best practices.
π€ Contribute & Connect
Iβd love your feedback, issues, and PRs!
If you find this template useful, please β the repo and share your thoughts.
Ready to build your next Flutter app?
Start with a foundation that scales. Try the Flutter Riverpod Clean Architecture template today!
Drop your questions, suggestions, or clean architecture tips in the comments!
Let me know if you want to highlight any specific feature, add more code samples, or further customize this post!
This is part of a series on Flutter Riverpod Clean Architecture. Check out the full repository on GitHub.
Top comments (0)