How rahuldobariya/flutter-clean-architecture works
Project type and purpose
• This is a multi‐platform Flutter application named “clean_demo” that demonstrates Clean Architecture across different state‐management solutions (Bloc, Cubit, GetX, Provider, SqlWithGetX).
• Its purpose is to show how to structure features (HomeScreen, UserListing) using layered architecture (Core, Data, Domain, Presentation) and to compare various Flutter state‐management patterns.
File structure
• Top-level directories:
• android, ios, web – platform shells and configs for mobile and web targets
• lib – the cross‐platform Dart code
• assets – image and other static resources
• injection_container.dart – dependency injection setup
• main.dart – application entry point
• In lib you have five parallel implementations (Bloc, Cubit, GetX, Provider, SqlWithGetX). Each follows a Clean Architecture pattern:
• Core – common helpers, constants, failure classes, navigation observers
• Features – each feature subdivided into Data (DataSource, Models, Repositories), Domain (Entities, Repositories interfaces, Usecases), Presentation (UI pages, widgets, state layer)
README
• It simply identifies this as a starting point for a Flutter app called clean_demo.
Components
a. Main components:
• Platform Layer: Android, iOS, Web shells
• Flutter Engine / Runner – the cross‐platform runtime
• Presentation Layer – Widget trees grouped by feature and state‐management pattern (Home & UserListing UIs)
• State Management Layer – Bloc, Cubit, GetX Controllers, Providers
• Domain Layer – Usecases and Entities (feature business logic abstractions)
• Data Layer – Repositories, Data Sources (Hive helpers or SQLite DB helpers), Data Models
• Core Services – Constants, Failure handling, Navigation observers, DI container
b. Relationships and interactions:
• User taps UI widget → triggers an event in the State Manager → invokes a Usecase → calls a Repository interface → implementation in Data Layer → DataSource reads/writes local storage (Hive or SQLite) → returns Entities back up → State Manager emits new State → UI rebuilds
• injection_container.dart wires concrete Repository/DataSource implementations to Domain interfaces and registers State Managers with Flutter’s DI system before main.dart runs
c. Architectural patterns and principles:
• Clean Architecture layering: Presentation → Domain → Data → External (local DB)
• Dependency Inversion: Domain depends only on abstractions, not on concrete Data sources
• Separation of concerns: each folder (Core, Data, Domain, Presentation) has a single responsibility
• Multiple state‐management implementations to illustrate interchangeable presentation strategies
d. Key technologies/frameworks:
• Flutter & Dart for UI and business logic
• flutter_bloc / bloc for Bloc pattern
• cubit / flutter_bloc for Cubit
• get / getx for GetX
• provider for Provider pattern
• hive for local key‐value storage
• sqflite for SQLite (SqlWithGetX implementation)
• get_it or similar for dependency injection in injection_container.dart
Detailed but focused
• Injection_container linking Repositories and State Managers into the widget tree