# dev-adnani/flutter-mvvm-template architecture

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

- Interactive diagram: https://gitdiagram.com/dev-adnani/flutter-mvvm-template
- Repository: https://github.com/dev-adnani/flutter-mvvm-template

## Overview

##### Project Type and Purpose
- This is a cross-platform Flutter client application (Android, iOS, Web, macOS, Windows, Linux) following the MVVM (Model-View-ViewModel) pattern.
- It uses Provider for state management and communicates with remote APIs and optional local storage.

##### File Structure
- The `lib/` directory holds the core app:
– data (local + remote)
– models
– repository
– view_model
– view (screens + shared widgets)
– utils
– main.dart (app entry point)

##### Key Architectural Patterns
- MVVM: View ↔ ViewModel ↔ Repository ↔ DataSources
- Provider: injects ViewModel into the Widget tree
- Repository abstracts over local vs. remote data
- Network layer for HTTP calls, optional local DB layer for caching

##### Relationships & Data Flow
- UI Widgets → read/write → ViewModel (using Provider)
- ViewModel → calls → Repository
- Repository → routes calls → RemoteAPIService or LocalDataSource
- RemoteAPIService → HTTP calls → External API → returns Response → mapped to Models
- LocalDataSource → reads/writes → local.db
- Models flow back up: DataSource → Repository → ViewModel → UI

##### Technologies & Frameworks
- Flutter/Dart (core engine)
- Provider (state management)
- HTTP client (e.g., `network.api.service.dart`)
- SQLite or simple file (local.db.txt)
- Platform embedder (Android Gradle, Xcode, CMake for desktop)

