# ferhatozcelik/android-mvvm-template architecture

> Architecture diagram of the GitHub repository ferhatozcelik/android-mvvm-template, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ferhatozcelik/android-mvvm-template
- Repository: https://github.com/ferhatozcelik/android-mvvm-template

## Overview

##### 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.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer"
        UI_Dir["UI Directory"]
        MainActivity["Main Activity"]
        HomeFragment["Home Fragment"]
        DetailFragment["Detail Fragment"]
        ListAdapter["List Adapter"]
    end

    %% ViewModel Layer
    subgraph "ViewModel Layer"
        HomeViewModel["Home ViewModel"]
        DetailViewModel["Detail ViewModel"]
    end

    %% Domain Layer
    subgraph "Domain Layer"
        ExampleRepository["Example Repository (Interface)"]
        SessionManager["Session Manager"]
        SessionManagerImp["Session Manager Implementation"]
    end

    %% Data Layer
    subgraph "Data Layer"
        ExampleDao["Example DAO"]
        ExampleEntity["Example Entity"]
        AppDatabase["App Database"]
        Converters["Converters"]
        ExampleRepositoryImp["Repository Implementation"]
        AppService["API Service"]
    end

    %% DI Modules
    subgraph "DI Modules"
        ApiModule["API Module"]
        AppModule["App Module"]
        DatabaseModule["Database Module"]
        PreferencesModule["Preferences Module"]
    end

    %% External & Utility
    subgraph "External & Utility"
        NetworkUtil["Network Utility"]
        SharedPrefs["Shared Preferences & Constants"]
        Extensions["Extensions & Utilities"]
    end

    %% UI Layer to ViewModel Layer
    HomeFragment -->|"bindsTo"| HomeViewModel
    DetailFragment -->|"bindsTo"| DetailViewModel

    %% ViewModel Layer to Data/Domain Layer
    HomeViewModel -->|"calls"| ExampleRepositoryImp
    DetailViewModel -->|"calls"| ExampleRepositoryImp

    %% Repository Implementation relationships
    ExampleRepositoryImp -->|"fetchesFrom"| AppService
    ExampleRepositoryImp -->|"fetchesFrom"| ExampleDao
    ExampleDao -->|"accesses"| AppDatabase

    %% Domain implementation link
    ExampleRepositoryImp -.->|"implements"| ExampleRepository
    ExampleRepositoryImp -->|"uses"| SessionManagerImp
    SessionManagerImp -.->|"implements"| SessionManager

    %% DI Modules providing dependencies
    ApiModule -->|"provides"| AppService
    DatabaseModule -->|"provides"| AppDatabase
    AppModule -->|"provides"| ExampleRepositoryImp
    PreferencesModule -->|"provides"| SharedPrefs

    %% External utilities integration
    NetworkUtil -->|"assists"| AppService
    SharedPrefs -->|"usedBy"| SessionManager

    %% Styling
    class UI_Dir,MainActivity,HomeFragment,DetailFragment,ListAdapter ui
    class HomeViewModel,DetailViewModel business
    class ExampleRepository,SessionManager,SessionManagerImp business
    class ExampleDao,ExampleEntity,AppDatabase,Converters,ExampleRepositoryImp,AppService business
    class ApiModule,AppModule,DatabaseModule,PreferencesModule di
    class NetworkUtil,SharedPrefs,Extensions external

    %% Classes definitions
    classDef ui fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef business fill:#A9DFBF,stroke:#1E8449,stroke-width:2px;
    classDef di fill:#F9E79F,stroke:#F1C40F,stroke-width:2px,stroke-dasharray: 5,5;
    classDef external fill:#F5B7B1,stroke:#E74C3C,stroke-width:2px;

    %% Click Events for UI Layer
    click UI_Dir "https://github.com/ferhatozcelik/android-mvvm-template/tree/master/app/src/main/java/com/ferhatozcelik/androidmvvmtemplate/ui"
    click MainActivity "https://github.com/ferhatozcelik/android-mvvm-template/blob/master/app/src/main/java/com/ferhatozcelik/androidmvvmtemplate/ui/activitys/MainActivity.kt"
    click HomeFragment "https://github.com/ferhatozcelik/android-mvvm-template/blob/master/app/src/main/java/com/ferhatozcelik/androidmvvmtemplate/ui/fragments/home/HomeFragment.kt"
    click DetailFragment "https://github.com/ferhatozcelik/android-mvvm-template/blob/master/app/src/main/java/com/ferhatozcelik/androidmvvmtemplate/ui/fragments/detail/DetailFragment.kt"
    click ListAdapter "https://github.com/ferhatozcelik/android-mvvm-template/blob/master/app/src/main/java/com/ferhatozcelik/androidmvvmtemplate/ui/adapters/ListAdapter.kt"

    %% Click Events for ViewModel
    click HomeViewModel "https://github.com/ferhatozcelik/android-mvvm-template/blob/master/app/src/main/java/com/ferhatozcelik/androidmvvmtemplate/ui/fragments/home/HomeViewModel.kt"
    click DetailViewModel "https://github.com/ferhatozcelik/android-mvvm-template/blob/master/app/src/main/java/com/ferhatozcelik/androidmvvmtemplate/ui/fragments/detail/DetailViewModel.kt"

    %% Click Events for Domain Layer
    click ExampleRepository "https://github.com/ferhatozcelik/android-mvvm-template/blob/master/app/src/main/java/com/ferhatozcelik/androidmvvmtemplate/domain/repository/ExampleRepository.kt"
    click SessionManager "https://github.com/ferhatozcelik/android-mvvm-template/blob/master/app/src/main/java/com/ferhatozcelik/androidmvvmtemplate/common/domain/session/SessionManager.kt"
    click SessionManagerImp "https://github.com/ferhatozcelik/android-mvvm-template/blob/master/app/src/main/java/com/ferhatozcelik/androidmvvmtemplate/common/domain/session/SessionManagerImp.kt"

    %% Click Events for Data Layer
    click ExampleDao "https://github.com/ferhatozcelik/android-mvvm-template/blob/master/app/src/main/java/com/ferhatozcelik/androidmvvmtemplate/data/dao/ExampleDao.kt"
    click ExampleEntity "https://github.com/ferhatozcelik/android-mvvm-template/blob/master/app/src/main/java/com/ferhatozcelik/androidmvvmtemplate/data/entity/ExampleEntity.kt"
    click AppDatabase "https://github.com/ferhatozcelik/android-mvvm-template/blob/master/app/src/main/java/com/ferhatozcelik/androidmvvmtemplate/data/local/AppDatabase.kt"
    click Converters "https://github.com/ferhatozcelik/android-mvvm-template/blob/master/app/src/main/java/com/ferhatozcelik/androidmvvmtemplate/data/local/Converters.kt"
    click ExampleRepositoryImp "https://github.com/ferhatozcelik/android-mvvm-template/blob/master/app/src/main/java/com/ferhatozcelik/androidmvvmtemplate/data/repository/ExampleRepositoryImp.kt"
    click AppService "https://github.com/ferhatozcelik/android-mvvm-template/blob/master/app/src/main/java/com/ferhatozcelik/androidmvvmtemplate/data/services/AppService.kt"

    %% Click Events for DI Modules
    click ApiModule "https://github.com/ferhatozcelik/android-mvvm-template/blob/master/app/src/main/java/com/ferhatozcelik/androidmvvmtemplate/di/ApiModule.kt"
    click AppModule "https://github.com/ferhatozcelik/android-mvvm-template/blob/master/app/src/main/java/com/ferhatozcelik/androidmvvmtemplate/di/AppModule.kt"
    click DatabaseModule "https://github.com/ferhatozcelik/android-mvvm-template/blob/master/app/src/main/java/com/ferhatozcelik/androidmvvmtemplate/di/DatabaseModule.kt"
    click PreferencesModule "https://github.com/ferhatozcelik/android-mvvm-template/blob/master/app/src/main/java/com/ferhatozcelik/androidmvvmtemplate/di/PreferencesModule.kt"

    %% Click Events for External & Utility
    click NetworkUtil "https://github.com/ferhatozcelik/android-mvvm-template/blob/master/app/src/main/java/com/ferhatozcelik/androidmvvmtemplate/util/NetworkUtil.kt"
    click SharedPrefs "https://github.com/ferhatozcelik/android-mvvm-template/tree/master/app/src/main/java/com/ferhatozcelik/androidmvvmtemplate/common/data/preferences"
    click Extensions "https://github.com/ferhatozcelik/android-mvvm-template/tree/master/app/src/main/java/com/ferhatozcelik/androidmvvmtemplate/common/extensions"
```
