# nanosoftonline/clean-flutter architecture

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

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

## Overview

##### Project Type and Purpose
- This is a mobile CRM application built in Flutter.
- It implements Clean Architecture to keep business logic (Domain and Use Cases) independent from technical details (UI, data sources, and external APIs).

##### Main Components
- Presentation Layer (UI):
- Found under the “lib/presentation” directory.
- Contains view files (e.g., views for customers and tasks), view models (with corresponding test files), and shared UI components.
- This layer interacts with the user, and it is where Flutter widgets, screens, and state management live.

- Domain Layer (Business Logic):
- Located in “lib/domain”.
- Contains the core models (like Customer and Task), repository interfaces, and use cases (for customer, lead, and task operations).
- This layer defines the business rules and workflows (use cases like create, update, delete, etc.).

- Data Layer:
- Placed under “lib/data”.
- Implements the actual data handling logic by providing concrete implementations for the interfaces defined in the domain layer (API data sources here such as customer_datasource_impl.dart and task_datasource_impl.dart).
- Contains entity mappers if needed (e.g., converting API responses to domain models).

- Core Layer:
- In “lib/core”.
- Defines cross-cutting concerns such as error handling and failure classes using the functional programming style (for example, the Failure class).

- Platforms/Infrastructure:
- All the Flutter platform-specific folders (android, ios, macos, web, windows, linux) represent the external environment where the application is deployed.
- They house all the native configurations and build settings necessary to run the same Flutter code on different platforms.

- External Dependencies:
- Notably declared in pubspec.yaml, including packages such as Equatable, Dio, dartz, UUID, and others.
- These can be noted as external libraries that enable parts of the application (e.g., network communication, unique id generation, and functional programming support).

##### Relationships and Data Flow
- The UI (Presentation Layer) interacts with View Models, which in turn invoke the appropriate Use Cases from the Domain Layer.
- The Use Cases call on Repository interfaces to either fetch or mutate data.
- The concrete implementations of these repositories are in the Data Layer, which bridges the business logic and the external data sources (for example, REST APIs).
- Failures (errors) are propagated back, using functional constructs (like Either from dartz) so that the UI can respond appropriately.
- The Clean Architecture layering ensures that the Domain Layer remains independent of the Data and Presentation layers.

##### Architectural Patterns and Design Principles
- Use of Clean Architecture (dependency inversion, separation of concerns) ensures that the domain models and use cases are at the center of the application.
- The data flow is unidirectional: from the Presentation Layer to the Domain, and then the Data Layer provides outputs.
- The repository pattern is used to abstract away the details of data sources.
- The functional programming approach, in part enabled by dartz, ensures that side effects and failures are handled in a controlled way.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% Presentation Layer
    subgraph "Presentation Layer (UI & View Models)"
        direction TB
        P1["Flutter Views & Widgets"]:::presentation
        P2["View Models"]:::presentation
    end

    %% Domain Layer
    subgraph "Domain Layer (Models, Use Cases, Repository Interfaces)"
        direction TB
        D1["Domain Models (Customer, Task, Lead)"]:::domain
        D2["Use Cases (Create, Update, Delete)"]:::domain
        D3["Repository Interfaces"]:::domain
    end

    %% Data Layer
    subgraph "Data Layer (Data Sources & API Implementations)"
        direction TB
        Data1["API Data Sources (Customer & Task)"]:::data
        Data2["Entity Mappers"]:::data
    end

    %% Core Layer
    subgraph "Core Layer (Error & Failure Handling)"
        C1["Failure/Error Handling"]:::core
    end

    %% Platforms/Infrastructure
    subgraph "Platforms/Infrastructure"
        direction TB
        Plat1["Android"]:::platform
        Plat2["iOS"]:::platform
        Plat3["Linux"]:::platform
        Plat4["macOS"]:::platform
        Plat5["Windows"]:::platform
        Plat6["Web"]:::platform
    end

    %% External Dependencies
    subgraph "External Dependencies"
        ED["Package Declarations (pubspec.yaml)"]:::external
    end

    %% Relationships and Data Flow
    P1 -->|"triggers"| P2
    P2 -->|"calls"| D2
    D2 -->|"invokes"| D3
    D3 -->|"implemented_by"| Data1
    D2 -->|"uses"| D1
    D1 -.->|"reports_failures"| C1
    Data1 -.->|"propagates_errors"| C1
    C1 -.->|"handled_in"| P2

    ED --- P1
    ED --- D1
    ED --- Data1

    P1 -->|"runs_on"| Plat1
    P1 -->|"runs_on"| Plat2
    P1 -->|"runs_on"| Plat3
    P1 -->|"runs_on"| Plat4
    P1 -->|"runs_on"| Plat5
    P1 -->|"runs_on"| Plat6

    %% Click Events
    click P1 "https://github.com/nanosoftonline/clean-flutter/tree/main/lib/presentation"
    click P2 "https://github.com/nanosoftonline/clean-flutter/tree/main/lib/presentation"
    click D1 "https://github.com/nanosoftonline/clean-flutter/tree/main/lib/domain"
    click D2 "https://github.com/nanosoftonline/clean-flutter/tree/main/lib/domain"
    click D3 "https://github.com/nanosoftonline/clean-flutter/tree/main/lib/domain"
    click Data1 "https://github.com/nanosoftonline/clean-flutter/tree/main/lib/data"
    click Data2 "https://github.com/nanosoftonline/clean-flutter/tree/main/lib/data"
    click C1 "https://github.com/nanosoftonline/clean-flutter/tree/main/lib/core"
    click Plat1 "https://github.com/nanosoftonline/clean-flutter/tree/main/android"
    click Plat2 "https://github.com/nanosoftonline/clean-flutter/tree/main/ios"
    click Plat3 "https://github.com/nanosoftonline/clean-flutter/tree/main/linux"
    click Plat4 "https://github.com/nanosoftonline/clean-flutter/tree/main/macos"
    click Plat5 "https://github.com/nanosoftonline/clean-flutter/tree/main/windows"
    click Plat6 "https://github.com/nanosoftonline/clean-flutter/tree/main/web"
    click ED "https://github.com/nanosoftonline/clean-flutter/blob/main/pubspec.yaml"

    %% Styles
    classDef presentation fill:#ADD8E6,stroke:#333,stroke-width:2px;
    classDef domain fill:#90EE90,stroke:#333,stroke-width:2px;
    classDef data fill:#FFFFE0,stroke:#333,stroke-width:2px;
    classDef core fill:#FFC0CB,stroke:#333,stroke-width:2px;
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:2px;
    classDef platform fill:#F0E68C,stroke:#333,stroke-width:2px;
```
