# v8tr/modernmvvm architecture

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

- Interactive diagram: https://gitdiagram.com/v8tr/modernmvvm
- Repository: https://github.com/v8tr/modernmvvm

## Overview

##### Project type and purpose
- This is a single iOS client app built in SwiftUI, illustrating the MVVM (Model–View–ViewModel) pattern with Combine and the CombineFeedback unidirectional data‐flow library.
- It fetches movie data from a remote API, shows a movies list, and displays movie details.

##### Break down the file structure into architectural modules
a. App Shell
– AppDelegate.swift / SceneDelegate.swift: entry points and scene management.
– SwiftUI App (ModernMVVM.xcodeproj).
b. Features
– MoviesList (MoviesListView.swift, MovieListViewModel.swift)
– MovieDetails (MovieDetailView.swift, MovieDetailViewModel.swift)
c. Data Layer / API
– API/Agent.swift: generic HTTP client
– API/MoviesAPI.swift: endpoint definitions & request logic
d. Feedback / State Management
– Feedback/System.swift & Feedback/Feedback.swift: CombineFeedback loop definitions
e. Controls & Utilities
– Controls/AsyncImage (AsyncImage.swift, ImageLoader.swift, ImageCache.swift)
– Controls/Spinner.swift
– Extensions/View+Ext.swift
f. Supporting Files
– Assets, Storyboard for launch screen, Info.plist

##### Extract key technologies and patterns
- SwiftUI for views, Combine for reactive streams, CombineFeedback for unidirectional state machine, MVVM for separation of concerns, REST API calls for data, image loader + cache for asynchronous asset loading.

1. UI Layer (SwiftUI Views)
– MoviesListView & MovieDetailView
– Custom Controls (AsyncImage, Spinner)
2. ViewModels (MVVM)
– MovieListViewModel & MovieDetailViewModel
– Expose @Published state, accept user/intents via CombineFeedback Subjects
3. Feedback Loop / State Machine
– Feedback.System: coordinates intents → state → effects (API) → new state
4. Data Layer
– MoviesAPI: defines network requests
– Agent: executes URLSessions → Publishers
5. Models
– Movie, MovieDetail (JSON‐decoded structs)
6. External Service
– Remote Movies API endpoint
7. Utilities
– ImageLoader + ImageCache for AsyncImage control

##### Relationships & data flows
a. User taps or onAppear triggers an Intent in the View.
b. View forwards Intent to ViewModel’s Feedback loop.
c. Feedback loop processes Intent, emits an Effect (e.g., “fetchMovies”).
d. Agent calls MoviesAPI → network → JSON → Model
e. Feedback loop reduces new State (loading → success/failure).
f. ViewModel publishes new @Published state.
g. SwiftUI View updates UI.
h. AsyncImage uses ImageLoader → cache → network → returns Image → displayed.

