How momshaddinury/flutter_template works
Purpose and Entry Points
A production-oriented Flutter mobile application template implementing Clean Architecture. It ships authentication, onboarding, guarded navigation, localization, theming, and an HTTP/token stack as reusable foundations. Flutter starts at lib/main.dart, which delegates initialization to lib/src/core/bootstrap.dart; Android and iOS host the Flutter runtime through android/app/src/main/kotlin/com/dinurymomshad/flutter_template/MainActivity.kt and ios/Runner/AppDelegate.swift.
Layered Application Boundary
The source is intentionally divided into core, domain, data, and presentation. Domain defines technology-independent entities, repository contracts, and use cases; data satisfies those contracts using transport and storage; presentation invokes use cases and renders state. Key seams are lib/src/domain/repositories/authentication_repository.dart, lib/src/data/repositories/authentication_repository_impl.dart, and lib/src/domain/use_cases/authentication_use_case.dart. Login/sign-up DTOs are mapped between data models and domain entities in lib/src/data/mappers/login_mapper.dart and lib/src/data/mappers/sign_up_mapper.dart.
Bootstrap, DI, and Fault Handling
Bootstrap establishes application-wide startup/error behavior before UI rendering. Riverpod is both state-management and dependency-injection mechanism, with provider composition organized by dependency type: external services, repositories, and use cases. Core boundaries are lib/src/core/bootstrap.dart, lib/src/core/di/dependency_injection.dart, and lib/src/core/di/parts/services.dart. Global error handlers route uncaught errors to the crash-reporting abstraction in lib/src/core/base/global_error_handlers.dart and lib/src/core/base/crash_reporter.dart.
Startup State and Navigation Gates
The router is declarative go_router, assembled from feature route groups and controlled by one derived redirect gate. Startup, onboarding completion, session/authentication status, and logout are app-level Riverpod state inputs; they determine whether users reach splash, onboarding, auth, or the authenticated shell. Primary paths: lib/src/presentation/core/router/router.dart, lib/src/presentation/core/router/redirect_gate.dart, and lib/src/presentation/core/application_state/startup_provider/app_startup_provider.dart. Route groups separate authentication, onboarding, and shell navigation in lib/src/presentation/core/router/parts/.
Authentication and Session Flow
Login UI/provider submits credentials through the authentication use case and repository contract; the implementation calls the REST layer, maps responses, and delegates token persistence/refresh behavior to network auth services. The feature surface begins at lib/src/presentation/features/authentication/login/riverpod/login_provider.dart and lib/src/presentation/features/authentication/login/view/login_page.dart. Session persistence and lifecycle decisions are represented by lib/src/presentation/core/application_state/session_status_provider/session_status_provider.dart; registration and password-reset screens are presentation flows under lib/src/presentation/features/authentication/.
Network, Storage, and Failure Translation
Dio/Retrofit provide the external REST boundary through lib/src/data/services/network/rest_client.dart, configured in lib/src/data/services/network/transport/dio_builder.dart. Interceptors attach auth and locale headers, log debug traffic, normalize errors, and refresh/retry expired-token requests; the retry boundary is lib/src/data/services/network/transport/interceptors/refresh_retry_interceptor.dart. Tokens use secure storage via lib/src/data/services/network/auth/secure_token_store.dart; non-secret persisted values such as preferences use lib/src/data/services/cache/shared_preference_service.dart. Transport exceptions are converted into infrastructure failures and then domain/UI-appropriate failures through lib/src/data/failures/infra_failure_mapper.dart.
Presentation System and Runtime Dependencies
Presentation is feature-oriented: authentication, home, profile, onboarding, and splash sit beneath shared router, widgets, status/failure models, and theme infrastructure. The authenticated shell is lib/src/presentation/core/widgets/navigation_shell.dart; theme tokens/extensions are centralized in lib/src/presentation/core/theme/theme.dart and lib/src/presentation/core/theme/src/theme_extensions/extensions.dart. Localization supports English, Bangla, and Arabic resources in lib/src/core/localization/. Material runtimes are Flutter/Dart, Android Gradle, and iOS/Xcode; external client services are REST APIs, secure device token storage, and SharedPreferences.
Main entry points: dependency_injection.dart Riverpod DI · authentication_repository_impl.dart Authentication repository · rest_client.dart REST client · authentication_use_case.dart Authentication use case
Components 24
Runtime Hosts
- Flutter entrypoint
lib/main.dart - Android host
android/app/src/main/kotlin/com/dinurymomshad/flutter_template/MainActivity.kt - iOS host
ios/Runner/AppDelegate.swift
Bootstrap & App Core
- Bootstrap · Initializes app-wide behavior before rendering.
lib/src/core/bootstrap.dart - Riverpod DI
lib/src/core/di/dependency_injection.dart - Service providers
lib/src/core/di/parts/services.dart - Global error handlers
lib/src/core/base/global_error_handlers.dart - Crash reporter
lib/src/core/base/crash_reporter.dart
Clean Architecture Layers
- Authentication contract
lib/src/domain/repositories/authentication_repository.dart - Authentication use case
lib/src/domain/use_cases/authentication_use_case.dart - Authentication repository · Implements the domain authentication contract.
lib/src/data/repositories/authentication_repository_impl.dart - Auth DTO mappers · Maps login and sign-up models to domain entities.
lib/src/data/mappers/login_mapper.dart
Presentation & Navigation
- Login flow · Login page and provider submit credentials.
lib/src/presentation/features/authentication/login/riverpod/login_provider.dart - App router
lib/src/presentation/core/router/router.dart - Redirect gate · Selects splash, onboarding, auth, or shell.
lib/src/presentation/core/router/redirect_gate.dart - Startup state
lib/src/presentation/core/application_state/startup_provider/app_startup_provider.dart - Session status · Tracks authentication lifecycle and logout.
lib/src/presentation/core/application_state/session_status_provider/session_status_provider.dart - Authenticated shell
lib/src/presentation/core/widgets/navigation_shell.dart
Infrastructure
- REST client
lib/src/data/services/network/rest_client.dart - Dio transport
lib/src/data/services/network/transport/dio_builder.dart - Refresh/retry interceptor · Refreshes expired tokens and retries requests.
lib/src/data/services/network/transport/interceptors/refresh_retry_interceptor.dart - Secure token store
lib/src/data/services/network/auth/secure_token_store.dart - Infrastructure failure mapper
lib/src/data/failures/infra_failure_mapper.dart - REST APIs
Connections 24
- Android host → Flutter entrypoint: hosts
- iOS host → Flutter entrypoint: hosts
- Flutter entrypoint → Bootstrap: starts
- Bootstrap → Riverpod DI: initializes
- Bootstrap → Global error handlers: installs
- Global error handlers → Crash reporter: reports uncaught faults
- Riverpod DI → Service providers: composes
- Riverpod DI → Authentication use case: provides
- Riverpod DI → Authentication repository: provides
- Login flow → Authentication use case: submits credentials
- Authentication use case → Authentication contract: depends on
- Authentication repository → Authentication contract: implements
- Authentication repository → Auth DTO mappers: maps DTOs
- Authentication repository → REST client: calls
- REST client → Dio transport: uses
- Dio transport → Refresh/retry interceptor: installs
- Refresh/retry interceptor → Secure token store: reads and refreshes tokens
- REST client → Infrastructure failure mapper: translates errors
- REST client → REST APIs: requests
- App router → Redirect gate: guards routes with
- Redirect gate → Startup state: reads
- Redirect gate → Session status: reads
- App router → Authenticated shell: renders authenticated routes
- Session status → Authentication use case: uses session operations