How ferhatozcelik/android-mvvm-template works
Main Architectural Layers and Components
• User Interface (View): Represented by activities (e.g., MainActivity), fragments (e.g., HomeFragment, DetailFragment), adapters (e.g., ListAdapter), and layout resources. This layer is responsible for user interaction and displaying data.
• ViewModel: Acts as the intermediary between the UI and the Model. In this project, you have ViewModel classes for different fragments (e.g., HomeViewModel, DetailViewModel). They handle business logic and data binding to the UI.
• Domain/Model: This is split into two primary aspects:
– Domain layer: Contains business logic and repository interfaces (e.g., ExampleRepository interface in the domain/repository folder).
– Data layer: Handles concrete implementations such as data access objects (e.g., ExampleDao), entity definitions (ExampleEntity), API service interfaces (AppService), and Room database components (AppDatabase, Converters).
• Dependency Injection (DI): Managed using Hilt / Dagger. There are several modules (e.g., ApiModule, AppModule, DatabaseModule, PreferencesModule) to facilitate the injection of dependencies across components.
• External and Utility Services: This includes networking (Retrofit integration via AppService), shared preferences (PreferenceManager, Preferences), and utility classes for constants or extensions.
Relationships and Data Flow
• User interactions in the UI (Activities/Fragments) trigger events that are processed by the respective ViewModels.
• ViewModels communicate with repositories (defined in both the domain and data layers) to fetch or update data.
• The repositories then decide whether to retrieve data from local persistence (Room database) or request data via network calls (Retrofit through AppService).
• The DI modules ensure that the proper instances (such as the repository implementations, database, network clients, etc.) are provided to the components that require them.
• Utility and extension functions support these primary interactions by encapsulating common behaviors across the app.
• Component (e.g., MainActivity, HomeFragment, HomeViewModel, ExampleRepositoryImp, AppDatabase, Retrofit-based AppService, DI Modules) appears as a node.