# coderprem/phone architecture

> Architecture diagram of the GitHub repository coderprem/phone, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-31). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/coderprem/phone
- Repository: https://github.com/coderprem/phone

## Overview

##### Main Components
- User Interface Layer:
- Activities (e.g., MainActivity, CreateContactActivity, SearchBarActivity) and Fragments (e.g., ContactsFragment, FavouriteFragment, RecentFragment, BottomSheet).
- Data Presentation and Business Logic Layer:
- Adapters (CallLogAdapter, ContactAdapter, FavoritesAdapter, etc.) for populating UI lists and handling user input.
- ViewModel classes (ContactViewModel, along with ViewModelFactory) that encapsulate UI state and interact with the repository.
- Data Management Layer:
- Repository (ContactRepository) which serves as an abstraction between the UI layer and the data sources.
- Local Database:
- Database files (ContactDatabase), Data Access Objects (ContactsDao), and entities (ContactEntity) that persist application data.
- Utility and Helper Functions:
- Utility classes (such as CallLogUtil) that provide common functionality.
- Testing:
- Unit tests and instrumentation tests in the test directories that validate app behavior.

##### Relationships and Interactions
- The UI layer (activities and fragments) communicates user events to the ViewModels.
- ViewModels then interact with the Repository to request or update data.
- The Repository abstracts the access to the local Room database (using DAOs) or any additional data sources.
- Data flows back from the database through the repository and then through the ViewModel, which updates the UI.
- Adapters serve as the bridge between raw data (from models or view models) and the UI components like RecyclerViews.
- Utility classes are leveraged wherever common processing (such as formatting call logs) is needed.

##### Important Architectural Patterns and Design Principles
- Adoption of the MVVM (Model-View-ViewModel) pattern:
- View (Activities/Fragments) ⇔ ViewModel (ContactViewModel) ⇔ Repository (ContactRepository) ⇔ Model/Data (Room database, entities, DAOs).
- Separation of concerns:
- Dividing responsibilities across layers (UI, business logic, data storage) ensures easier maintenance and testing.
- Proper management of dependencies (evidenced by the use of a ViewModelFactory and repository abstraction).

##### Specify Technologies and Frameworks
- Android SDK (Activities, Fragments, Resources, etc.)
- Kotlin (language of implementation)
- Android Architecture Components (ViewModel, LiveData, possibly Room for local database)
- Gradle for build and dependency management (as seen by the build.gradle.kts and gradle configuration files)

