# devmuaz/flutter-clean-architecture architecture

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

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

## Overview

This project is a Flutter mobile application built using a Clean Architecture approach. The core objective is to separate concerns by dividing the app into distinct layers—Presentation, Domain, and Data—which makes the codebase easier to maintain, test, and extend.

##### Main Components
- Mobile Platforms: Represent the platform-specific layers (Android and iOS) as the underlying runtime environments where the Flutter app is deployed.
- Presentation Layer: This is found under the lib/src/presentation directory. It includes the UI components (views and widgets) and state management (cubits in the cubits subfolder). This layer is responsible for handling user interactions.
- Domain Layer: Located in lib/src/domain, this layer contains the core business models, request/response models, and repository interface definitions that represent the business logic.
- Data Layer: Located in lib/src/data, this layer comprises:
- Data Sources: Separated into local (using a SQLite-like database system with generated code, like in app_database.dart and its converters/DAOs), and remote data sources (defined in news_api_service files which interface with external APIs).
- Repository Implementations: Found in data/repositories. They provide concrete implementations that satisfy the interfaces defined in the Domain.
- Configuration and Dependency Injection: Components such as the configuration settings (router settings in lib/src/config/router and theme settings in lib/src/config/themes) and the dependency injection setup (locator.dart) are vital for wiring the layers together.

##### Relationships and Interactions
- The Flutter UI (Presentation layer) communicates with cubits (state management components) to handle events.
- Cubits interact with the Domain layer via repository interfaces. This ensures business logic isn’t coupled to specific data implementations.
- The Domain layer passes the requests to the Data layer’s repositories, which in turn access remote APIs (through news_api_service) or local databases (through app_database and its associated components).
- The Data layer provides the retrieved or processed data back up the chain.
- Dependency Injection (via locator.dart) ensures that the correct repository implementations and other dependencies are provided at runtime.

##### Architectural Patterns and Design Principles
- Clean Architecture: Strict separation into Presentation, Domain, and Data layers.
- Dependency Inversion: The Domain layer defines interfaces that the Data layer implements.
- State Management with Cubits: Controllers for managing UI state and business events.
- Separation of Concerns: Configuration, theming, and routing are kept in dedicated config folders.

##### Relevant Technologies, Frameworks, and Libraries
- Flutter: The core framework for building the UI.
- Dart: Programming language used for the app.
- State Management: Cubits (from the presentation layer).
- Local Database: Utilizes code generation for app_database (as seen with app_database.g.dart), possibly using a package like Floor or Moor.
- Remote API Services: Implemented in the news_api_service files with generated code (news_api_service.g.dart).
- Dependency Injection: Set up in locator.dart.
- Mobile-specific Build Systems: Android and iOS directories contain platform-specific configuration and build files.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Mobile Platforms
    subgraph "Mobile Platforms"
        A("Android"):::mobile
        B("iOS"):::mobile
    end

    %% Presentation Layer
    subgraph "Presentation Layer"
        C("UI Components (Views/Widgets)"):::presentation
        D("State Management (Cubits)"):::presentation
    end

    %% Domain Layer
    subgraph "Domain Layer"
        E("Business Models"):::domain
        F("Repository Interfaces"):::domain
    end

    %% Data Layer
    subgraph "Data Layer"
        G("Local Data Sources (SQL Database)"):::data
        H("Remote Data Sources (News API)"):::data
        I("Repository Implementations"):::data
    end

    %% Configuration and Dependency Injection
    subgraph "Configuration and Dependency Injection"
        J("Router Settings"):::config
        K("Theme Settings"):::config
        L("Dependency Injection (Locator)"):::config
    end

    %% Relationships
    A -->|"supports"| C
    B -->|"supports"| C
    C -->|"triggers"| D
    D -->|"calls"| F
    F -->|"implemented_by"| I
    I -.->|"fetches_from"| G
    I -.->|"fetches_from"| H
    I -->|"returns_data"| F
    F -->|"returns_results"| D
    D -->|"updates"| C

    L -->|"injects_in"| D
    L -->|"injects_in"| I
    L -->|"injects_in"| F

    K -->|"applied_to"| C
    J -->|"routes"| C

    %% Click Events
    click A "https://github.com/devmuaz/flutter-clean-architecture/tree/master/android/"
    click B "https://github.com/devmuaz/flutter-clean-architecture/tree/master/ios/"
    click C "https://github.com/devmuaz/flutter-clean-architecture/tree/master/lib/src/presentation/views"
    click D "https://github.com/devmuaz/flutter-clean-architecture/tree/master/lib/src/presentation/cubits"
    click E "https://github.com/devmuaz/flutter-clean-architecture/tree/master/lib/src/domain/models"
    click F "https://github.com/devmuaz/flutter-clean-architecture/tree/master/lib/src/domain/repositories"
    click G "https://github.com/devmuaz/flutter-clean-architecture/tree/master/lib/src/data/datasources/local"
    click H "https://github.com/devmuaz/flutter-clean-architecture/tree/master/lib/src/data/datasources/remote"
    click I "https://github.com/devmuaz/flutter-clean-architecture/tree/master/lib/src/data/repositories"
    click J "https://github.com/devmuaz/flutter-clean-architecture/tree/master/lib/src/config/router"
    click K "https://github.com/devmuaz/flutter-clean-architecture/tree/master/lib/src/config/themes"
    click L "https://github.com/devmuaz/flutter-clean-architecture/blob/master/lib/src/locator.dart"

    %% Styles
    classDef mobile fill:#FFCC00,stroke:#333,stroke-width:2px;
    classDef presentation fill:#66CCFF,stroke:#333,stroke-width:2px;
    classDef domain fill:#99FF99,stroke:#333,stroke-width:2px;
    classDef data fill:#FF9999,stroke:#333,stroke-width:2px;
    classDef config fill:#CCCCFF,stroke:#333,stroke-width:2px;
```
