# mr-1504/bookmoth-literarysocialnetwork architecture

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

- Interactive diagram: https://gitdiagram.com/mr-1504/bookmoth-literarysocialnetwork
- Repository: https://github.com/mr-1504/bookmoth-literarysocialnetwork

## Overview

##### Your top-level components
- Mobile Application (Android): This is the container for the whole system. It contains the presentation/UI, domain/business logic, and data layers.
- UI Layer: Represented by the “ui” package, including activities (e.g., HomeActivity, LoginActivity, various registration and profile activities), fragments, dialogs, and adapters. This is where user interaction happens.
- ViewModels: Within the “ui/viewmodel” package, these act as the bridge between the UI and the domain logic (e.g., LoginViewModel, PostViewModel, WalletViewModel).
- Domain Layer: Located in “domain” (packages for models, repositories, and use cases). This layer holds business rules and use cases such as login, post creation, profile management, and wallet operations.
- Data Layer: Broken down into “data” with local and remote packages.
- Local Data: Contains SQLite helpers, DAO classes, caching (e.g., ProfileDao, PostSQLiteHelper, ImageCache, DatabaseManager).
- Remote Data: API services and network modules (e.g., LoginApiService, ProfileApiService, RetrofitClient, AuthInterceptor, and other utilities). It also shows use of external libraries (e.g., Retrofit, OkHttp interceptors, Firebase messaging service).
- External Services & Libraries: Include Firebase (evident from MyFirebaseMessagingService), Google services (google-services.json), and third-party libraries stored in the “libs” directory (such as Apache HTTP components, RxJava, and slf4j). Also include native integration through a C++ file (api_key.cpp).

##### Relationships and Data Flow
- The ViewModels then call the corresponding Use Cases in the Domain Layer.
- The Domain Layer operations use repository interfaces which are implemented in the Data Layer.
- Remote API calls (via RetrofitClient and API services).
- Local storage operations (via SQLite helpers, file-based caching).
- Integrations with external services such as Firebase for notifications.
- That network interactions encapsulated by interceptors (e.g., ApiKeyInterceptor, AuthInterceptor) are connected to the remote API services.

##### Architectural Patterns and Design Principles
- Clean Architecture separation: UI, Domain, and Data layers.
- Use of the Repository pattern (with repository implementations for login, register, profile, wallet, etc.).
- Use of the MVVM (Model–View–ViewModel) pattern in the presentation layer.
- That the domain layer focuses exclusively on business logic and use cases, keeping it free from infrastructure details.

##### Key Technologies and Frameworks to Note
- Android framework and Android SDK for the mobile application.
- Retrofit for networking, along with various interceptors.
- Firebase Messaging for real-time notifications.
- SQLite for local data storage.
- Clean Architecture / MVVM as the guiding software pattern.
- Native C++ integration where required (as per the api_key.cpp file).

