| name | flutter-clean-arch |
| description | Flutter clean architecture guide for this template. Use when creating features, screens, state managers (providers/blocs/cubits/controllers), use cases, repositories, models, or entities. Also use when asked about project structure, conventions, or architecture decisions.
|
Flutter Clean Architecture Template
This project follows Clean Architecture with feature-based modular structure. Every feature is split into three layers with strict dependency rules.
Project Structure
lib/
โโโ app/ # App entry point, DI container, main widget
โ โโโ app_name.dart # MaterialApp with GoRouter
โ โโโ injection_container.dart # Global GetIt DI setup
โ
โโโ core/ # Shared code across all features
โ โโโ config/ # Responsive scaling config
โ โโโ constants/ # App-wide constants, asset paths
โ โโโ entities/ # Shared domain entities
โ โโโ enums/ # Global enums
โ โโโ extensions/ # Context, responsive, string, widget extensions
โ โโโ providers/ # Global state (theme, etc.)
โ โโโ router/ # GoRouter config, route names, transitions
โ โโโ services/ # Dio HTTP, local storage, logger, network, notifications
โ โโโ theme/ # Colors, text styles, theme data
โ โโโ utils/ # Validators, system utilities
โ โโโ widgets/ # Reusable UI components (buttons, inputs, loaders, etc.)
โ
โโโ features/ # Feature modules
โโโ <feature_name>/
โโโ data/ # Data layer
โ โโโ models/ # DTOs with fromJson/toJson/toEntity
โ โโโ datasources/ # Remote & local data sources
โ โโโ repositories/ # Repository implementations
โโโ domain/ # Domain layer (pure Dart)
โ โโโ entities/ # Business objects
โ โโโ repositories/ # Repository interfaces (abstract)
โ โโโ usecases/ # Business logic
โโโ presentation/ # Presentation layer
โ โโโ screens/ # Full screens/pages
โ โโโ widgets/ # Feature-specific widgets
โ โโโ <state_mgmt>/ # State managers (providers/blocs/cubits/controllers)
โโโ <feature>_di.dart # Feature-level DI registration
Three-Layer Rule
| Layer | Depends on | Contains | Rules |
|---|
| Domain | Nothing | Entities, repository interfaces, use cases | Pure Dart only. NO Flutter imports. NO external packages. |
| Data | Domain | Models, datasources, repository impls | Can use Dio, HTTP, databases. NO Flutter UI code. |
| Presentation | Domain | Screens, widgets, state managers | Uses use cases, never repositories directly. |
Dependency direction: Presentation โ Domain โ Data. Domain knows nothing about the others.
State Management
This template does not enforce a specific state management solution. Use whatever your team prefers:
- Provider (ChangeNotifier)
- BLoC/Cubit (flutter_bloc)
- GetX (Controller)
- Riverpod
- MobX
- Or any other approach
The key rule: state managers live in presentation/ and call use cases โ never repositories directly.
Dependency Injection (GetIt)
- Global instance:
final di = GetIt.instance;
- State managers โ
registerFactory() (new instance per screen)
- Use cases โ
registerLazySingleton() (shared singleton)
- Repositories โ
registerLazySingleton() (register as interface type)
- DataSources โ
registerLazySingleton() (register as interface type)
- Each feature has its own
<feature>_di.dart class, called from injection_container.dart
Available Core Utilities
Before writing new code, check if these already solve your need:
- Extensions:
context.colorScheme, context.textTheme, context.hideKeyboard(), .h, .w, .sp, .r, .ht, .wt, .paddingAll(), .marginSymmetric(), .capitalize(), .isEmail
- Widgets:
CustomTextField, PrimaryButton, CustomLoader, ShimmerLoader, CustomDialog, CustomSnackBar, CustomCard, AppBackButton, ConnectivityWidget
- Services:
DioClient (HTTP), LocalStorageService (secure storage), LoggerService (structured logging), NetworkService (connectivity), ImagePickerService
- Validators:
Validators.validateEmail(), .validatePassword(), .validateName(), .validatePhone(), .validateRequired()
- Navigation:
GoRouter with context.go() / context.push(), route names in RouteNames
- Theme:
AppColors, AppTextStyle, light/dark theme via AppThemeData
Additional Resources