##### Architectural patterns & principles
- Unidirectional data flow: Intent → Feedback → Effect → State → UI
- MVVM: clear separation between Views and stateful logic in ViewModels
- Reusable Controls: AsyncImage, Spinner decoupled from features
- Dependency inversion: Agent abstracts networking, easy to mock
- Combine & CombineFeedback for reactive chaining

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% App Shell
    subgraph "App Shell"
        AppDelegate["AppDelegate.swift"]:::app
        SceneDelegate["SceneDelegate.swift"]:::app
        Xcodeproj["ModernMVVM.xcodeproj"]:::app
    end

    %% UI Layer
    subgraph "UI Layer (Views)" 
        MoviesListView["MoviesListView"]:::ui
        MovieDetailView["MovieDetailView"]:::ui
    end

    %% Controls & Utilities
    subgraph "Controls & Utilities"
        subgraph "AsyncImage Control"
            AsyncImage["AsyncImage.swift"]:::control
            ImageLoader["ImageLoader.swift"]:::control
            ImageCache["ImageCache.swift"]:::control
        end
        Spinner["Spinner.swift"]:::control
        ViewExt["View+Ext.swift"]:::control
    end

    %% ViewModels & Feedback
    subgraph "ViewModels & Feedback"
        MovieListVM["MovieListViewModel"]:::vm
        MovieDetailVM["MovieDetailViewModel"]:::vm
        FeedbackSys["System.swift"]:::vm
        FeedbackCore["Feedback.swift"]:::vm
    end

    %% Data Layer / API
    subgraph "Data Layer / API"
        Agent["Agent.swift"]:::data
        MoviesAPI["MoviesAPI.swift"]:::data
    end

    %% Models
    subgraph "Models"
        MovieModel["Movie"]:::model
        MovieDetailModel["MovieDetail"]:::model
    end

    %% External Service
    ExternalService["Remote Movies API"]:::external

    %% Supporting Files
    subgraph "Supporting Files"
        Assets["Assets.xcassets"]:::app
        LaunchScreen["LaunchScreen.storyboard"]:::app
        InfoPlist["Info.plist"]:::app
    end

    %% Relationships
    MoviesListView -->|"onAppear Intent"| MovieListVM
    MovieDetailView -->|"onAppear Intent"| MovieDetailVM
    MovieListView -->|uses| Spinner
    MovieDetailView -->|uses| AsyncImage

    MovieListVM -->|"intent"| FeedbackSys
    MovieDetailVM -->|"intent"| FeedbackSys

    FeedbackSys -->|"effect"| Agent
    Agent -->|"call"| MoviesAPI
    MoviesAPI -->|"response JSON"| FeedbackSys

    FeedbackSys -->|"newState"| MovieListVM
    FeedbackSys -->|"newState"| MovieDetailVM

    MoviesAPI -->|"decode"| MovieModel
    MoviesAPI -->|"decode"| MovieDetailModel

    AsyncImage -->|"loadImage"| ImageLoader
    ImageLoader -->|"cache lookup"| ImageCache
    ImageLoader -->|"network request"| ExternalService

    %% Click Events
    click AppDelegate "https://github.com/v8tr/modernmvvm/blob/master/ModernMVVM/App/AppDelegate.swift"
    click SceneDelegate "https://github.com/v8tr/modernmvvm/blob/master/ModernMVVM/App/SceneDelegate.swift"
    click Xcodeproj "https://github.com/v8tr/modernmvvm/blob/master/ModernMVVM.xcodeproj"

    click MoviesListView "https://github.com/v8tr/modernmvvm/blob/master/ModernMVVM/Features/MoviesList/MoviesListView.swift"
    click MovieListVM "https://github.com/v8tr/modernmvvm/blob/master/ModernMVVM/Features/MoviesList/MovieListViewModel.swift"

    click MovieDetailView "https://github.com/v8tr/modernmvvm/blob/master/ModernMVVM/Features/MovieDetails/MovieDetailView.swift"
    click MovieDetailVM "https://github.com/v8tr/modernmvvm/blob/master/ModernMVVM/Features/MovieDetails/MovieDetailViewModel.swift"

    click Agent "https://github.com/v8tr/modernmvvm/blob/master/ModernMVVM/API/Agent.swift"
    click MoviesAPI "https://github.com/v8tr/modernmvvm/blob/master/ModernMVVM/API/MoviesAPI.swift"

    click FeedbackSys "https://github.com/v8tr/modernmvvm/blob/master/ModernMVVM/Feedback/System.swift"
    click FeedbackCore "https://github.com/v8tr/modernmvvm/blob/master/ModernMVVM/Feedback/Feedback.swift"

    click AsyncImage "https://github.com/v8tr/modernmvvm/blob/master/ModernMVVM/Controls/AsyncImage/AsyncImage.swift"
    click ImageLoader "https://github.com/v8tr/modernmvvm/blob/master/ModernMVVM/Controls/AsyncImage/ImageLoader.swift"
    click ImageCache "https://github.com/v8tr/modernmvvm/blob/master/ModernMVVM/Controls/AsyncImage/ImageCache.swift"
    click Spinner "https://github.com/v8tr/modernmvvm/blob/master/ModernMVVM/Controls/Spinner.swift"
    click ViewExt "https://github.com/v8tr/modernmvvm/blob/master/ModernMVVM/Extensions/View+Ext.swift"

    click Assets "https://github.com/v8tr/modernmvvm/blob/master/ModernMVVM/SupportingFIles/Assets.xcassets"
    click LaunchScreen "https://github.com/v8tr/modernmvvm/blob/master/ModernMVVM/SupportingFIles/Base.lproj/LaunchScreen.storyboard"
    click InfoPlist "https://github.com/v8tr/modernmvvm/blob/master/ModernMVVM/SupportingFIles/Info.plist"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#3399ff
    classDef vm fill:#d4edda,stroke:#28a745
    classDef data fill:#fff3cd,stroke:#ffc107
    classDef model fill:#e2e3e5,stroke:#6c757d
    classDef external fill:#e2d4f0,stroke:#6f42c1
    classDef control fill:#d1ecf1,stroke:#17a2b8
    classDef app fill:#f0f0f0,stroke:#343a40
```
