# vonjy-2101/mvvm-flutter-project architecture

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

- Interactive diagram: https://gitdiagram.com/vonjy-2101/mvvm-flutter-project
- Repository: https://github.com/vonjy-2101/mvvm-flutter-project

## Overview

##### Project type and purpose
- This is a client-side, multi-platform Flutter application (“PostApp”) that follows an MVVM architecture.
- It consumes a remote REST API (JSONPlaceholder) to fetch posts and comments, display them, and allow users to create new ones.

##### File structure
- Top-level platform folders (android, ios, web) host platform projects and configs.
- lib/ contains the Flutter code, structured per MVVM:
- core/ – global configs (themes, constants, DI/service locator, logging)
- models/ – data classes (PostModel, CommentModel)
- service/api/ – network‐access layer (PostApiService, CommentApiService using Dio)
- viewmodels/ – state & presentation logic (PostListViewModel, PostDetailViewModel, NewPostViewModel, CommentPostViewModel)
- views/ – UI pages and shared widgets (post_list, post_detail, new_post, comment_post, shared)
- main.dart – app entrypoint, sets up DI, theme, routes.
- Configuration files: pubspec.yaml, analysis_options.yaml, gradle scripts, Podfile, web/manifest, etc.

##### Insights from README
- Confirms MVVM + Riverpod (or Provider) + Dio + dark/light theming.
- Lists core features: list posts, add post, view/add comments.
- Shows expected app layout and navigation flow.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Platform Runners
    subgraph "Platform Runners"
        direction TB
        Android("Android\nMainActivity"):::core
        iOS("iOS\nAppDelegate"):::core
        Web("Web\nindex.html"):::core
    end

    %% Presentation Layer
    subgraph "Presentation Layer" 
        direction TB
        PostListScreen["PostListScreen"]:::ui
        PostDetailScreen["PostDetailScreen"]:::ui
        NewPostScreen["NewPostScreen"]:::ui
        CommentPostScreen["CommentPostScreen"]:::ui
        SharedWidgets["Shared Widgets"]:::ui
    end

    %% ViewModel Layer
    subgraph "ViewModel Layer"
        direction TB
        PostListViewModel["PostListViewModel"]:::vm
        PostDetailViewModel["PostDetailViewModel"]:::vm
        NewPostViewModel["NewPostViewModel"]:::vm
        CommentPostViewModel["CommentPostViewModel"]:::vm
    end

    %% Service/API Layer
    subgraph "Service/API Layer"
        direction TB
        HTTPClient["HTTP Client & Interceptors"]:::svc
        PostApiService["PostApiService"]:::svc
        CommentApiService["CommentApiService"]:::svc
    end

    %% Core Layer
    subgraph "Core Layer"
        direction TB
        ServiceLocator["Service Locator"]:::core
        NetworkException["Network Exception Handling"]:::core
        AppTheme["App Theme Configuration"]:::core
        Constants["Application Constants"]:::core
        Logging["Logging Utility"]:::core
        AppPages["Routing Definitions\n(app_pages)"]:::core
        AppRoutes["Routing Definitions\n(app_routes)"]:::core
        MainDart["App Entry Point\n(main.dart)"]:::core
    end

    %% External API
    JSONPlaceholder["JSONPlaceholder REST API"]:::ext

    %% Connections: Platform to main
    Android -->|launches| MainDart
    iOS -->|launches| MainDart
    Web -->|launches| MainDart

    %% Main sets up DI and routes
    MainDart -->|registers| ServiceLocator
    MainDart -->|configures| AppTheme
    MainDart -->|configures| AppPages
    MainDart -->|configures| AppRoutes

    %% DI constructs HTTP client
    ServiceLocator -->|provides| HTTPClient
    ServiceLocator -->|handles| NetworkException
    ServiceLocator -->|injects| PostApiService
    ServiceLocator -->|injects| CommentApiService
    ServiceLocator -->|injects| PostListViewModel
    ServiceLocator -->|injects| PostDetailViewModel
    ServiceLocator -->|injects| NewPostViewModel
    ServiceLocator -->|injects| CommentPostViewModel

    %% UI to ViewModel
    PostListScreen -->|user action| PostListViewModel
    PostDetailScreen -->|user action| PostDetailViewModel
    NewPostScreen -->|user action| NewPostViewModel
    CommentPostScreen -->|user action| CommentPostViewModel

    %% Shared Widgets used by all screens
    SharedWidgets -.-> PostListScreen
    SharedWidgets -.-> PostDetailScreen
    SharedWidgets -.-> NewPostScreen
    SharedWidgets -.-> CommentPostScreen

    %% ViewModel to API Services
    PostListViewModel -->|calls| PostApiService
    PostDetailViewModel -->|calls| CommentApiService
    NewPostViewModel -->|calls| PostApiService
    CommentPostViewModel -->|calls| CommentApiService

    %% Services use HTTP Client
    PostApiService -->|uses| HTTPClient
    CommentApiService -->|uses| HTTPClient

    %% Services communicate with External API
    PostApiService -->|requests| JSONPlaceholder
    CommentApiService -->|requests| JSONPlaceholder
    JSONPlaceholder -->|responds| PostApiService
    JSONPlaceholder -->|responds| CommentApiService

    %% Responses flow back
    PostApiService -->|returns data| PostListViewModel
    PostApiService -->|returns data| NewPostViewModel
    CommentApiService -->|returns data| PostDetailViewModel
    CommentApiService -->|returns data| CommentPostViewModel

    %% ViewModel updates UI
    PostListViewModel -->|updates| PostListScreen
    PostDetailViewModel -->|updates| PostDetailScreen
    NewPostViewModel -->|updates| NewPostScreen
    CommentPostViewModel -->|updates| CommentPostScreen

    %% Click Events
    click PostListScreen "https://github.com/vonjy-2101/mvvm-flutter-project/blob/main/lib/views/post_list/post_list_screen.dart"
    click PostDetailScreen "https://github.com/vonjy-2101/mvvm-flutter-project/blob/main/lib/views/post_detail/post_detail_screen.dart"
    click NewPostScreen "https://github.com/vonjy-2101/mvvm-flutter-project/blob/main/lib/views/new_post/new_post_screen.dart"
    click CommentPostScreen "https://github.com/vonjy-2101/mvvm-flutter-project/blob/main/lib/views/comment_post/comment_post_screen.dart"
    click SharedWidgets "https://github.com/vonjy-2101/mvvm-flutter-project/tree/main/lib/views/shared/"
    click PostListViewModel "https://github.com/vonjy-2101/mvvm-flutter-project/blob/main/lib/viewmodels/post_list_viewmodel.dart"
    click PostDetailViewModel "https://github.com/vonjy-2101/mvvm-flutter-project/blob/main/lib/viewmodels/post_detail_viewmodel.dart"
    click NewPostViewModel "https://github.com/vonjy-2101/mvvm-flutter-project/blob/main/lib/viewmodels/new_post_viewmodel.dart"
    click CommentPostViewModel "https://github.com/vonjy-2101/mvvm-flutter-project/blob/main/lib/viewmodels/comment_post_viewmodel.dart"
    click PostApiService "https://github.com/vonjy-2101/mvvm-flutter-project/blob/main/lib/service/api/post_api_service.dart"
    click CommentApiService "https://github.com/vonjy-2101/mvvm-flutter-project/blob/main/lib/service/api/comment_api_service.dart"
    click HTTPClient "https://github.com/vonjy-2101/mvvm-flutter-project/blob/main/lib/core/di/service_locator.dart"
    click NetworkException "https://github.com/vonjy-2101/mvvm-flutter-project/blob/main/lib/core/di/network_exception.dart"
    click AppTheme "https://github.com/vonjy-2101/mvvm-flutter-project/blob/main/lib/core/app_theme.dart"
    click Constants "https://github.com/vonjy-2101/mvvm-flutter-project/blob/main/lib/core/constants.dart"
    click Logging "https://github.com/vonjy-2101/mvvm-flutter-project/blob/main/lib/core/log.dart"
    click AppPages "https://github.com/vonjy-2101/mvvm-flutter-project/blob/main/lib/core/routes/app_pages.dart"
    click AppRoutes "https://github.com/vonjy-2101/mvvm-flutter-project/blob/main/lib/core/routes/app_routes.dart"
    click MainDart "https://github.com/vonjy-2101/mvvm-flutter-project/blob/main/lib/main.dart"
    click Android "https://github.com/vonjy-2101/mvvm-flutter-project/blob/main/android/app/src/main/kotlin/com/mvvm/mvvm/MainActivity.kt"
    click iOS "https://github.com/vonjy-2101/mvvm-flutter-project/blob/main/ios/Runner/AppDelegate.swift"
    click Web "https://github.com/vonjy-2101/mvvm-flutter-project/blob/main/web/index.html"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0366D6,color:#0366D6,stroke-width:1px
    classDef vm fill:#DFFFE0,stroke:#028A0F,color:#028A0F,stroke-width:1px
    classDef svc fill:#FFE8CC,stroke:#D97904,color:#D97904,stroke-width:1px
    classDef core fill:#F0F0F0,stroke:#6A6A6A,color:#6A6A6A,stroke-width:1px
    classDef ext fill:#FFE0E0,stroke:#D60000,color:#D60000,stroke-width:1px
```