##### Essential Details to Capture
- main.dart (App entry) initializes Providers
- API endpoints configured in `api.end.points.dart`
- BaseApiService → inherited by NetworkApiService
- app.exceptions.dart for error flow from remote calls up to UI

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Flutter Shell Layer
    subgraph "Flutter Host" 
        direction TB
        Android["Android"]:::shell
        IOS["iOS"]:::shell
        Linux["Linux"]:::shell
        MacOS["macOS"]:::shell
        Windows["Windows"]:::shell
        Web["Web"]:::shell
    end

    %% App Entry
    Main["main.dart\n(App Entry)"]:::shell

    %% Presentation Layer
    subgraph "Presentation Layer (View)" 
        direction TB
        HomeScreen["HomeScreen Widget"]:::view
        UserScreen["UserScreen Widget"]:::view
        LoadingWidget["Loading Widget"]:::view
        ErrorWidget["Error Widget"]:::view
        TextView["Text View Widget"]:::view
    end

    %% ViewModel Layer
    subgraph "ViewModel Layer" 
        direction TB
        UserViewModel["UserViewModel"]:::domain
    end

    %% Repository Layer
    subgraph "Repository Layer" 
        direction TB
        UserRepo["UserRepository"]:::domain
    end

    %% Data Sources Layer
    subgraph "Data Sources" 
        direction TB
        subgraph "Remote Data Source"
            BaseApiService["BaseApiService"]:::data
            NetworkApiService["NetworkApiService"]:::data
            ApiEndpoints["API Endpoints"]:::data
            AppException["AppException"]:::data
            ApiResponse["API Response"]:::data
            ApiStatus["API Status"]:::data
        end
        subgraph "Local Data Source"
            LocalDB["Local DB (local.db)"]:::data
        end
    end

    %% Models & Support
    UserModel["UserModel"]:::domain
    Resources["Resources"]:::support
    Utils["Utilities"]:::support

    %% External API
    ExternalAPI["External REST API"]:::external

    %% Connections
    Android -->|hosts| Main
    IOS -->|hosts| Main
    Linux -->|hosts| Main
    MacOS -->|hosts| Main
    Windows -->|hosts| Main
    Web -->|hosts| Main

    Main -->|initializes Provider| HomeScreen
    Main -->|initializes Provider| UserScreen

    HomeScreen -->|injects ViewModel| UserViewModel
    UserScreen -->|injects ViewModel| UserViewModel

    UserViewModel -->|calls| UserRepo
    UserRepo -->|uses| NetworkApiService
    UserRepo -->|uses| LocalDB

    NetworkApiService -->|HTTP call| ExternalAPI
    ExternalAPI -->|response| ApiResponse
    ApiResponse -->|maps to| UserModel
    ApiStatus -->|status info| NetworkApiService
    AppException -->|error flow| UserViewModel

    LocalDB -->|reads/writes| UserModel

    UserModel -->|data| UserRepo
    UserRepo -->|returns| UserViewModel
    UserViewModel -->|updates| HomeScreen
    UserViewModel -->|updates| UserScreen

    Resources -->|provides| HomeScreen
    Resources -->|provides| UserScreen
    Utils -->|helper| UserRepo

    %% Click Events
    click Android "https://github.com/dev-adnani/flutter-mvvm-template/tree/main/android/"
    click IOS "https://github.com/dev-adnani/flutter-mvvm-template/tree/main/ios/"
    click Linux "https://github.com/dev-adnani/flutter-mvvm-template/tree/main/linux/"
    click MacOS "https://github.com/dev-adnani/flutter-mvvm-template/tree/main/macos/"
    click Windows "https://github.com/dev-adnani/flutter-mvvm-template/tree/main/windows/"
    click Web "https://github.com/dev-adnani/flutter-mvvm-template/tree/main/web/"
    click Main "https://github.com/dev-adnani/flutter-mvvm-template/blob/main/lib/main.dart"
    click HomeScreen "https://github.com/dev-adnani/flutter-mvvm-template/blob/main/lib/view/screens/homeScreen/home.screen.dart"
    click UserScreen "https://github.com/dev-adnani/flutter-mvvm-template/blob/main/lib/view/screens/userScreen/user.screen.dart"
    click LoadingWidget "https://github.com/dev-adnani/flutter-mvvm-template/blob/main/lib/view/shared/loading.widget.dart"
    click ErrorWidget "https://github.com/dev-adnani/flutter-mvvm-template/blob/main/lib/view/shared/my.error.widget.dart"
    click TextView "https://github.com/dev-adnani/flutter-mvvm-template/blob/main/lib/view/shared/my.text.view.dart"
    click UserViewModel "https://github.com/dev-adnani/flutter-mvvm-template/blob/main/lib/view_model/userViewModel/user.view.model.dart"
    click UserRepo "https://github.com/dev-adnani/flutter-mvvm-template/blob/main/lib/repository/userRepo/user.repo.dart"
    click BaseApiService "https://github.com/dev-adnani/flutter-mvvm-template/blob/main/lib/data/remote/network/base.api.service.dart"
    click NetworkApiService "https://github.com/dev-adnani/flutter-mvvm-template/blob/main/lib/data/remote/network/network.api.service.dart"
    click ApiEndpoints "https://github.com/dev-adnani/flutter-mvvm-template/blob/main/lib/data/remote/network/api.end.points.dart"
    click AppException "https://github.com/dev-adnani/flutter-mvvm-template/blob/main/lib/data/remote/app.exception.dart"
    click ApiResponse "https://github.com/dev-adnani/flutter-mvvm-template/blob/main/lib/data/remote/response/api.response.dart"
    click ApiStatus "https://github.com/dev-adnani/flutter-mvvm-template/blob/main/lib/data/remote/response/api.status.dart"
    click LocalDB "https://github.com/dev-adnani/flutter-mvvm-template/blob/main/lib/data/local/local.db.txt"
    click UserModel "https://github.com/dev-adnani/flutter-mvvm-template/blob/main/lib/models/userModel/user.model.dart"
    click Resources "https://github.com/dev-adnani/flutter-mvvm-template/blob/main/lib/res/resources.dart"
    click Utils "https://github.com/dev-adnani/flutter-mvvm-template/blob/main/lib/utils/utils.dart"

    %% Styles
    classDef shell fill:#f0f0f0,stroke:#333,stroke-width:1px
    classDef view fill:#cce5ff,stroke:#024,stroke-width:1px
    classDef domain fill:#ffe0b2,stroke:#663c00,stroke-width:1px
    classDef data fill:#d0f0c0,stroke:#2e7d32,stroke-width:1px
    classDef external fill:#eeeeee,stroke:#666,stroke-width:1px
    classDef support fill:#f5f5f5,stroke:#999,stroke-width:1px
```
