# rahuldobariya/flutter-clean-architecture architecture

> Architecture diagram of the GitHub repository rahuldobariya/flutter-clean-architecture, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rahuldobariya/flutter-clean-architecture
- Repository: https://github.com/rahuldobariya/flutter-clean-architecture

## Overview

##### 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

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Platforms
    subgraph "External Platforms" 
        direction TB
        Android["Android Shell"]:::external
        iOS["iOS Shell"]:::external
        Web["Web Shell"]:::external
    end

    %% Entry Point & DI
    Main["main.dart"]:::core
    click Main "https://github.com/rahuldobariya/flutter-clean-architecture/blob/master/lib/main.dart"
    DI["injection_container.dart"]:::core
    click DI "https://github.com/rahuldobariya/flutter-clean-architecture/blob/master/lib/injection_container.dart"

    Android --> Main
    iOS --> Main
    Web --> Main
    Main --> DI

    %% Flutter Engine
    FlutterEngine["Flutter Engine / Runner"]:::core
    DI --> FlutterEngine

    %% Layer: Presentation
    subgraph "Presentation Layer" 
        direction TB
        BlocHome["HomePage (Bloc)"]:::presentation
        click BlocHome "https://github.com/rahuldobariya/flutter-clean-architecture/blob/master/lib/Bloc/Features/HomeScreen/Presentation/Pages/home_page.dart"
        BlocListPage["UserListPage (Bloc)"]:::presentation
        click BlocListPage "https://github.com/rahuldobariya/flutter-clean-architecture/blob/master/lib/Bloc/Features/UserListingScreen/Presentation/Pages/userlist_bloc_page.dart"
        BlocAddPage["AddUserPage (Bloc)"]:::presentation
        click BlocAddPage "https://github.com/rahuldobariya/flutter-clean-architecture/blob/master/lib/Bloc/Features/UserListingScreen/Presentation/Pages/add_user_bloc_page.dart"
    end
    FlutterEngine --> BlocHome
    FlutterEngine --> BlocListPage
    FlutterEngine --> BlocAddPage

    %% Layer: State Management
    subgraph "State Management Layer" 
        direction TB
        UserBloc["UserBloc"]:::presentation
        click UserBloc "https://github.com/rahuldobariya/flutter-clean-architecture/blob/master/lib/Bloc/Features/UserListingScreen/Presentation/bloc/user_bloc.dart"
        UserEvent["UserEvent"]:::presentation
        click UserEvent "https://github.com/rahuldobariya/flutter-clean-architecture/blob/master/lib/Bloc/Features/UserListingScreen/Presentation/bloc/user_event.dart"
        UserState["UserState"]:::presentation
        click UserState "https://github.com/rahuldobariya/flutter-clean-architecture/blob/master/lib/Bloc/Features/UserListingScreen/Presentation/bloc/user_state.dart"
    end
    BlocListPage --> UserBloc
    UserBloc --> UserEvent
    UserBloc --> UserState

    %% Layer: Domain
    subgraph "Domain Layer" 
        direction TB
        UserEntity["Entity: User"]:::domain
        click UserEntity "https://github.com/rahuldobariya/flutter-clean-architecture/blob/master/lib/Bloc/Features/UserListingScreen/Domain/Entities/user_entities.dart"
        UserRepoInterface["Repository Interface"]:::domain
        click UserRepoInterface "https://github.com/rahuldobariya/flutter-clean-architecture/blob/master/lib/Bloc/Features/UserListingScreen/Domain/Repositories/user_repository.dart"
        UsecaseList["Usecase: ListUsers"]:::domain
        click UsecaseList "https://github.com/rahuldobariya/flutter-clean-architecture/blob/master/lib/Bloc/Features/UserListingScreen/Domain/Usecases/user_list_case.dart"
        UsecaseAdd["Usecase: AddUser"]:::domain
        click UsecaseAdd "https://github.com/rahuldobariya/flutter-clean-architecture/blob/master/lib/Bloc/Features/UserListingScreen/Domain/Usecases/add_user_case.dart"
    end
    UserBloc --> UsecaseList
    UserBloc --> UsecaseAdd
    UsecaseList --> UserRepoInterface
    UsecaseAdd --> UserRepoInterface

    %% Layer: Data
    subgraph "Data Layer" 
        direction TB
        UserRepoImpl["Repository Impl."]:::data
        click UserRepoImpl "https://github.com/rahuldobariya/flutter-clean-architecture/blob/master/lib/Bloc/Features/UserListingScreen/Data/Repositories/user_repository_imp.dart"
        LocalDataSource["DataSource: local_source"]:::data
        click LocalDataSource "https://github.com/rahuldobariya/flutter-clean-architecture/blob/master/lib/Bloc/Features/UserListingScreen/Data/DataSource/local_source.dart"
    end
    UserRepoInterface --> UserRepoImpl
    UserRepoImpl --> LocalDataSource

    %% Layer: External Storage
    subgraph "External / Storage" 
        direction TB
        HiveHelper["Hive Helper"]:::core
        click HiveHelper "https://github.com/rahuldobariya/flutter-clean-architecture/blob/master/lib/Bloc/Core/Helper/hive_helper.dart"
        SQLiteHelper["SQLite Helper"]:::core
        click SQLiteHelper "https://github.com/rahuldobariya/flutter-clean-architecture/blob/master/lib/SqlWithGetX/Core/Helper/database_helper.dart"
    end
    LocalDataSource --> HiveHelper
    LocalDataSource --> SQLiteHelper

    %% Styles
    classDef presentation fill:#AED6F1,stroke:#2980B9,color:#1B2631;
    classDef domain fill:#ABEBC6,stroke:#27AE60,color:#1B2631;
    classDef data fill:#F9E79F,stroke:#D4AC0D,color:#1B2631;
    classDef core fill:#E5E7E9,stroke:#7B7D7D,color:#1B2631;
    classDef external fill:#D5D8DC,stroke:#566573,color:#1B2631;
```
