# redsolution/xabber-android architecture

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

- Interactive diagram: https://gitdiagram.com/redsolution/xabber-android
- Repository: https://github.com/redsolution/xabber-android

## Overview

##### Project type and purpose
- A native Android mobile application (XMPP client)
- Written in Java (Android SDK), built with Gradle, supporting multiple product flavors (open, store, vip)
- Implements an MVP presentation layer, a data/business layer, persistence (SQLite + Realm), network layers (XMPP via Smack, HTTP via Retrofit), background Android services, and integrates 3rd-party submodules (MemorizingTrustManager, emojicon)

A. Presentation Layer (UI & MVP)
– Activities / Fragments (com.xabber.android.ui.*)
– View interfaces & Presenter classes (com.xabber.android.presentation.mvp.*)
B. Domain & Data Layer
– Managers (AccountManager, ConnectionManager, MessageManager, etc.)
– Extension managers (CapsManager, CarbonManager, FileManager, OTRManager, etc.)
– Business events & callbacks (OnInitializedListener, OnPacketListener, NewMessageEvent)
C. Persistence Layer
– SQLite tables (classes in data.database.sqlite)
– Realm models (data.database.messagerealm & io.realm)
– DatabaseManager façade
D. Network Layer
– XMPP stack (Smack: XMPPTCPConnection, PacketExtension, ProviderUtils)
– HTTP APIs (Retrofit/OkHttp clients in data.http: CrowdfundingClient, PushApiClient, XabberComClient)
– Custom trust management (MemorizingTrustManager submodule)
E. Background Services
– XabberService (foreground service for persistent connection)
– DownloadService / UploadService (file transfer)
– PushService (in open/store flavors)
F. Build & Flavor configuration
– Gradle productFlavors “open”, “store”, “vip”
– Submodule: MemorizingTrustManager
– Scripts (crowdin.bash for translation updates)

##### External Systems & Services
– XMPP servers (any XMPP domain)
– Xabber.com HTTP API (xaccount, Patreon endpoints)
– Crowdfunding / Patreon servers
– Crowdin (localization pipeline)
– Google Play / F-Droid (app distribution)

##### Relationships & Data Flows
- UI → Presenter: user actions (send message, change account settings)
- Presenter → Manager: invokes business logic (AccountManager.createAccount(), MessageManager.send())
- Manager → Network: XMPP layer (via ConnectionBuilder & XMPPTCPConnection) or Retrofit HTTP client
- Network → Manager → UI: incoming XMPP stanzas generate events (OnPacketListener → MessageUpdateEvent → Presenter)
- Manager → Persistence: store/retrieve chat history & settings (DatabaseManager → SQLite/Realm)
- Services → Manager/UI: background reconnection, push notification dispatch
- Build scripts → Flavor modules: include/exclude PushService keys, resource overlays for “vip” gold theme

