How brianleiser/desafio-android works
Project Type and Purpose
• This is a native Android mobile application (“PicPay - Desafio Android”) whose main function is to fetch and display a list of users from a backend service.
• The README describes an architecture-improvement challenge: maintain UI state on configuration changes, enforce null-safety, add caching, support evolving business/presentation logic, and enable both unit and instrumented testing.
File Structure
• Top-level files: Gradle scripts, settings, wrapper—standard Android/Gradle project.
• app/src/main/java/com/picpay/desafio/android: houses the UI (MainActivity.kt), service interface (PicPayService.kt), data model (User.kt), and RecyclerView adapter classes.
• Test directories:
• app/src/test/java/.../ExampleServiceTest.kt for local unit tests.
• app/src/androidTest/java/.../MainActivityTest.kt for instrumented UI tests.
• No explicit layers for domain or data cache present—this is an opportunity to introduce Repository/Use-Case/Local-Data patterns.
Key Insights from the README
• Requirements call for:
• Preservation of screen state across rotations (ViewModel + LiveData/StateFlow)
• Null-safety (strict Kotlin types, proper initialization)
• Caching (in-memory and/or persistent—Room or DataStore)
• Separation of concerns to accommodate business/presentation changes
• Fast unit tests for presentation/business/data logic, plus faithful instrumented tests
Main Components
a. Presentation Layer
• MainActivity (Android Activity)
• RecyclerView + UserListAdapter & ViewHolder
• ViewModel (new component to add) exposing LiveData/StateFlow of UI state
b. Domain Layer (optional but recommended)
• UseCase/Interactor for “FetchUsers” business logic
c. Data Layer
• Repository interface (e.g., UserRepository)
• RemoteDataSource: PicPayService (Retrofit/OkHttp)
• LocalDataSource: in-memory/LRU cache or Room database
d. External Services
• PicPay REST API (HTTPS backend)
e. Test Modules
• Unit Tests exercising ViewModel, UseCase, Repository in isolation
• Instrumented Tests driving MainActivity and RecyclerView
Relationships and Data Flow
• UI triggers ViewModel events (e.g., “refresh”) → ViewModel invokes UseCase → UseCase calls Repository
• Repository:
• Check LocalDataSource for cached data → if stale/empty, call RemoteDataSource → store results in LocalDataSource → return data
• ViewModel observes Repository results → emits UI state to Activity → Activity renders list via Adapter
• Lifecycle boundaries: ViewModel survives configuration, Activity does not
Architectural Patterns and Principles
• MVVM (Model-View-ViewModel)
• Repository pattern with Data Sources
• Single-Source-of-Truth for user data
• Clean separation: Presentation ↔ Domain ↔ Data
• Dependency Injection (e.g., Hilt or Dagger) to wire Retrofit, Repository, ViewModel
• Null-safety enforced via Kotlin types and architecture components