A production-structured Android starter project implementing clean MVVM (Model-View-ViewModel) architecture, token-based REST authentication, Kotlin Coroutines, ViewBinding, persistent session storage, and interactive dashboard UI.
The MVVM-implementation project is an architectural reference blueprint demonstrating how to build robust, decoupled Android applications. By strictly isolating UI controllers (Activities) from business logic (ViewModels) and data sources (Repositories), the codebase achieves clean separation of concerns, high testability, and seamless session state management.
- MVVM + Repository Pattern: Distinct layering that keeps Views purely declarative, ViewModels lifecycle-aware, and Repositories as the single source of truth for remote data.
- RESTful Network Layer: Asynchronous HTTP communication with remote REST endpoints via Google Volley dispatches inside Kotlin Coroutines (
viewModelScope). - Secure Session Lifecycle: Automatic session verification on startup (Splash screen) with persistent authentication token storage in
SharedPreferences. - Type-Safe View Binding: Zero boilerplate
findViewByIdcalls with Android Jetpack ViewBinding. - Rich User Experience: Smooth Lottie vector animations during startup and dynamic accordion/dropdown dashboard layouts.
graph TD
classDef view fill:#2D3748,stroke:#4FD1C5,stroke-width:2px,color:#fff;
classDef vm fill:#1A365D,stroke:#63B3ED,stroke-width:2px,color:#fff;
classDef repo fill:#234E52,stroke:#38B2AC,stroke-width:2px,color:#fff;
classDef storage fill:#744210,stroke:#F6E05E,stroke-width:2px,color:#fff;
classDef remote fill:#7B341E,stroke:#ED8936,stroke-width:2px,color:#fff;
subgraph ViewLayer ["View Layer (Activities & ViewBinding)"]
Splash["MainActivitySplash<br/>(Lottie Animation)"]:::view
Login["MainActivityLogin"]:::view
Register["MainActivityRegister"]:::view
Home["MainActivityHome<br/>(Interactive Dashboard)"]:::view
end
subgraph ViewModelLayer ["ViewModel Layer (Lifecycle Aware)"]
AuthVM["AuthViewModel<br/>(viewModelScope.launch)"]:::vm
end
subgraph RepositoryLayer ["Data & Repository Layer"]
AuthRepo["AuthRepository"]:::repo
Prefs["SharedPreferences<br/>('PrefsDatabase' / user_token)"]:::storage
BackendAPI["Remote REST API<br/>(cricdex.enfotrix.com/api)"]:::remote
end
Splash -->|1. Check user_token| Prefs
Splash -->|Token Present| Home
Splash -->|Token Null| Login
Login -->|2. Trigger loginUser| AuthVM
Register -->|Trigger registerUser| AuthVM
AuthVM -->|3. Dispatch network request| AuthRepo
AuthRepo -->|4. Volley JsonObjectRequest POST| BackendAPI
BackendAPI -->|5. JSON Response + Token| AuthRepo
AuthRepo -->|6. Callback onSuccess| AuthVM
AuthVM -->|7. Deliver Token| Login
Login -->|8. Save token| Prefs
Login -->|9. Route to| Home
Home -->|Logout Action| Prefs
Home -->|Clear Session & Redirect| Login
AuthRepository encapsulates all HTTP headers, JSON serialization, and Volley RequestQueue dispatches:
class AuthRepository(private val context: Context) {
private val loginUrl = "https://cricdex.enfotrix.com/api/login"
fun loginUser(phone: String, password: String, onSuccess: (String) -> Unit, onError: (String) -> Unit) {
val jsonBody = JSONObject().apply {
put("phone_number", phone)
put("password", password)
}
val jsonObjectRequest = object : JsonObjectRequest(
Method.POST, loginUrl, jsonBody,
Response.Listener { response ->
if (response.optBoolean("success", false)) {
val token = response.optJSONObject("data")?.optString("token", "")
if (!token.isNullOrEmpty()) onSuccess(token)
else onError("Login failed: no token received")
} else {
onError(response.optString("message", "Login Failed!"))
}
},
Response.ErrorListener { error -> onError("Error: ${error.message}") }
) {
override fun getHeaders(): Map<String, String> =
mapOf("Content-Type" to "application/json")
}
Volley.newRequestQueue(context.applicationContext).add(jsonObjectRequest)
}
}Leverages AndroidViewModel and viewModelScope to handle network triggers safely without leaking Activity contexts during device configuration changes:
class AuthViewModel(application: Application) : AndroidViewModel(application) {
private val authRepository = AuthRepository(application)
fun loginUser(phone: String, password: String, onSuccess: (String) -> Unit, onError: (String) -> Unit) {
viewModelScope.launch {
authRepository.loginUser(phone, password, onSuccess, onError)
}
}
}MainActivitySplash inspects local persistence before navigation, ensuring authenticated users skip the login wall automatically.
MainActivityHome incorporates expandable collapsible accordion cards (e.g., iCloud & Outlook containers) and an action overflow popup menu with session termination / log-out capabilities.
MVVM-implementation/
βββ app/
β βββ src/main/java/com/shayan/mvvm_login/
β β βββ model/
β β β βββ ModelUser.kt # Data class representing user credentials
β β βββ repository/
β β β βββ AuthRepository.kt # Remote network datasource & Volley requests
β β βββ view/
β β β βββ MainActivitySplash.kt # Splashscreen with Lottie & session check
β β β βββ MainActivityLogin.kt # Login Activity with input validation
β β β βββ MainActivityRegister.kt # User registration activity
β β β βββ MainActivityHome.kt # Dashboard activity with expandable cards
β β βββ viewmodel/
β β βββ AuthViewModel.kt # ViewModel orchestrating business logic
β βββ src/main/res/
β β βββ layout/ # XML layouts with ViewBinding support
β β βββ menu/ # Toolbar dropdown menu definitions
β β βββ raw/ # Lottie animation JSON file
β β βββ values/ # Colors, styles, and string resources
β βββ build.gradle.kts # App dependencies & Kotlin DSL configuration
βββ gradle/
βββ libs.versions.toml # Centralized version catalog
| Layer / Category | Technology | Purpose / Notes |
|---|---|---|
| Platform | Android (API 24+ to 35) | Min SDK 24, Target SDK 34, Compile SDK 35 |
| Language | Kotlin 2.0+ | Modern Android language |
| Architecture | MVVM + Repository | Clean Architecture separation of concerns |
| Concurrency | Kotlinx Coroutines | viewModelScope & background task execution |
| Networking | Google Volley | Asynchronous HTTP / REST JSON request queue |
| View Binding | AndroidX ViewBinding | Null-safe compile-time view references |
| Animations | Airbnb Lottie Android | High-performance vector animations |
| Local Storage | Android SharedPreferences | Persistent token and session caching |
- Android Studio Ladybug (2024.2.1+) or newer.
- JDK 11 or JDK 17.
- Android SDK 34 / 35.
- Clone the repository:
git clone https://github.com/shayann07/MVVM-implementation.git cd MVVM-implementation - Open in Android Studio: Let Gradle sync the project dependencies.
- Build the project:
./gradlew assembleDebug
- Deploy: Run on an emulator or physical device.
This project is licensed under the MIT License β Copyright (c) 2026 shayann07.