How aliahmedbd/news-app-mvvm-kotlin-coroutine--flow-koin-retrofit- works
Project Type and Purpose
• This is a full-stack mobile application (Android) built using MVVM, Kotlin Coroutines & Flows, DI with Koin, and Retrofit.
• It consists of two Gradle modules:
– app: the Android UI/application module
– datamodule: a Kotlin library module that provides data models, networking, and repository logic
File Structure
Top-level modules:
• NewsApp/app
– src/main/java/.../ui → Fragments & MainActivity (SearchNewsFragment, NewsFragment, DetailNewsFragment, FavoriteNewsFragment)
– src/main/java/.../viewmodel → NewsViewModel
– src/main/java/.../di → AppModule (Koin definitions for ViewModel, SharedPreferences, etc.)
– adapter, util packages (UI adapters, extension functions)
– res → layouts, navigation graph, menus, drawables
• NewsApp/datamodule
– datamodel → Article, NewsResponse, UserInput
– network → APIClient (Retrofit), APIService (endpoint definition), URL constants, ResponseModel
– repository → DataRepository (exposes suspend/Flow methods)
– di → DataModule (Koin definitions for Retrofit, repository)
README for Insights
• MVVM clean architecture with clear separation: View ↔ ViewModel ↔ Repository
• Coroutine + Flow for asynchronous, streaming data
• Koin for dependency injection (no generated code)
• Retrofit + NewsCatcher external API as remote data source
• Unit tests (Junit, instrumented) for repository and favorites persistence
Main Components
A. UI Layer (Android)
– MainActivity + NavHostFragment
– Fragments: NewsFragment, SearchNewsFragment, DetailNewsFragment, FavoriteNewsFragment
B. ViewModel Layer
– NewsViewModel
C. Domain/Data Layer (in datamodule)
– DataRepository (implements business logic for fetch, search, favorites)
D. Data Sources
– Remote: APIService (Retrofit client to NewsCatcher API)
– Local: SharedPreferences (via SharedPreferenceExt) for favorites cache
E. Dependency Injection
– Koin containers: AppModule (UI + ViewModel bindings), DataModule (Retrofit & repository bindings)
F. External Service
– NewsCatcher REST API
Relationships & Data Flows
• Fragments ↔ NewsViewModel
– observe Flows of List<Article>, perform search/favorite actions
• NewsViewModel → DataRepository
– calls suspend/Flow methods to fetch / search / save favorites
• DataRepository → APIService
– Retrofit GET requests
• DataRepository → SharedPreferences
– save/retrieve favorite Article IDs or objects
• Koin → injects Repository & Retrofit → ViewModel → Fragments
Key Architectural Patterns & Principles
• MVVM (View ↔ ViewModel ↔ Model/Repository)
• Single Activity with Navigation Graph (NavController)
• Dependency Injection (Koin modules separate app & data concerns)
• Clean separation of network vs. UI vs. storage
• Asynchronous data via Coroutines + Flow
Elements
• Labels: “UI / Fragments,” “NewsViewModel,” “DataRepository,” “Retrofit APIService,” “SharedPreferences”
– Green for ViewModel
– Orange for repository & DI