# flutter_riverpod_clean_architecture
**Repository Path**: honley/flutter_riverpod_clean_architecture
## Basic Information
- **Project Name**: flutter_riverpod_clean_architecture
- **Description**: No description available
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: main
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2025-09-23
- **Last Updated**: 2025-09-23
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# Flutter Riverpod Clean Architecture




A production-ready Flutter project template implementing Clean Architecture principles with Riverpod for state management. This template provides a solid foundation for building scalable, maintainable, and testable Flutter applications.
## 🌟 Key Features
- **Clean Architecture** — Domain, data, and presentation layers separation
- **Riverpod State Management** — Powerful, testable state management
- **Multi-language Support** — Full internationalization with language switching
- **Advanced Caching** — Memory and disk caching with type-safety
- **Biometric Authentication** — Secure fingerprint and face recognition
- **Feature Flags** — A/B testing and staged rollouts
- **Analytics Integration** — Flexible event tracking
- **Push Notifications** — Deep linking and background handling
- **Accessibility** — Screen reader and dynamic text support
- **Offline-First** — Work seamlessly with or without connection
- **CI/CD Ready** — Automated workflows with GitHub Actions
[See All Features](docs/FEATURES.md)
## � Documentation
- [Architecture Guide](https://ssoad.github.io/flutter_riverpod_clean_architecture/architecture.html) - Project structure and principles
- [Utility Tools](docs/TOOLS.md) - CLI tools for development
- [Feature Documentation](docs/FEATURES.md) - Core features explained
- [Code Examples](docs/EXAMPLES.md) - Usage examples
- [Online Documentation](https://ssoad.github.io/flutter_riverpod_clean_architecture/) - Complete reference
## 🏗️ Project Structure
```plaintext
lib/
├── core/ # Core shared functionality
├── features/ # Feature modules
│ └── feature_name/ # Individual feature
│ ├── data/ # Data layer (repositories, sources)
│ ├── domain/ # Domain layer (entities, use cases)
│ └── presentation/ # UI layer (screens, providers)
├── examples/ # Example implementations
└── main.dart # Application entry point
```
[Full Architecture Overview](docs/ARCHITECTURE.md)
## 🚀 Quick Start
```bash
# Clone the repository
git clone https://github.com/ssoad/flutter_riverpod_clean_architecture.git
# Navigate to the project directory
cd flutter_riverpod_clean_architecture
# Install dependencies
flutter pub get
# Run the app
flutter run
```
[Detailed Getting Started Guide](docs/GETTING_STARTED.md)
## 🧑💻 Adding New Features
This template provides two approaches to creating new features: automated generation with our powerful CLI tools or manual setup following Clean Architecture principles.
### Method 1: Using the Feature Generator Tool (Recommended)
The fastest way to create a new feature is using our built-in feature generator:
```bash
./generate_feature.sh --name user_profile
```
This will automatically:
1. Create the complete folder structure following Clean Architecture
2. Generate data, domain, and presentation layer templates
3. Add Riverpod providers with proper dependency injection
4. Create test file templates for each component
5. Add basic documentation for the feature
#### Feature Generator Options
```bash
# Basic usage - creates a complete feature with all layers
./generate_feature.sh --name user_profile
# Create a feature without UI (for background services)
./generate_feature.sh --name analytics_service --no-ui
# Create a feature without repository pattern (simplified structure)
./generate_feature.sh --name theme_switcher --no-repository
# Create a UI-only feature (for shared components)
./generate_feature.sh --name custom_button --ui-only
# Create a service-only feature (for utility services)
./generate_feature.sh --name logger --service-only
# Create data-only feature without tests
./generate_feature.sh --name local_storage --no-ui --no-tests
# Minimal feature without UI, tests or docs (for utilities)
./generate_feature.sh --name formatter --no-ui --no-tests --no-docs
# See all available options
./generate_feature.sh --help
```
#### Generated Structure
The feature generator creates different structures based on the options you choose:
##### Full Clean Architecture Structure (Default)
```plaintext
lib/features/feature_name/
├── data/
│ ├── datasources/
│ │ ├── feature_name_remote_datasource.dart
│ │ └── feature_name_local_datasource.dart
│ ├── models/
│ │ └── feature_name_model.dart
│ └── repositories/
│ └── feature_name_repository_impl.dart
├── domain/
│ ├── entities/
│ │ └── feature_name_entity.dart
│ ├── repositories/
│ │ └── feature_name_repository.dart
│ └── usecases/
│ ├── get_all_feature_names.dart
│ └── get_feature_name_by_id.dart
├── presentation/ (optional with --no-ui flag)
│ ├── providers/
│ │ └── feature_name_ui_providers.dart
│ ├── screens/
│ │ ├── feature_name_list_screen.dart
│ │ └── feature_name_detail_screen.dart
│ └── widgets/
│ └── feature_name_list_item.dart
└── providers/
└── feature_name_providers.dart
```
##### No-Repository Structure (with --no-repository flag)
```plaintext
lib/features/feature_name/
├── models/
│ └── feature_name_model.dart
├── presentation/ (optional with --no-ui flag)
│ ├── providers/
│ │ └── feature_name_ui_providers.dart
│ ├── screens/
│ │ └── feature_name_screen.dart
│ └── widgets/
│ └── feature_name_widget.dart
└── providers/
└── feature_name_providers.dart
```
##### UI-Only Structure (with --ui-only flag)
```plaintext
lib/features/feature_name/
├── models/
│ └── feature_name_model.dart
├── presentation/
│ ├── providers/
│ │ └── feature_name_ui_providers.dart
│ └── widgets/
│ └── feature_name_widget.dart
└── providers/
└── feature_name_providers.dart
```
##### Service-Only Structure (with --service-only flag)
```plaintext
lib/features/feature_name/
├── models/
│ └── feature_name_model.dart
├── services/
│ └── feature_name_service.dart
└── providers/
└── feature_name_providers.dart
```
#### Using the Dart Feature Generator
For programmatic usage in your own tools or scripts, you can also use the included Dart class:
```dart
// Import the generator
import 'package:flutter_riverpod_clean_architecture/core/cli/feature_generator.dart';
// Create and run the generator
final generator = FeatureGenerator(
featureName: 'user_profile',
withUi: true, // Include presentation layer
withTests: true, // Generate test files
withDocs: true // Create documentation
);
// Generate all files and folders
await generator.generate();
```
### Method 2: Manual Feature Creation
If you prefer to create features manually, follow this structure:
1. **Create the feature directory structure**:
```plaintext
lib/features/feature_name/
├── data/
│ ├── datasources/ # Remote and local data sources
│ ├── models/ # DTOs and model classes
│ └── repositories/ # Repository implementations
├── domain/
│ ├── entities/ # Business entities
│ ├── repositories/ # Repository interfaces
│ └── usecases/ # Business use cases
├── presentation/
│ ├── providers/ # UI-specific providers
│ ├── screens/ # Page/screen widgets
│ └── widgets/ # Reusable UI components
└── providers/ # Core feature providers
```
Then implement each component:
**Step 1:** Define your entities in `domain/entities/` - these are your core business models.
**Step 2:** Create repository interfaces in `domain/repositories/` that define how data will be accessed.
**Step 3:** Implement use cases in `domain/usecases/` for each business operation.
**Step 4:** Create data models in `data/models/` that extend your entities with data layer functionality.
**Step 5:** Implement repositories in `data/repositories/` that fulfill your repository interfaces.
**Step 6:** Create Riverpod providers in `providers/feature_providers.dart`:
```dart
// Data source providers
final userRemoteDataSourceProvider = Provider((ref) =>
UserRemoteDataSourceImpl(client: ref.read(httpClientProvider)));
// Repository providers
final userRepositoryProvider = Provider((ref) =>
UserRepositoryImpl(
remoteDataSource: ref.read(userRemoteDataSourceProvider),
localDataSource: ref.read(userLocalDataSourceProvider),
));
// Use case providers
final getUserProfileProvider = Provider((ref) =>
GetUserProfile(ref.read(userRepositoryProvider)));
// State providers
final userProfileProvider = FutureProvider((ref) async {
final usecase = ref.read(getUserProfileProvider);
final result = await usecase(NoParams());
return result.fold(
(failure) => throw Exception(failure.toString()),
(user) => user,
);
});
```
**Step 7:** Create UI components in the presentation layer that consume your providers.
**Step 8:** Write tests for each layer in the corresponding test directory.
### Feature Organization Best Practices
- Keep feature code isolated from other features
- Use dependency injection via Riverpod providers
- Follow the unidirectional data flow: UI → Use Case → Repository → Data Source
- Write tests for each layer, especially use cases and repositories
- Document feature usage and key integration points
### Example: Complete User Profile Feature
Here's a comprehensive example of implementing a user profile feature using Clean Architecture:
#### 1. Domain Layer
```dart
// domain/entities/user_entity.dart
class UserEntity extends Equatable {
final String id;
final String name;
final String email;
final String? profileImage;
final DateTime lastActive;
const UserEntity({
required this.id,
required this.name,
required this.email,
this.profileImage,
required this.lastActive,
});
@override
List