# anilibapp/anilib architecture

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

- Interactive diagram: https://gitdiagram.com/anilibapp/anilib
- Repository: https://github.com/anilibapp/anilib

## Overview

##### Project Type and Purpose
- This is a full‑stack Android client app (written in Kotlin + Jetpack Compose) for the AniList GraphQL API.
- Its purpose is to let users track anime/manga, browse details, manage lists, view notifications, and host widgets—all from a mobile interface.

##### High‑Level File Structure Analysis
- Top‑level “app” module: contains all Android code (UI screens, viewmodels, data services, sources, stores, workers, widgets).
- “i18n” submodule: hosts multi‑language resource strings.
- “buildSrc”: centralizes Gradle dependencies and build helper extensions.
- GraphQL schema & queries under app/src/main/graphql: drives code‑gen of Apollo models & services.
- Standard Android config: manifests, resources, flavors (debug, release, standard), ProGuard rules.
- WorkManager and Widget code under app/src/main/kotlin/.../worker and widget.

##### Key Architectural Insights from README
- Uses Apollo GraphQL client under the hood for all network calls.
- Employs MVVM: Compose UI screens ← ViewModels ← Services/Repositories ← Apollo.
- Local storage via DataStore (for preferences & filters).
- Background workers for notifications and widget updates.

##### Main Components to Capture
a. UI Layer
- Jetpack Compose screens & components (e.g., BrowseScreen, MediaScreen, etc.)
- Widgets (AiringScheduleWidgetReceiver → AiringScheduleWidget)
b. ViewModel Layer
- Feature‑specific ViewModels (e.g., BrowseViewModel, MediaViewModel)
- SharedActivityViewModel, BaseViewModel
c. Domain/Service Layer
- Service interfaces & implementations (e.g., MediaServiceImpl)
- Repository modules (ApolloRepositoryImpl)
d. Data Layer
- Apollo GraphQL client
- DataStore stores & serializers (e.g., MediaFilterDataStore)
- PagingSources for network data pagination
e. External Services
- AniList GraphQL API (cloud)
- Google Play services (for push notifications, analytics)
f. Background Workers
- NotificationWorker
- AiringScheduleWidgetWorker
g. Localization Module
- i18n strings resource module

##### Relationships & Data Flows
- UI → ViewModel: user actions, screen state updates.
- ViewModel → Service/Repository: function calls to fetch data.
- Service → Apollo Client: GraphQL query/mutation over HTTP.
- Apollo → Service: parsed Kotlin models.
- Service → ViewModel → UI: exposed state flows/LiveData.
- ViewModel → DataStore: read/write filter & preference settings.
- Workers → Services: periodic refresh of notifications/widgets.
- Workers → App: send notifications via OS and update widget UI.