##### Additional Suggested Elements
- Environmental and build components:
- Gradle build system and its role in compiling and deploying the app.
- Incorporate testing pathways:
- That both unit tests and instrumentation tests exist and are used to ensure app stability.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interface Layer
    subgraph "User Interface Layer"
        %% Activities
        subgraph "Activities"
            MA["MainActivity\n(Entry point for user interactions)"]
            CCA["CreateContactActivity\n(Handles contact creation)"]
            SBA["SearchBarActivity\n(Provides contact search)"]
        end
        %% Fragments
        subgraph "Fragments"
            CF["ContactsFragment\n(Displays contact list)"]
            FF["FavouriteFragment\n(Shows favorite contacts)"]
            RF["RecentFragment\n(Displays recent call logs)"]
            BS["BottomSheet\n(Adds contextual actions)"]
        end
        %% Adapters
        subgraph "Adapters"
            CLA["CallLogAdapter\n(Populates call log lists)"]
            CTA["ContactAdapter\n(Binds contact data)"]
            FA["FavoritesAdapter\n(Handles favorite contacts)"]
            STC["SwipeToCallCallback\n(Enables swipe-to-call gesture)"]
        end
    end

    %% Business Logic Layer
    subgraph "Business Logic Layer"
        CVM["ContactViewModel\n(Manages UI state and data)"]
        VMF["ViewModelFactory\n(Creates view model instances)"]
    end

    %% Data Management Layer
    subgraph "Data Management Layer"
        CR["ContactRepository\n(Abstraction over data sources)"]
        subgraph "Local Database"
            CD["ContactDatabase\n(Persistent storage)"]
            CDAO["ContactsDao\n(Data access object)"]
            CE["ContactEntity\n(Data model)"]
        end
    end

    %% Utility & Testing Layer
    subgraph "Utility & Testing"
        CLU["CallLogUtil\n(Provides call log formatting)"]
        Tests["Tests\n(Unit and instrumentation tests)"]
    end

    %% Build System
    GS["Gradle Build System\n(Compiles and builds the app)"]

    %% Connections from UI to Business Logic
    MA -->|"triggers"| CVM
    CCA -->|"triggers"| CVM
    SBA -->|"triggers"| CVM
    CF -->|"displays"| CVM
    FF -->|"displays"| CVM
    RF -->|"displays"| CVM
    BS -->|"displays"| CVM
    CVM -->|"provides data to"| CTA

    %% Connection from Adapters to Utility
    CLA -->|"utilizes"| CLU

    %% Business Logic to Data Management
    VMF -->|"creates"| CVM
    CVM -->|"requests data from"| CR

    %% Data Management internal flow
    CR -->|"accesses"| CDAO
    CDAO -->|"queries"| CD
    CD -->|"stores/retrieves"| CE

    %% Testing connections (validation of core layers)
    Tests --- CVM
    Tests --- CR
    Tests --- CD

    %% Gradle Build System builds core components
    GS --> MA
    GS --> CVM
    GS --> CR

    %% Class definitions for styling
    classDef ui fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef view fill:#A9DFBF,stroke:#196F3D,stroke-width:2px;
    classDef data fill:#F9E79F,stroke:#B9770E,stroke-width:2px;
    classDef adapter fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef util fill:#D7BDE2,stroke:#6C3483,stroke-width:2px;
    classDef test fill:#D5F5E3,stroke:#28B463,stroke-width:2px;
    classDef build fill:#FAD7A0,stroke:#D35400,stroke-width:2px;

    %% Assign classes
    class MA,CCA,SBA,CF,FF,RF,BS ui;
    class CLA,CTA,FA,STC adapter;
    class CVM,VMF view;
    class CR,CD,CDAO,CE data;
    class CLU util;
    class Tests test;
    class GS build;

    %% Click Events for Component Mapping
    click MA "https://github.com/coderprem/phone/blob/main/app/src/main/java/com/example/phone/MainActivity.kt"
    click CCA "https://github.com/coderprem/phone/blob/main/app/src/main/java/com/example/phone/CreateContactActivity.kt"
    click SBA "https://github.com/coderprem/phone/blob/main/app/src/main/java/com/example/phone/SearchBarActivity.kt"
    click CF "https://github.com/coderprem/phone/blob/main/app/src/main/java/com/example/phone/fragments/ContactsFragment.kt"
    click FF "https://github.com/coderprem/phone/blob/main/app/src/main/java/com/example/phone/fragments/FavouriteFragment.kt"
    click RF "https://github.com/coderprem/phone/blob/main/app/src/main/java/com/example/phone/fragments/RecentFragment.kt"
    click BS "https://github.com/coderprem/phone/blob/main/app/src/main/java/com/example/phone/fragments/BottomSheet.kt"
    click CLA "https://github.com/coderprem/phone/blob/main/app/src/main/java/com/example/phone/adapters/CallLogAdapter.kt"
    click CTA "https://github.com/coderprem/phone/blob/main/app/src/main/java/com/example/phone/adapters/ContactAdapter.kt"
    click FA "https://github.com/coderprem/phone/blob/main/app/src/main/java/com/example/phone/adapters/FavoritesAdapter.kt"
    click STC "https://github.com/coderprem/phone/blob/main/app/src/main/java/com/example/phone/adapters/SwipeToCallCallback.kt"
    click CVM "https://github.com/coderprem/phone/blob/main/app/src/main/java/com/example/phone/db/viewmodel/ContactViewModel.kt"
    click VMF "https://github.com/coderprem/phone/blob/main/app/src/main/java/com/example/phone/db/viewmodel/ViewModelFactory.kt"
    click CR "https://github.com/coderprem/phone/blob/main/app/src/main/java/com/example/phone/repository/ContactRepository.kt"
    click CD "https://github.com/coderprem/phone/blob/main/app/src/main/java/com/example/phone/db/ContactDatabase.kt"
    click CDAO "https://github.com/coderprem/phone/blob/main/app/src/main/java/com/example/phone/db/ContactsDao.kt"
    click CE "https://github.com/coderprem/phone/blob/main/app/src/main/java/com/example/phone/db/ContactEntity.kt"
    click CLU "https://github.com/coderprem/phone/blob/main/app/src/main/java/com/example/phone/utils/CallLogUtil.kt"
```