##### Architectural patterns & design principles
– Layered architecture (Presentation → Domain → Persistence → Network)
– MVP in UI layer for separation of concerns
– Observer / Listener patterns for event dispatch
– Façades (DatabaseManager, NetworkManager) to abstract low‐level details
– Dependency injection implied by Manager interfaces (e.g., BaseManagerInterface)
– Product Flavor isolation (open vs. store vs. vip code paths)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer" 
        direction TB
        UI_Activities["UI Activities & Fragments"]:::ui
        MVP["Presenters & Views"]:::ui
    end

    %% Domain & Data Layer
    subgraph "Domain & Data Layer"
        direction TB
        CoreData["Core Data Package"]:::domain
        AccountMgr["AccountManager"]:::domain
        ConnectionMgr["ConnectionManager"]:::domain
        MessageMgr["MessageManager"]:::domain
    end

    %% Persistence Layer
    subgraph "Persistence Layer"
        direction TB
        DBFacade["DatabaseManager"]:::persistence
        SQLiteTables["SQLite Tables"]:::persistence
        RealmModels["Realm Models"]:::persistence
    end

    %% Network Layer
    subgraph "Network Layer"
        direction TB
        XMPPStack["XMPP Stack Core"]:::network
        XMPPTCP["XMPPTCPConnection"]:::network
        HTTPClients["HTTP API Clients"]:::network
        TrustMgr["MemorizingTrustManager"]:::network
    end

    %% Background Services
    subgraph "Background Services"
        direction TB
        XabberSvc["XabberService"]:::service
        DownloadSvc["DownloadService"]:::service
        UploadSvc["UploadService"]:::service
        PushOpen["PushService (Open)"]:::service
        PushStore["PushService (Store)"]:::service
    end

    %% Build & Flavor Configuration
    subgraph "Build & Flavor Config"
        direction TB
        GradleFlavors["Gradle & Flavors"]:::build
        CrowdinScript["Localization Scripts"]:::build
    end

    %% External Systems
    subgraph "External Systems"
        direction TB
        XMPPServers["XMPP Servers"]:::external
        XabberAPI["Xabber.com HTTP API"]:::external
        CrowdinExt["Crowdin"]:::external
        Distribution["Google Play / F-Droid"]:::external
    end

    %% Connections
    UI_Activities -->|"user actions"| MVP
    MVP -->|"invokes"| AccountMgr
    MVP -->|"invokes"| MessageMgr
    MVP -->|"invokes"| ConnectionMgr

    AccountMgr -->|"save/retrieve"| DBFacade
    MessageMgr -->|"saveMessage()"| DBFacade
    ConnectionMgr -->|"build connection"| XMPPStack

    DBFacade -->|"uses"| SQLiteTables
    DBFacade -->|"uses"| RealmModels

    XMPPStack -->|"open socket"| XMPPTCP
    XMPPTCP -->|"TLS handshake"| TrustMgr
    HTTPClients -->|"HTTP calls"| XabberAPI

    XMPPServers -->|"stanzas"| XMPPStack
    XMPPStack -->|"OnPacketListener"| MessageMgr
    MessageMgr -->|"update UI"| MVP

    XabberSvc -->|"maintains conn."| ConnectionMgr
    DownloadSvc -->|"file transfer"| FileSystem
    UploadSvc -->|"file transfer"| FileSystem

    PushOpen -->|"push notif."| MVP
    PushStore -->|"push notif."| MVP

    GradleFlavors -->|"include/exclude"| PushOpen
    GradleFlavors -->|"include/exclude"| PushStore

    CrowdinExt -->|"translations"| CrowdinScript
    CrowdinScript -->|"generates resources"| UI_Activities

    Distribution -->|"publishes app"| GradleFlavors

    %% FileSystem placeholder (not a layer)
    FileSystem["File System"]:::service

    DownloadSvc --> FileSystem
    UploadSvc --> FileSystem

    %% Click Events
    click UI_Activities "https://github.com/redsolution/xabber-android/tree/master/xabber/src/main/java/com/xabber/android/ui"
    click MVP "https://github.com/redsolution/xabber-android/tree/master/xabber/src/main/java/com/xabber/android/presentation/mvp"
    click CoreData "https://github.com/redsolution/xabber-android/tree/master/xabber/src/main/java/com/xabber/android/data"
    click AccountMgr "https://github.com/redsolution/xabber-android/blob/master/xabber/src/main/java/com/xabber/android/data/account/AccountManager.java"
    click ConnectionMgr "https://github.com/redsolution/xabber-android/blob/master/xabber/src/main/java/com/xabber/android/data/connection/ConnectionManager.java"
    click MessageMgr "https://github.com/redsolution/xabber-android/blob/master/xabber/src/main/java/com/xabber/android/data/message/MessageManager.java"
    click DBFacade "https://github.com/redsolution/xabber-android/blob/master/xabber/src/main/java/com/xabber/android/data/database/DatabaseManager.java"
    click SQLiteTables "https://github.com/redsolution/xabber-android/tree/master/xabber/src/main/java/com/xabber/android/data/database/sqlite"
    click RealmModels "https://github.com/redsolution/xabber-android/tree/master/xabber/src/main/java/com/xabber/android/data/database/messagerealm"
    click XMPPStack "https://github.com/redsolution/xabber-android/tree/master/xabber/src/main/java/com/xabber/xmpp"
    click XMPPTCP "https://github.com/redsolution/xabber-android/blob/master/xabber/src/main/java/com/xabber/xmpp/smack/XMPPTCPConnection.java"
    click HTTPClients "https://github.com/redsolution/xabber-android/tree/master/xabber/src/main/java/com/xabber/android/data/http"
    click TrustMgr "https://github.com/redsolution/xabber-android/tree/master/xabber/MemorizingTrustManager"
    click XabberSvc "https://github.com/redsolution/xabber-android/blob/master/xabber/src/main/java/com/xabber/android/service/XabberService.java"
    click DownloadSvc "https://github.com/redsolution/xabber-android/blob/master/xabber/src/main/java/com/xabber/android/service/DownloadService.java"
    click UploadSvc "https://github.com/redsolution/xabber-android/blob/master/xabber/src/main/java/com/xabber/android/service/UploadService.java"
    click PushOpen "https://github.com/redsolution/xabber-android/blob/master/xabber/src/open/java/com/xabber/android/service/PushService.java"
    click PushStore "https://github.com/redsolution/xabber-android/blob/master/xabber/src/store/java/com/xabber/android/service/PushService.java"
    click GradleFlavors "https://github.com/redsolution/xabber-android/blob/master/xabber/build.gradle"
    click CrowdinScript "https://github.com/redsolution/xabber-android/blob/master/scripts/crowdin.bash"

    %% Styles
    classDef ui fill:#cce5ff,stroke:#004085;
    classDef domain fill:#d4edda,stroke:#155724;
    classDef persistence fill:#fff3cd,stroke:#856404;
    classDef network fill:#ffe5b4,stroke:#b36b00;
    classDef service fill:#e2e3e5,stroke:#6c757d;
    classDef build fill:#d1ecf1,stroke:#0c5460;
    classDef external fill:#f8d7da,stroke:#721c24;
```
