← all projects

learn this topic (theory + diagrams) →

MVVM-Architecture-Android

A minimal but complete MVVM sample — Dagger for DI, Retrofit for networking, Coroutines + Flow + StateFlow for reactive UI state.

View on GitHub ↗Kotlinupdated 2d ago

KotlinMVVMDaggerRetrofitStateFlow

High-level design

One screen fetching news headlines, wired with the tools a production app uses — deliberately small so the entire architecture can be held in your head at once.

data/model

Article, Source, TopHeadlinesResponse

data/api

Retrofit NetworkService interface

data/repository

TopHeadlineRepository — the single source of truth the ViewModel calls

di

Dagger ApplicationModule/ActivityModule, components, qualifiers, scopes

ui/base

UiState + ViewModelProviderFactory

ui/topheadline

Activity, ViewModel, Adapter

Low-level design

The load-bearing idea is the unidirectional data flow: View → ViewModel → Repository, with Dagger wiring the graph.

  • View observes a StateFlow<UiState>; it never talks to the data layer directly
  • Dagger modules declare how to build deps, components declare where they're available — nothing constructs its own collaborators
  • A sealed UiState (Loading / Success / Error) keeps the UI out of invalid states