| name | flutter-riverpod-architecture |
| description | Clean Architecture patterns for Flutter with Riverpod state management. Use when building or reviewing Flutter apps with layered architecture (Domain, Data, Application, Presentation). |
Flutter + Riverpod Clean Architecture
Overview
This skill provides architectural patterns and rules for building Flutter applications using Clean Architecture with Riverpod for state management. Follow these patterns to maintain clear layer boundaries, testability, and scalability.
Architecture Layers
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Presentation Layer โ Flutter UI, Widgets, Routing
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Application Layer โ Riverpod Providers, State Management
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Data Layer โ Repositories, External APIs
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโค
โ Domain Layer โ Entities, Value Objects, Business Rules
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
Layer Dependency Rules
| Layer | Can Depend On | Cannot Depend On |
|---|
| Domain | Nothing (pure Dart) | Flutter, Riverpod, Firebase, any SDK |
| Data | Domain | Flutter, Riverpod, Presentation |
| Application | Domain, Data | Flutter UI classes |
| Presentation | Application, Domain | Data (direct access) |
Quick Reference
| Layer | Primary Purpose | Key Technology |
|---|
| Domain | Business entities, Value Objects | Freezed, pure Dart |
| Data | Repository implementations, API calls | Firebase, HTTP clients |
| Application | State management, Provider definitions | Riverpod, AsyncNotifier |
| Presentation | UI components, routing | ConsumerWidget, go_router |
Layer References
references/domain-layer.md - Freezed entities, Value Objects, immutable data
references/data-layer.md - Repository pattern, dependency injection
references/application-layer.md - Riverpod providers, AsyncNotifier pattern
references/presentation-layer.md - ConsumerWidget, type-safe routing
references/ui-patterns.md - Widget composition, anti-patterns
Core Principles
1. Dependency Inversion
- Inner layers don't know about outer layers
- Domain is completely independent
- Data depends only on Domain
- Dependencies flow inward
2. Single Responsibility
- Each layer has a clear purpose
- Repositories handle data access only
- Providers handle state management only
- Widgets handle UI rendering only
3. Testability
- Domain layer is easily unit-testable (no dependencies)
- Data layer can mock external services
- Application layer can mock repositories
- Presentation layer can mock providers
Directory Structure (Recommended)
lib/
โโโ app/
โ โโโ route/ # go_router configuration
โ โโโ providers/ # App-wide providers
โโโ features/
โ โโโ {feature}/
โ โโโ domain/ # Entities, Value Objects
โ โโโ data/ # Repositories
โ โโโ application/ # Providers, Notifiers
โ โโโ presentation/# Screens, Widgets
โโโ shared/
โโโ domain/ # Shared entities
โโโ data/ # Shared repositories
โโโ widgets/ # Shared UI components
Getting Started
- New Entity? -> See
references/domain-layer.md
- API Integration? -> See
references/data-layer.md
- State Management? -> See
references/application-layer.md
- Building UI? -> See
references/presentation-layer.md
- Widget Patterns? -> See
references/ui-patterns.md
Compliance Verification
grep -r "package:flutter" lib/features/*/domain/
grep -r "riverpod" lib/features/*/domain/
grep -r "package:flutter" lib/features/*/data/
grep -r "riverpod" lib/features/*/data/
grep -r "features/.*/data/.*_repository" lib/features/*/presentation/
All commands should return empty results if architecture is properly maintained.