# dgbjkrist/flutter-clean-arch architecture

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

- Interactive diagram: https://gitdiagram.com/dgbjkrist/flutter-clean-arch
- Repository: https://github.com/dgbjkrist/flutter-clean-arch

## Overview

##### Project Type and Purpose
- This is a Flutter mobile app (“cleanarchi”) with Android and iOS native projects that wrap the Flutter code.
- The project follows clean architecture principles by separating the code into distinct layers (presentation, domain, data) and includes core elements like dependency injection, navigation, and session management.

##### File Structure
- Top-level directories include “android”, “ios”, and “lib”. The “lib” directory is subdivided into:
- core: Contains common utilities like dependency injection (service locator), navigation (app router), and session management.
- data: Contains data sources (remote API services for auth, transaction, and user), and repositories’ implementations.
- domain: Holds entities, repository interfaces, and use cases. This is the business logic layer of the application.
- presentation: Includes the UI elements (screens) and BLoC/Cubit components for state management.
- Other files like “pubspec.yaml” and “Main.dart” indicate standard Flutter project configurations.

##### Reading the README
- The README confirms that this is a “starting point for a Flutter application” and gets new users started with Flutter, indicating no further custom external integrations beyond the typical mobile app ecosystem.

a. Identification of Main Components:
- Native Shells: Android and iOS projects which bootstrap the Flutter app.
- Flutter Framework: The overall framework which runs the logic.
- Presentation Layer: Contains screens (UI) and BLoC/Cubit components located under lib/presentation.
- Domain Layer: Consists of entities, repository interfaces, and use cases under lib/domain.
- Data Layer: Includes data sources (API services in lib/data/datasources/remote) and concrete repository implementations under lib/data/repositories.
- Core Utilities: Contains dependency injection (service_locator), navigation (app_router) and session management in lib/core.

b. Relationships and Interactions:
- The Presentation Layer interacts with the Domain Layer by invoking use cases (e.g., login, register, transfer).
- The Domain Layer uses abstract repository interfaces that are fulfilled by implementations in the Data Layer.
- The Data Layer communicates with external APIs via remote data sources.
- The Core layer acts as an underlying structure that all layers depend on for common services like dependency injection and navigation.
- UI events flowing from screens to BLoC/Use Cases.
- Use cases calling repository interfaces.
- Repositories calling remote data sources.
- Dependency injection wiring linking all these components.

c. Architectural Patterns/Design Principles:
- Clean Architecture: Clear separation between presentation, domain, and data layers.
- Dependency Injection: The service locator handles wiring across layers.
- BLoC/Cubit Pattern: Used in the presentation for state management.
- Modularization: Each layer’s responsibilities are isolated, making the code testable and scalable.

d. Key Technologies/Frameworks:
- Flutter framework (Dart language)
- BLoC state management libraries (as evidenced by files like auth_bloc.dart, transfer_bloc.dart)
- Dependency Injection pattern (service_locator.dart)
- Platform-specific integrations for Android and iOS.

## Diagram (Mermaid)

```mermaid
graph TD
    A("Native Shell Android"):::native
    B("Native Shell iOS"):::native
    C("Flutter Engine"):::flutter

    A -->|"bootstraps"| C
    B -->|"bootstraps"| C

    subgraph "Core Utilities"
      direction TB
      core1("Dependency Injection"):::core
      core2("Navigation"):::core
      core3("Session Management"):::core
    end

    subgraph "Presentation Layer"
      direction TB
      pres1("UI Screens"):::presentation
      pres2("BLoC/Cubit"):::presentation
    end

    subgraph "Domain Layer"
      direction TB
      dom1("Use Cases & Repository Interfaces"):::domain
    end

    subgraph "Data Layer"
      direction TB
      data1("Repository Implementations"):::data
      data2("API Services"):::data
    end

    C -->|"initializes"| core1
    core1 -->|"wires"| pres1
    pres1 -->|"triggers"| pres2
    pres2 -->|"invokes"| dom1
    dom1 -->|"calls"| data1
    data1 -->|"fetches"| data2

    core1 -.->|"DI_wiring"| pres1
    core1 -.->|"DI_wiring"| pres2
    core1 -.->|"DI_wiring"| dom1
    core1 -.->|"DI_wiring"| data1
    core1 -.->|"DI_wiring"| data2
    core2 -.->|"routes"| pres1
    core3 -.->|"manages"| pres2

    click A "https://github.com/dgbjkrist/flutter-clean-arch/blob/main/android/app/src/main/kotlin/com/example/cleanarchi/MainActivity.kt"
    click B "https://github.com/dgbjkrist/flutter-clean-arch/blob/main/ios/Runner/AppDelegate.swift"
    click pres1 "https://github.com/dgbjkrist/flutter-clean-arch/tree/main/lib/presentation/screens"
    click pres2 "https://github.com/dgbjkrist/flutter-clean-arch/tree/main/lib/presentation/blocs"
    click dom1 "https://github.com/dgbjkrist/flutter-clean-arch/tree/main/lib/domain"
    click data2 "https://github.com/dgbjkrist/flutter-clean-arch/tree/main/lib/data/datasources/remote"
    click data1 "https://github.com/dgbjkrist/flutter-clean-arch/tree/main/lib/data/repositories"
    click core1 "https://github.com/dgbjkrist/flutter-clean-arch/blob/main/lib/core/di/service_locator.dart"
    click core2 "https://github.com/dgbjkrist/flutter-clean-arch/blob/main/lib/core/navigation/app_router.dart"
    click core3 "https://github.com/dgbjkrist/flutter-clean-arch/blob/main/lib/core/session/session_manager.dart"

    classDef native fill:#f9c74f,stroke:#f9844a,stroke-width:2px;
    classDef flutter fill:#90be6d,stroke:#43aa8b,stroke-width:2px;
    classDef core fill:#577590,stroke:#4d908e,stroke-width:2px;
    classDef presentation fill:#f94144,stroke:#f3722c,stroke-width:2px;
    classDef domain fill:#277da1,stroke:#4d908e,stroke-width:2px;
    classDef data fill:#f3722c,stroke:#f9844a,stroke-width:2px;
```
