# dheerajkotwani/cinewatch architecture

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

- Interactive diagram: https://gitdiagram.com/dheerajkotwani/cinewatch
- Repository: https://github.com/dheerajkotwani/cinewatch

## Overview

##### Project Type & Purpose
- The project is an Android mobile application built using Kotlin.
- Its main features include browsing movie listings (upcoming, popular, top rated), viewing detailed movie info, cast details, bookmarking favorites, and trailers.
- It uses TMDB APIs for retrieving movie data and implements MVVM along with Dependency Injection, Room for local storage, Retrofit for networking, and Paging 3 for incremental data loading.

##### Analyzing the File Structure
- At the top level, the primary directories are:
- “app”: Contains Android-specific resources, configurations, and the main application code.
- “app/src/main”: Houses the code structured in subfolders representing different layers:
◦ “data”: Divided into “api” (network calls using Retrofit and SafeApiRequest), “local” (using Room and BookmarkDatabase with related DAO), “model” (data models like Movie, Actor, Cast, etc.), and “repository” (NetworkRepository bridging API and local data).
◦ “di”: Contains dependency injection modules (ApiModule, DatabaseModule) using Dagger 2.
◦ “ui”: Organized further into feature-centric packages (home, search, details, main, paging, etc.). Each feature typically has a Fragment/Activity alongside its ViewModel.
◦ “utils”: Utility classes for common tasks (networking, constants, date/time, views, etc.).
- Additional directories for resources, layouts, navigation (nav_graph.xml), and tests are also present, which reinforce the use of modern Android components like Navigation Graph and Paging.