##### Architectural Patterns & Design Principles
- MVVM (separation of UI, state, business logic).
- Layered architecture (UI, ViewModel, Domain, Data).
- Dependency Injection via Modules (RepositoryModule, ServiceModule, WorkerModules).
- Single source of truth for network via Apollo.
- Feature‑based packaging (airing, browse, character, etc.).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "UI Layer" 
        direction TB
        BrowseScreen["BrowseScreen"]:::ui
        MediaScreen["MediaScreen"]:::ui
        AiringScheduleWidgetReceiver["AiringScheduleWidgetReceiver"]:::ui
        AiringScheduleWidget["AiringScheduleWidget"]:::ui
    end

    %% ViewModel Layer
    subgraph "ViewModel Layer"
        direction TB
        BrowseViewModel["BrowseViewModel"]:::vm
        MediaViewModel["MediaViewModel"]:::vm
        SharedActivityViewModel["SharedActivityViewModel"]:::vm
        BaseViewModel["BaseViewModel"]:::vm
    end

    %% Service Layer
    subgraph "Domain / Service Layer"
        direction TB
        MediaServiceImpl["MediaServiceImpl"]:::service
        ApolloRepositoryImpl["ApolloRepositoryImpl"]:::service
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        ApolloClient["Apollo GraphQL Client"]:::data
        GraphqlSchema["GraphQL Schema & Queries"]:::data
        MediaFilterDataStore["MediaFilterDataStore"]:::data
        MediaPagingSource["MediaPagingSource"]:::data
    end

    %% External Services
    subgraph "External Services"
        direction TB
        AniListAPI["AniList GraphQL API"]:::external
        PlayServices["Google Play Services"]:::external
    end

    %% Workers & Widgets
    subgraph "Workers & Widgets"
        direction TB
        NotificationWorker["NotificationWorker"]:::worker
        AiringScheduleWidgetWorker["AiringScheduleWidgetWorker"]:::worker
    end

    %% UI to VM flows
    BrowseScreen -->|"userAction()"| BrowseViewModel
    MediaScreen -->|"userAction()"| MediaViewModel
    AiringScheduleWidgetReceiver -->|"onReceive()"| SharedActivityViewModel
    AiringScheduleWidget -->|"onTap()"| SharedActivityViewModel

    %% VM dependencies
    BrowseViewModel -->|"fetchBrowse()"| ApolloRepositoryImpl
    MediaViewModel -->|"fetchMedia()"| MediaServiceImpl
    SharedActivityViewModel -->|"-"| BaseViewModel

    %% Service to Data
    MediaServiceImpl -->|"queryMedia()"| ApolloClient
    ApolloRepositoryImpl -->|"graphqlCall()"| ApolloClient
    ApolloClient -->|"execute HTTP" | AniListAPI
    ApolloClient -->|"mapResponse()"| MediaServiceImpl
    MediaServiceImpl -->|"returnModels()"| MediaViewModel

    %% VM to DataStore
    MediaViewModel -->|"readFilter()"| MediaFilterDataStore
    MediaViewModel -->|"writeFilter()"| MediaFilterDataStore

    %% PagingSource
    MediaViewModel -->|"paginate()"| MediaPagingSource
    MediaPagingSource -->|"loadPage()"| ApolloClient

    %% Workers to Services
    NotificationWorker -->|"refreshNotifications()"| ApolloRepositoryImpl
    AiringScheduleWidgetWorker -->|"fetchAiringSchedule()"| MediaServiceImpl

    %% Workers to UI (OS)
    NotificationWorker -->|"sendNotification()"| PlayServices
    AiringScheduleWidgetWorker -->|"updateWidget()"| AiringScheduleWidget

    %% Localization Module
    i18n["i18n Resource Strings"]:::data

    %% Click Events
    click BrowseScreen "https://github.com/anilibapp/anilib/blob/master/app/src/main/kotlin/com/revolgenx/anilib/browse/ui/screen/BrowseScreen.kt"
    click MediaScreen "https://github.com/anilibapp/anilib/blob/master/app/src/main/kotlin/com/revolgenx/anilib/media/ui/screen/MediaScreen.kt"
    click AiringScheduleWidgetReceiver "https://github.com/anilibapp/anilib/blob/master/app/src/main/kotlin/com/revolgenx/anilib/widget/ui/AiringScheduleWidgetReceiver.kt"
    click AiringScheduleWidget "https://github.com/anilibapp/anilib/blob/master/app/src/main/kotlin/com/revolgenx/anilib/widget/ui/AiringScheduleWidget.kt"
    click BrowseViewModel "https://github.com/anilibapp/anilib/blob/master/app/src/main/kotlin/com/revolgenx/anilib/browse/ui/viewmodel/BrowseViewModel.kt"
    click MediaViewModel "https://github.com/anilibapp/anilib/blob/master/app/src/main/kotlin/com/revolgenx/anilib/media/ui/viewmodel/MediaViewModel.kt"
    click SharedActivityViewModel "https://github.com/anilibapp/anilib/blob/master/app/src/main/kotlin/com/revolgenx/anilib/app/ui/viewmodel/SharedActivityViewModel.kt"
    click BaseViewModel "https://github.com/anilibapp/anilib/blob/master/app/src/main/kotlin/com/revolgenx/anilib/common/ui/viewmodel/BaseViewModel.kt"
    click MediaServiceImpl "https://github.com/anilibapp/anilib/blob/master/app/src/main/kotlin/com/revolgenx/anilib/media/data/service/MediaServiceImpl.kt"
    click ApolloRepositoryImpl "https://github.com/anilibapp/anilib/blob/master/app/src/main/kotlin/com/revolgenx/anilib/common/data/repository/ApolloRepositoryImpl.kt"
    click GraphqlSchema "https://github.com/anilibapp/anilib/blob/master/app/src/main/graphql/com/revolgenx/anilib/*.graphql"
    click MediaFilterDataStore "https://github.com/anilibapp/anilib/blob/master/app/src/main/kotlin/com/revolgenx/anilib/media/data/store/MediaFilterData.kt"
    click MediaFilterDataStore "https://github.com/anilibapp/anilib/blob/master/app/src/main/kotlin/com/revolgenx/anilib/media/data/store/MediaFilterDataSerializer.kt"
    click MediaPagingSource "https://github.com/anilibapp/anilib/blob/master/app/src/main/kotlin/com/revolgenx/anilib/media/data/source/MediaPagingSource.kt"
    click NotificationWorker "https://github.com/anilibapp/anilib/blob/master/app/src/main/kotlin/com/revolgenx/anilib/notification/data/worker/NotificationWorker.kt"
    click AiringScheduleWidgetWorker "https://github.com/anilibapp/anilib/blob/master/app/src/main/kotlin/com/revolgenx/anilib/widget/data/worker/AiringScheduleWidgetWorker.kt"
    click i18n "https://github.com/anilibapp/anilib/blob/master/i18n/src/main/res/values/strings.xml"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0366D6,color:#0366D6
    classDef vm fill:#E0F8E0,stroke:#2E8B57,color:#2E8B57
    classDef service fill:#E0F8E0,stroke:#228B22,color:#006400
    classDef data fill:#FFE5B4,stroke:#FF8C00,color:#A0522D
    classDef worker fill:#F0F0F0,stroke:#A9A9A9,color:#696969
    classDef external fill:#E6E6FA,stroke:#9370DB,color:#4B0082
```
