# iamageo/flutter_mvvm_template architecture

> Architecture diagram of the GitHub repository iamageo/flutter_mvvm_template, 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/iamageo/flutter_mvvm_template
- Repository: https://github.com/iamageo/flutter_mvvm_template

## Overview

##### Main Components
- Mobile Platforms: Although the primary focus is on the Flutter code under lib, include separate blocks (or notes) for the Android and iOS configurations. This shows that while the UI and business logic are cross-platform, build configurations and platform-specific settings are managed in dedicated directories.
- UI Layer:
- Located in the lib/ui directory with subdirectories organized by functionality (e.g., get and post). This layer contains the visual screens.
- Router:
- Found under lib/router, which centralizes screen definitions, routes, and navigation bindings using GetX.
- ViewModel / Controller Layer:
- Within lib/ui/controller and the GetX bindings in lib/ui/get/binding and lib/ui/post/binding. This layer implements the MVVM pattern by binding UI components to data streams via GetX.
- Repository & Data Access Layer:
- Found under lib/remote/repository, where the abstraction layer between the data sources (APIs) and the application resides. This layer ensures separation of concerns.
- API Client and Data Models:
- lib/remote/api holds components like API endpoints and HTTP manager for making network calls.
- lib/remote/model and lib/remote/response include the data models (with generated helpers from Freezed and json_serializable) and response handlers.
- External Libraries / Frameworks:
- GetX is used for state management, dependency injection, and navigation.
- Freezed and json_annotation handle data immutability and JSON conversion.

##### Relationships and Interactions
- Data flows back from the API response (processed by the corresponding response/model classes) to the Repository and then gets passed to the ViewModels which update the UI.

##### Architectural Patterns and Design Principles
- MVVM Pattern: Clearly separate out Model (data models and API response handling), View (UI screens), and ViewModel (controllers managing business logic and state).
- Repository Pattern: Abstract data sourcing by encapsulating API calls and local data (if applicable) so that the rest of the app is decoupled from data access logic.
- Code Generation Tools: Freezed (for immutable models) and json_annotation together with json_serializable are key parts of the Model layer.

## Diagram (Mermaid)

```mermaid
flowchart TD

    subgraph "Mobile Platforms"
        Android("Android"):::platform
        iOS("iOS"):::platform
    end

    subgraph "UI Layer"
        BaseScreen("Base Screen"):::ui
        UIGet("UI - GET"):::ui
        UIPost("UI - POST"):::ui
    end

    subgraph "Router"
        Router("Router"):::router
    end

    subgraph "Controller/Bindings"
        BindingGet("GetX Binding (GET)"):::controller
        BindingPost("GetX Binding (POST)"):::controller
        ViewModel("ViewModel/Controller"):::controller
    end

    subgraph "Repository Layer"
        Repository("Repository"):::repo
    end

    subgraph "API & Data"
        APIClient("API Client"):::api
        DataModels("Data Models"):::api
        APIResponse("API Response"):::api
    end

    %% Connections between components
    Android ---|"config"| BaseScreen
    iOS ---|"config"| BaseScreen

    BaseScreen -->|"navigates"| Router
    UIGet -->|"navigates"| Router
    UIPost -->|"navigates"| Router

    BaseScreen -->|"triggers"| BindingGet
    UIGet -->|"triggers"| BindingGet
    UIPost -->|"triggers"| BindingPost

    BindingGet -->|"instantiates"| ViewModel
    BindingPost -->|"instantiates"| ViewModel

    ViewModel -->|"fetches/updates"| Repository
    Repository -->|"calls"| APIClient
    APIClient -->|"formats"| DataModels
    APIClient -->|"handles"| APIResponse
    APIResponse -->|"returns"| Repository
    Repository -->|"updates"| ViewModel
    ViewModel -->|"updates"| BaseScreen
    ViewModel -->|"updates"| UIGet
    ViewModel -->|"updates"| UIPost

    Router -->|"maps to"| BaseScreen
    Router -->|"maps to"| UIGet
    Router -->|"maps to"| UIPost

    %% Click Events
    click Android "https://github.com/iamageo/flutter_mvvm_template/tree/main/android/"
    click iOS "https://github.com/iamageo/flutter_mvvm_template/tree/main/ios/"
    click BaseScreen "https://github.com/iamageo/flutter_mvvm_template/blob/main/lib/ui/base_screen.dart"
    click UIGet "https://github.com/iamageo/flutter_mvvm_template/blob/main/lib/ui/get/get_example_screen.dart"
    click UIPost "https://github.com/iamageo/flutter_mvvm_template/blob/main/lib/ui/post/post_example_screen.dart"
    click Router "https://github.com/iamageo/flutter_mvvm_template/blob/main/lib/router/screen_controller.dart"
    click ViewModel "https://github.com/iamageo/flutter_mvvm_template/blob/main/lib/ui/controller/example_view_model.dart"
    click BindingGet "https://github.com/iamageo/flutter_mvvm_template/blob/main/lib/ui/get/binding/get_example_binding.dart"
    click BindingPost "https://github.com/iamageo/flutter_mvvm_template/blob/main/lib/ui/post/binding/post_example_binding.dart"
    click Repository "https://github.com/iamageo/flutter_mvvm_template/blob/main/lib/remote/repository/app_repository.dart"
    click APIClient "https://github.com/iamageo/flutter_mvvm_template/blob/main/lib/remote/api/api_endpoints.dart"
    click DataModels "https://github.com/iamageo/flutter_mvvm_template/blob/main/lib/remote/model/base_model.dart"
    click APIResponse "https://github.com/iamageo/flutter_mvvm_template/blob/main/lib/remote/response/api_response.dart"

    %% Styles
    classDef platform fill:#D3D3D3,stroke:#000,stroke-width:1px;
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef router fill:#FFD700,stroke:#000,stroke-width:1px;
    classDef controller fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef repo fill:#FFA500,stroke:#000,stroke-width:1px;
    classDef api fill:#FFB6C1,stroke:#000,stroke-width:1px;
```
