How v8tr/modernmvvm works
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