# deltachat/deltachat-android architecture

> Architecture diagram of the GitHub repository deltachat/deltachat-android, 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/deltachat/deltachat-android
- Repository: https://github.com/deltachat/deltachat-android

## Overview

##### Main Components
- Android Application (Frontend/UI): Represent the different source variants (e.g., “src/main”, “src/foss”, “src/gplay”) which include Activities, Fragments, Services, Content Providers, and Broadcast Receivers. Note that the UI is built using standard Android components (many layouts, resources, XML files).
- Native/ Core Library Layer: Illustrate the integration with the core messaging engine (deltachat-core-rust). This native component is built via the NDK build scripts and lives partly in the “jni/” folder and also exists as a git submodule. Indicate the JNI bridge and how it communicates with the Java layer.
- Build and Tooling Environment:
– Gradle build files (build.gradle, settings.gradle) for building the Android project.
– Build scripts under “scripts/” that manage tasks such as cross-compilation, toolchain installation, and launching the NDK build (e.g. ndk-make.sh).
– Dockerfile and Nix (flake.nix) support for containerized development environments.
- CI/CD & Metadata/Deployment:
– GitHub Actions workflows (in “.github/workflows”) for artifact generation and APK previews.
– Fastlane directory for managing metadata and publishing to F-Droid, Google Play, etc.
- Internationalization & External Resources:
– Translations managed with Weblate are indirectly integrated via fastlane/metadata and the metadata folder.
– Additional configuration files (e.g., google-services.json) which suggest dependency on external services such as Firebase.

##### Relationships and Interactions
- Specify the build toolchain: Gradle orchestrates the build process, while integration with NDK scripts and Rust cross-compilation happens through the “scripts/” folder. Show these elements as supporting infrastructure that “builds” the app.
- External integration points for release deployment (fastlane metadata for Play Store and F-Droid) and testing (automated UI tests, Android instrumented tests in “src/androidTest”).

##### Architectural Patterns and Design Principles
- Modular Design: Show how the submodule (the Delta Chat Core native library) is an independent component (in a separate repository) that is integrated into the Android app.
- Layered Architecture: Represent the application as layered where the top layer is presentation (activities, fragments), the middle layer contains services/utilities (events, networking, database access), and a lower layer handles native operations.
- Testing and CI/CD automation as part of the development lifecycle.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CI/CD & Deployment Layer
    subgraph "CI/CD & Deployment"
        CIC1["GitHub Actions Workflows: .github/workflows/"]:::cicd
        CIC2["Fastlane Deployment: fastlane/"]:::cicd
    end

    %% Build & Tooling Infrastructure Layer
    subgraph "Build & Tooling Infrastructure"
        BT1["Gradle Build: build.gradle"]:::build
        BT2["Gradle Settings: settings.gradle"]:::build
        BT3["Gradle Wrapper: gradle/ (gradlew,gradlew.bat)"]:::build
        BT4["Scripts: scripts/"]:::build
        BT5["Dockerfile"]:::build
        BT6["Nix Config: flake.nix"]:::build
    end

    %% Internationalization & External Resources (supporting Build)
    subgraph "Internationalization & External Resources"
        IR1["Fastlane Metadata: fastlane/metadata/"]:::intl
        IR2["Google Services: google-services.json"]:::intl
    end

    %% Android UI Layer
    subgraph "Android UI Layer"
        UI1["UI: src/main"]:::ui
        UI2["UI: src/foss"]:::ui
        UI3["UI: src/gplay"]:::ui
    end

    %% Native Messaging Engine Layer
    subgraph "Native Messaging Engine"
        NM1["Native Engine: deltachat-core-rust"]:::native
        NM2["JNI Bridge: dc_wrapper.c"]:::native
        NM3["NDK Build Files: Android.mk & Application.mk"]:::native
    end

    %% Relationships: CI/CD triggers Build & Tooling
    CIC1 -->|"triggers"| BT1
    CIC1 -->|"triggers"| BT2
    CIC1 -->|"triggers"| BT3
    CIC1 -->|"triggers"| BT4
    CIC1 -->|"triggers"| BT5
    CIC1 -->|"triggers"| BT6
    CIC2 -->|"deploys"| BT1
    CIC2 -->|"deploys"| BT2
    CIC2 -->|"deploys"| BT3
    CIC2 -->|"deploys"| BT4
    CIC2 -->|"deploys"| BT5
    CIC2 -->|"deploys"| BT6

    %% International resources supporting Build
    IR1 -->|"informs"| BT1
    IR1 -->|"informs"| BT2
    IR2 -->|"provides"| BT1

    %% Build & Tooling builds the UI Layer
    BT1 -->|"builds"| UI1
    BT1 -->|"builds"| UI2
    BT1 -->|"builds"| UI3

    %% Build & Tooling also supports Native integration via Scripts
    BT4 -->|"runs"| NM3

    %% UI Layer interacts with Native via JNI
    UI1 -->|"JNI_calls"| NM2
    UI2 -->|"JNI_calls"| NM2
    UI3 -->|"JNI_calls"| NM2

    %% JNI Bridge integrates with Native Engine
    NM2 -->|"connects_to"| NM1

    %% Also, NDK Build Files combine with JNI Bridge for native integration
    NM3 -->|"supports"| NM2

    %% Click Events for Android UI Layer
    click UI1 "https://github.com/deltachat/deltachat-android/tree/main/src/main"
    click UI2 "https://github.com/deltachat/deltachat-android/tree/main/src/foss"
    click UI3 "https://github.com/deltachat/deltachat-android/tree/main/src/gplay"

    %% Click Events for Native Messaging Engine
    click NM1 "https://github.com/deltachat/deltachat-android/tree/main/jni/deltachat-core-rust"
    click NM2 "https://github.com/deltachat/deltachat-android/blob/main/jni/dc_wrapper.c"
    click NM3 "https://github.com/deltachat/deltachat-android/blob/main/jni/Android.mk"

    %% Click Events for Build & Tooling Infrastructure
    click BT1 "https://github.com/deltachat/deltachat-android/blob/main/build.gradle"
    click BT2 "https://github.com/deltachat/deltachat-android/blob/main/settings.gradle"
    click BT3 "https://github.com/deltachat/deltachat-android/tree/main/gradle/"
    click BT4 "https://github.com/deltachat/deltachat-android/tree/main/scripts/"
    click BT5 "https://github.com/deltachat/deltachat-android/tree/main/Dockerfile"
    click BT6 "https://github.com/deltachat/deltachat-android/blob/main/flake.nix"

    %% Click Events for CI/CD & Deployment
    click CIC1 "https://github.com/deltachat/deltachat-android/tree/main/.github/workflows/"
    click CIC2 "https://github.com/deltachat/deltachat-android/tree/main/fastlane/"

    %% Click Events for Internationalization & External Resources
    click IR1 "https://github.com/deltachat/deltachat-android/tree/main/fastlane/metadata/"
    click IR2 "https://github.com/deltachat/deltachat-android/blob/main/google-services.json"

    %% Styles
    classDef ui fill:#AED6F1,stroke:#2471A3,stroke-width:2px;
    classDef native fill:#F9E79F,stroke:#D4AC0D,stroke-width:2px;
    classDef build fill:#D5F5E3,stroke:#28B463,stroke-width:2px;
    classDef cicd fill:#F5B7B1,stroke:#C0392B,stroke-width:2px;
    classDef intl fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
```
