How uuttssaavv/flutter-clean-architecture-riverpod works
Purpose and runtime
This is a Flutter/Dart mobile client demonstrating clean architecture with Riverpod. It authenticates against DummyJSON, persists the logged-in user locally, and presents paginated/searchable products. Flutter renders the UI; Android and iOS host the Flutter engine via android/app/src/main/kotlin/com/example/flutter_project/MainActivity.kt and ios/Runner/AppDelegate.swift.
Bootstrap, environments, and routing
Application startup initializes services and installs Riverpod’s dependency container before building the root app. Environment-specific launch files support development/staging configuration. The root Material app owns generated AutoRoute navigation, including splash, login, and dashboard transitions.
• lib/main.dart
• lib/main/app.dart
• lib/main/main_dev.dart
• lib/routes/app_route.dart
Clean-architecture feature boundary
Authentication and dashboard are independently organized into data, domain, and presentation layers. Domain repository interfaces define feature contracts; data repositories bind those contracts to local/remote sources; presentation consumes Riverpod providers and state notifiers rather than concrete transport/storage implementations.
• lib/features/authentication/domain/repositories/auth_repository.dart
• lib/features/authentication/data/repositories/authentication_repository_impl.dart
• lib/features/dashboard/domain/repositories/dashboard_repository.dart
• lib/features/dashboard/data/repositories/dashboard_repository.dart
Authentication and session persistence
The login screen dispatches through presentation state, which invokes domain login providers and the authentication repository. Remote authentication obtains user data; local authentication and the app-level user-cache service persist/read the current user. This cached session is the likely input to splash-driven initial navigation.
• lib/features/authentication/presentation/providers/state/auth_notifier.dart
• lib/features/authentication/data/datasource/auth_remote_data_source.dart
• lib/features/authentication/data/datasource/auth_local_data_source.dart
• lib/services/user_cache_service/domain/providers/current_user_provider.dart
Dashboard product flow
Dashboard state initializes product retrieval and manages pagination/search. Its notifier depends on a repository abstraction; the repository delegates to dashboard data sources, which retrieve product pages/search results and may cache locally. UI observes state and renders loading, error, or product results.
• lib/features/dashboard/presentation/providers/state/dashboard_notifier.dart
• lib/features/dashboard/presentation/screens/dashboard_screen.dart
• lib/features/dashboard/data/datasource/dashboard_remote_datasource.dart
• lib/features/dashboard/data/datasource/dashboard_local_datasource.dart
Shared infrastructure and data contracts
A NetworkService abstraction is implemented by Dio, isolating HTTP configuration and error translation from features. StorageService is implemented with SharedPreferences for simple persistent state. Shared models represent users, products, paginated API responses, and functional/error result boundaries; Freezed and JSON-generated model artifacts support immutable serialization.
• lib/shared/data/remote/network_service.dart
• lib/shared/data/remote/dio_network_service.dart
• lib/shared/data/local/shared_prefs_storage_service.dart
• lib/shared/domain/models/paginated_response.dart
• lib/shared/exceptions/http_exception.dart
State and UI boundaries
Riverpod providers compose concrete dependencies from shared services through feature repositories and into StateNotifier state machines. Presentation remains Flutter-specific: screens emit user events and subscribe to immutable auth/dashboard state, while shared theme and reusable loading/error widgets standardize rendering.
• lib/features/authentication/presentation/providers/auth_providers.dart
• lib/features/authentication/presentation/providers/state/auth_state.dart
• lib/features/dashboard/presentation/providers/dashboard_state_provider.dart
• lib/shared/widgets/app_error.dart
Main entry points: app_route.dart App routes · main.dart Bootstrap · auth_providers.dart Auth providers · authentication_repository_impl.dart Auth repository
Components 21
Native Hosts
- Android host · Hosts the Flutter engine.
android/app/src/main/kotlin/com/example/flutter_project/MainActivity.kt - iOS host · Hosts the Flutter engine.
ios/Runner/AppDelegate.swift
App Shell
- Bootstrap · Initializes services and Riverpod before rendering.
lib/main.dart - Environment launchers · Development and staging launch configuration.
lib/main/main_dev.dart - Root app · Owns the app shell and navigation setup.
lib/main/app.dart - App routes · Routes splash, login, and dashboard.
lib/routes/app_route.dart
Authentication
- Auth UI state · Processes login events and exposes immutable auth state.
lib/features/authentication/presentation/providers/state/auth_notifier.dart - Auth providers · Wires presentation to authentication dependencies.
lib/features/authentication/presentation/providers/auth_providers.dart - Auth repository contract
lib/features/authentication/domain/repositories/auth_repository.dart - Auth repository · Combines remote login and local session access.
lib/features/authentication/data/repositories/authentication_repository_impl.dart - Auth data sources · Authenticates remotely and persists the user locally.
lib/features/authentication/data/datasource/auth_remote_data_source.dart - Current user cache · Reads the persisted user for session restoration.
lib/services/user_cache_service/domain/providers/current_user_provider.dart
Dashboard
- Dashboard screen · Renders loading, errors, and product results.
lib/features/dashboard/presentation/screens/dashboard_screen.dart - Dashboard state · Manages product loading, paging, and search.
lib/features/dashboard/presentation/providers/state/dashboard_notifier.dart - Dashboard repository contract
lib/features/dashboard/domain/repositories/dashboard_repository.dart - Dashboard repository · Delegates product retrieval to data sources.
lib/features/dashboard/data/repositories/dashboard_repository.dart - Product data sources · Retrieves or caches product pages and searches.
lib/features/dashboard/data/datasource/dashboard_remote_datasource.dart
Shared Infrastructure
- Network service · Isolates HTTP configuration and error translation.
lib/shared/data/remote/dio_network_service.dart - Storage service · Provides persistent local state.
lib/shared/data/local/shared_prefs_storage_service.dart - Shared data contracts · Defines paginated responses and HTTP failure boundaries.
lib/shared/domain/models/paginated_response.dart - Error widget
lib/shared/widgets/app_error.dart
Connections 25
- Android host → Bootstrap: hosts
- iOS host → Bootstrap: hosts
- Environment launchers → Bootstrap: launches
- Bootstrap → Root app: builds
- Root app → App routes: uses
- App routes → Auth UI state: login flow
- App routes → Dashboard screen: dashboard flow
- Current user cache → App routes: restores session for splash
- Auth UI state → Auth providers: resolves dependencies
- Auth providers → Auth repository contract: depends on
- Auth repository → Auth repository contract: implements
- Auth providers → Auth repository: binds implementation
- Auth repository → Auth data sources: uses
- Auth data sources → Network service: login request
- Auth data sources → Storage service: persist user
- Current user cache → Storage service: reads user
- Dashboard screen → Dashboard state: observes and dispatches
- Dashboard state → Dashboard repository contract: depends on
- Dashboard repository → Dashboard repository contract: implements
- Dashboard state → Dashboard repository: retrieves products
- Dashboard repository → Product data sources: delegates
- Product data sources → Network service: pages and search
- Product data sources → Storage service: optional cache
- Network service → Shared data contracts: maps responses and errors
- Dashboard screen → Error widget: renders failures