##### Final Steps
- Drill into each layer (UI, Domain, Data) with clear separation of responsibilities.
- Component is very clearly labeled and connected. For instance, show how the “LoginRepositoryImpl” in the data layer aligns with the “LoginUseCase” in the domain and ultimately with “LoginViewModel” in the UI layer.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Mobile Application Container
    A["Mobile Application"]:::app

    %% UI Layer Subgraph
    subgraph "UI Layer (Activities, Fragments, Adapters)"
        A1["Activities"]:::ui
        A2["Fragments/Dialogs"]:::ui
        A3["Adapters"]:::ui
    end

    %% ViewModels Subgraph
    subgraph "ViewModels (MVVM)"
        B1["LoginViewModel"]:::viewmodel
        B2["PostViewModel"]:::viewmodel
        B3["WalletViewModel"]:::viewmodel
    end

    %% Domain Layer Subgraph
    subgraph "Domain Layer (Business Logic)"
        C1["Models"]:::domain
        C2["RepositoryInterfaces"]:::domain
        C3["UseCases"]:::domain
    end

    %% Data Layer Subgraph
    subgraph "Data Layer"
        %% Local Data Subgraph
        subgraph "Local Data"
            D1["PostSQLiteHelper"]:::data
            D2["ProfileDao"]:::data
            D3["DatabaseManager"]:::data
            D4["ImageCache"]:::data
        end
        %% Remote Data Subgraph
        subgraph "Remote Data"
            D5["LoginApiService"]:::data
            D6["ProfileApiService"]:::data
            D7["NotificationApiService"]:::data
            D8["WalletApiService"]:::data
            D9["APIUtils"]:::data
        end
    end

    %% Repository Implementations Subgraph
    subgraph "Repository Implementations"
        E1["LoginRepositoryImpl"]:::repository
        E2["PostRepositoryImpl"]:::repository
        E3["ProfileRepositoryImpl"]:::repository
        E4["RegisterRepositoryImpl"]:::repository
        E5["WalletRepositoryImpl"]:::repository
    end

    %% External Services & Libraries Subgraph
    subgraph "External Services & Libraries"
        F1["FirebaseMessaging"]:::external
        F2["NativeC++Integration"]:::external
        F3["ExternalLibraries"]:::external
    end

    %% Connections - Data Flow
    A -->|"contains"| A1
    A --> A2
    A --> A3

    A1 -->|"triggers"| B1
    A2 -->|"triggers"| B2
    A3 -->|"triggers"| B3

    %% ViewModel to Domain interaction
    B1 -->|"calls"| C3
    B2 --> C3
    B3 --> C3

    %% Domain Use Cases to Repository Interfaces
    C3 -->|"uses"| C2

    %% Repository Interfaces to Repository Implementations
    C2 -->|"implemented by"| E1
    C2 --> E2
    C2 --> E3
    C2 --> E4
    C2 --> E5

    %% Repository Implementations to Data Layer - both Local and Remote
    E1 -->|"reads/writes"| D1
    E1 --> D5
    E2 --> D1
    E2 --> D7
    E3 --> D2
    E3 --> D6
    E4 --> D2
    E4 --> D7
    E5 -->|"handles"| D4
    E5 --> D8

    %% Remote Data API Utils connecting to API Services
    D9 -->|"supports"| D5
    D9 --> D6
    D9 --> D7
    D9 --> D8

    %% External Services integration
    D7 -->|"notifies"| F1
    F2 ---|"integrated in"| C3
    D9 --- F3

    %% Click Events
    click A "https://github.com/mr-1504/bookmoth-literarysocialnetwork/tree/dev/app/"
    click A1 "https://github.com/mr-1504/bookmoth-literarysocialnetwork/tree/dev/app/src/main/java/com/example/bookmoth/ui/activity"
    click A2 "https://github.com/mr-1504/bookmoth-literarysocialnetwork/tree/dev/app/src/main/java/com/example/bookmoth/ui/activity/home"
    click A3 "https://github.com/mr-1504/bookmoth-literarysocialnetwork/tree/dev/app/src/main/java/com/example/bookmoth/ui/adapter"

    click B1 "https://github.com/mr-1504/bookmoth-literarysocialnetwork/blob/dev/app/src/main/java/com/example/bookmoth/ui/viewmodel/login/LoginViewModel.java"
    click B2 "https://github.com/mr-1504/bookmoth-literarysocialnetwork/tree/dev/app/src/main/java/com/example/bookmoth/ui/viewmodel"
    click B3 "https://github.com/mr-1504/bookmoth-literarysocialnetwork/tree/dev/app/src/main/java/com/example/bookmoth/ui/viewmodel"

    click C1 "https://github.com/mr-1504/bookmoth-literarysocialnetwork/tree/dev/app/src/main/java/com/example/bookmoth/domain/model"
    click C2 "https://github.com/mr-1504/bookmoth-literarysocialnetwork/tree/dev/app/src/main/java/com/example/bookmoth/domain/repository"
    click C3 "https://github.com/mr-1504/bookmoth-literarysocialnetwork/tree/dev/app/src/main/java/com/example/bookmoth/domain/usecase"

    click D1 "https://github.com/mr-1504/bookmoth-literarysocialnetwork/blob/dev/app/src/main/java/com/example/bookmoth/data/local/post/PostSQLiteHelper.java"
    click D2 "https://github.com/mr-1504/bookmoth-literarysocialnetwork/blob/dev/app/src/main/java/com/example/bookmoth/data/local/profile/ProfileDao.java"
    click D3 "https://github.com/mr-1504/bookmoth-literarysocialnetwork/blob/dev/app/src/main/java/com/example/bookmoth/data/local/utils/DatabaseManager.java"
    click D4 "https://github.com/mr-1504/bookmoth-literarysocialnetwork/blob/dev/app/src/main/java/com/example/bookmoth/data/local/utils/ImageCache.java"

    click D5 "https://github.com/mr-1504/bookmoth-literarysocialnetwork/blob/dev/app/src/main/java/com/example/bookmoth/data/remote/login/LoginApiService.java"
    click D6 "https://github.com/mr-1504/bookmoth-literarysocialnetwork/blob/dev/app/src/main/java/com/example/bookmoth/data/remote/profile/ProfileApiService.java"
    click D7 "https://github.com/mr-1504/bookmoth-literarysocialnetwork/blob/dev/app/src/main/java/com/example/bookmoth/data/remote/notification/NotificationApiService.java"
    click D8 "https://github.com/mr-1504/bookmoth-literarysocialnetwork/blob/dev/app/src/main/java/com/example/bookmoth/data/remote/wallet/WalletApiService.java"
    click D9 "https://github.com/mr-1504/bookmoth-literarysocialnetwork/tree/dev/app/src/main/java/com/example/bookmoth/data/remote/utils"

    click E1 "https://github.com/mr-1504/bookmoth-literarysocialnetwork/blob/dev/app/src/main/java/com/example/bookmoth/data/repository/login/LoginRepositoryImpl.java"
    click E2 "https://github.com/mr-1504/bookmoth-literarysocialnetwork/tree/dev/app/src/main/java/com/example/bookmoth/data/repository/post"
    click E3 "https://github.com/mr-1504/bookmoth-literarysocialnetwork/tree/dev/app/src/main/java/com/example/bookmoth/data/repository/profile"
    click E4 "https://github.com/mr-1504/bookmoth-literarysocialnetwork/tree/dev/app/src/main/java/com/example/bookmoth/data/repository/register"
    click E5 "https://github.com/mr-1504/bookmoth-literarysocialnetwork/blob/dev/app/src/main/java/com/example/bookmoth/data/repository/wallet/WalletRepositoryImpl.java"

    click F1 "https://github.com/mr-1504/bookmoth-literarysocialnetwork/blob/dev/app/src/main/java/com/example/bookmoth/core/services/MyFirebaseMessagingService.java"
    click F2 "https://github.com/mr-1504/bookmoth-literarysocialnetwork/blob/dev/app/src/main/java/com/example/bookmoth/core/base/cpp/api_key.cpp"
    click F3 "https://github.com/mr-1504/bookmoth-literarysocialnetwork/tree/dev/app/libs"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef viewmodel fill:#FFFF99,stroke:#000,stroke-width:1px;
    classDef domain fill:#FFA500,stroke:#000,stroke-width:1px;
    classDef data fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef repository fill:#F08080,stroke:#000,stroke-width:1px;
    classDef external fill:#D8BFD8,stroke:#000,stroke-width:1px;
    classDef app fill:#FFFFFF,stroke:#000,stroke-width:1px;
```