##### Key Components & Their Interactions
- UI Layer:
- Activities/Fragments (e.g., MainActivity, SplashScreenActivity, HomeFragment, MovieDetailsFragment, etc.) form the presentation layer.
- Adapters (e.g., various RecyclerViewAdapters) display lists of movies, casts, etc.
- ViewModels (e.g., HomeViewModel, SearchViewModel, MovieDetailsViewModel, etc.) that manage UI data and lifecycle, observing LiveData.
- Domain / Data Layer:
- Repository (NetworkRepository) acts as a mediator between data sources.
- Data sources include:
▪ Network Service (NetworkService.kt) using Retrofit for remote calls.
▪ Local Database (BookmarkDatabase with BookmarkDao) using Room for caching/bookmarks.
- Data Models (Movie, Actor, etc.) that represent the domain objects.
- Dependency Injection:
- DI modules (ApiModule, DatabaseModule) to bind dependencies via Dagger 2, making sure the right implementations are injected into ViewModels and Repositories.
- External Services & Libraries:
- TMDB API is the external source.
- Other libraries include Dagger 2, Retrofit, Room, Paging 3, Material Components, and Coil (for image loading).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "User Interface Layer"
        MA["MainActivity"]:::ui
        SSA["SplashScreenActivity"]:::ui
        HF["HomeFragment"]:::ui
        MDF["MovieDetailsFragment"]:::ui
        ADF["ActorDetailsFragment"]:::ui
        UIA["Adapters"]:::ui
    end

    %% Presentation Logic Layer
    subgraph "Presentation Logic"
        HVM["HomeViewModel"]:::viewmodel
        MDVM["MovieDetailsViewModel"]:::viewmodel
        SVM["SearchViewModel"]:::viewmodel
        ADVM["ActorDetailsViewModel"]:::viewmodel
        VAVM["ViewAllViewModel"]:::viewmodel
    end

    %% Data Repository Layer
    subgraph "Data Repository"
        NR["NetworkRepository"]:::repository
    end

    %% Data Sources Layer
    subgraph "Data Sources"
        subgraph "Remote API"
            NS["NetworkService"]:::datasource
            SAR["SafeApiRequest"]:::datasource
        end
        subgraph "Local Database"
            BDB["BookmarkDatabase"]:::datasource
            BDAO["BookmarkDao"]:::datasource
        end
    end

    %% Dependency Injection
    subgraph "Dependency Injection"
        API["ApiModule"]:::di
        DBM["DatabaseModule"]:::di
    end

    %% Utility & Helpers
    UT["Utility Classes"]:::utility

    %% External Services
    TMDB["TMDB API"]:::external

    %% Connections from UI to Presentation
    MA -->|"triggers"| HVM
    SSA -->|"triggers"| HVM
    HF -->|"triggers"| HVM
    MDF -->|"triggers"| MDVM
    ADF -->|"triggers"| ADVM
    UIA -->|"renders"| HVM

    %% Connections from Presentation to Repository
    HVM -->|"fetches"| NR
    MDVM -->|"fetches"| NR
    SVM -->|"fetches"| NR
    ADVM -->|"fetches"| NR
    VAVM -->|"fetches"| NR

    %% Connections from Repository to Data Sources
    NR -->|"calls"| NS
    NR -->|"calls"| SAR
    NR -->|"caches to"| BDB
    BDB -->|"handled by"| BDAO

    %% Dependency Injection providing dependencies
    API ---|"provides"| HVM
    API ---|"provides"| MDVM
    API ---|"provides"| SVM
    API ---|"provides"| ADVM
    API ---|"provides"| VAVM
    API ---|"injects"| NR
    DBM ---|"injects"| NR
    DBM ---|"injects"| BDB

    %% Remote API calling external TMDB API
    NS -->|"calls"| TMDB

    %% Utility usage (illustrative arrow)
    UT ---|"assists"| MA
    UT ---|"assists"| HVM

    %% Click Events for UI Layer
    click MA "https://github.com/dheerajkotwani/cinewatch/blob/master/app/src/main/java/project/dheeraj/cinewatch/ui/main/MainActivity.kt"
    click SSA "https://github.com/dheerajkotwani/cinewatch/blob/master/app/src/main/java/project/dheeraj/cinewatch/ui/SplashScreenActivity.kt"
    click HF "https://github.com/dheerajkotwani/cinewatch/blob/master/app/src/main/java/project/dheeraj/cinewatch/ui/home/HomeFragment.kt"
    click MDF "https://github.com/dheerajkotwani/cinewatch/blob/master/app/src/main/java/project/dheeraj/cinewatch/ui/details/MovieDetailsFragment.kt"
    click ADF "https://github.com/dheerajkotwani/cinewatch/blob/master/app/src/main/java/project/dheeraj/cinewatch/ui/details/ActorDetailsFragment.kt"
    click UIA "https://github.com/dheerajkotwani/cinewatch/tree/master/app/src/main/java/project/dheeraj/cinewatch/ui/adapter"

    %% Click Events for Presentation Logic
    click HVM "https://github.com/dheerajkotwani/cinewatch/blob/master/app/src/main/java/project/dheeraj/cinewatch/ui/home/HomeViewModel.kt"
    click MDVM "https://github.com/dheerajkotwani/cinewatch/blob/master/app/src/main/java/project/dheeraj/cinewatch/ui/details/MovieDetailsViewModel.kt"
    click SVM "https://github.com/dheerajkotwani/cinewatch/blob/master/app/src/main/java/project/dheeraj/cinewatch/ui/search/SearchViewModel.kt"
    click ADVM "https://github.com/dheerajkotwani/cinewatch/blob/master/app/src/main/java/project/dheeraj/cinewatch/ui/details/ActorDetailsViewModel.kt"
    click VAVM "https://github.com/dheerajkotwani/cinewatch/blob/master/app/src/main/java/project/dheeraj/cinewatch/ui/list/ViewAllViewModel.kt"

    %% Click Event for Data Repository
    click NR "https://github.com/dheerajkotwani/cinewatch/blob/master/app/src/main/java/project/dheeraj/cinewatch/data/repository/NetworkRepository.kt"

    %% Click Events for Remote API
    click NS "https://github.com/dheerajkotwani/cinewatch/blob/master/app/src/main/java/project/dheeraj/cinewatch/data/api/NetworkService.kt"
    click SAR "https://github.com/dheerajkotwani/cinewatch/blob/master/app/src/main/java/project/dheeraj/cinewatch/data/api/SafeApiRequest.kt"

    %% Click Events for Local Database
    click BDB "https://github.com/dheerajkotwani/cinewatch/blob/master/app/src/main/java/project/dheeraj/cinewatch/data/local/BookmarkDatabase.kt"
    click BDAO "https://github.com/dheerajkotwani/cinewatch/blob/master/app/src/main/java/project/dheeraj/cinewatch/data/local/dao/BookmarkDao.kt"

    %% Click Events for Dependency Injection
    click API "https://github.com/dheerajkotwani/cinewatch/blob/master/app/src/main/java/project/dheeraj/cinewatch/di/module/ApiModule.kt"
    click DBM "https://github.com/dheerajkotwani/cinewatch/blob/master/app/src/main/java/project/dheeraj/cinewatch/di/module/DatabaseModule.kt"

    %% Click Event for Utility Classes
    click UT "https://github.com/dheerajkotwani/cinewatch/tree/master/app/src/main/java/project/dheeraj/cinewatch/utils"

    %% Styles
    classDef ui fill:#FFEB3B,stroke:#000,stroke-width:2px;
    classDef viewmodel fill:#8BC34A,stroke:#000,stroke-width:2px;
    classDef repository fill:#03A9F4,stroke:#000,stroke-width:2px;
    classDef datasource fill:#E91E63,stroke:#000,stroke-width:2px;
    classDef di fill:#9C27B0,stroke:#000,stroke-width:2px;
    classDef utility fill:#009688,stroke:#000,stroke-width:2px;
    classDef external fill:#FF7043,stroke:#000,stroke-width:2px;
```
