# philippc/keepass2android architecture

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

- Interactive diagram: https://gitdiagram.com/philippc/keepass2android
- Repository: https://github.com/philippc/keepass2android

## Overview

##### Main Components
a. User Interface (UI) and Presentation Layer:
- Located primarily in the “src/keepass2android-app” directory.
- Consists of various Activities (e.g., EntryActivity, GroupActivity, PasswordActivity, etc.), Dialogs, and the accompanying Android Resources (layouts, drawables and XML resources).
- This layer handles user inputs, displays the password/database content, and invokes business logic.
b. Business Logic and Database Management:
- Contained in modules such as “src/Kp2aBusinessLogic” and parts of the keepass2android-app code.
- Handles operations such as reading/writing KeePass databases, performing encryption/decryption, key derivation, and file I/O.
- Coordinates data exchange between UI and persistence layers.
c. Cloud Storage & File Management:
- There are several binding and storage modules (e.g., “AndroidFileChooserBinding”, “DropboxBinding”, “JavaFileStorageBindings”, “PCloudBindings”, etc.).
- These components abstract different file storage options (built-in cloud storage as well as third-party storage).
- They interact with the business logic to enable synchronization of the KeePass database across devices.
d. Plugin and Extension Ecosystem:
- Modules like “PluginSdkBinding”, “Keepass2AndroidPluginSDK2”, “PluginQR”, etc. are dedicated to extending the application’s functionality.
- They allow developers to build plug-ins (e.g., QR-code support) that integrate into the app’s lifecycle.
e. Key Transformation and Cryptographic Libraries:
- The “kp2akeytransform” module and native libraries like “TwofishCipher”, “ZlibAndroid”, and others offer targeted support for performing cryptographic functions and data compression.
- They are critical for converting user keys into the strong master key for the database, as well as for handling encryption (AES, Twofish, Argon2, etc.) and compression.
f. Supporting Java Modules and Native Components:
- “src/java” contains many modules that provide additional utilities – such as key file storage, alternative file chooser implementations, and even a soft keyboard project.
- Native C/C++ libraries and Android NDK components (in directories like “jni” under various modules) are used for performance-critical operations like cryptography and compression.

##### Relationships and Interactions
- The UI layer communicates with the Business Logic layer using well-defined service interfaces and event handlers.
- Business Logic accesses the encrypted password database and, when needed, calls the Key Transformation and Cryptographic Libraries to derive keys and encrypt/decrypt data.
- The storage modules (cloud integrations) and file choosers are invoked by the Business Logic when synchronizing or selecting database files.
- Plugin modules provide extensibility – they hook into the UI (for example, integrating QR scanning components) and may also call into business logic for additional actions.
- Native libraries interact with the Java/C# layers via bindings or wrapper modules (e.g., “Transforms”, “Jars” directories in many projects) to offload performance‐critical computations.

##### Architectural Patterns & Design Principles
- There is a clear “separation of concerns” between the UI, Business Logic, Data Access, and Extension/Plugin modules.
- A modular approach is evident, which facilitates independent building, testing, and plugin integration.
- The use of binding projects and wrappers shows an interoperation between different languages (C#, Java, and native C/C++ code) to leverage platform-specific performance or capabilities.
- Directional data flows (from UI → Business Logic → File Storage / Encryption → External Storage) should be clearly captured.

##### Relevant Technologies, Frameworks, and Libraries
- C# and .NET (likely Xamarin or Mono for Android) for the “keepass2android-app”.
- Java for many of the native Android modules (including file storage and plug-in SDK implementations).
- Android native frameworks (Activities, resources, manifests) for the front end.
- Native C/C++ libraries (NDK) for cryptographic algorithms (e.g., Twofish, Argon2, Zlib).
- External libraries such as Dropbox’s SDK, Google’s API for Drive, etc., are integrated via dedicated binding projects.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Presentation Layer
    subgraph "Presentation Layer (UI)"
        UI["UI - keepass2android-app"]
    end

    %% Business Logic / Database Layer
    subgraph "Business Logic & Database"
        BL["BusinessLogic - Kp2aBusinessLogic"]
    end

    %% Cloud Storage & Plugin Modules Layer
    subgraph "Cloud Storage & Plugin Modules"
        subgraph "Cloud Storage & File Management"
            AFC["AndroidFileChooserBinding"]
            DBX["DropboxBinding"]
            JFS["JavaFileStorageBindings"]
            PCLD["PCloudBindings"]
        end
        subgraph "Plugin & Extension Ecosystem"
            PSK["PluginSdkBinding"]
            PSK2["Keepass2AndroidPluginSDK2"]
            QRP["PluginQR"]
        end
    end

    %% Cryptography & Native Components Layer
    subgraph "Cryptography & Native Components"
        subgraph "Key Transformation & Crypto Libraries"
            KT["Key Transform Module"]
            TF["TwofishCipher Support"]
            ZA["ZlibAndroid (Compression/Encryption)"]
            KPL["KeePassLib2Android (Crypto Core)"]
        end
        subgraph "Supporting Java Modules & Native Components"
            JM["Java Modules & Utilities"]
            KDB["KP2AKdbLibrary (Native/KDB)"]
            SKB["KP2ASoftkeyboard (Soft Keyboard)"]
            ARG["Argon2 (Native Cryptography)"]
        end
    end

    %% Connections
    UI -->|"invokes"| BL
    BL -->|"sync"| AFC
    BL -->|"sync"| DBX
    BL -->|"sync"| JFS
    BL -->|"sync"| PCLD

    BL -->|"crypto"| KT
    KT -->|"uses"| TF
    KT -->|"uses"| ZA
    KT -->|"core"| KPL

    UI -->|"plugin"| PSK
    UI -->|"plugin"| PSK2
    UI -->|"plugin"| QRP
    PSK -->|"hooks"| BL
    PSK2 -->|"hooks"| BL
    QRP -->|"hooks"| BL

    BL -->|"native support"| JM
    BL -->|"native support"| KDB
    BL -->|"native support"| SKB
    BL -->|"native support"| ARG

    %% Click Events
    click UI "https://github.com/philippc/keepass2android/tree/master/src/keepass2android-app"
    click BL "https://github.com/philippc/keepass2android/tree/master/src/Kp2aBusinessLogic"
    click AFC "https://github.com/philippc/keepass2android/tree/master/src/AndroidFileChooserBinding"
    click DBX "https://github.com/philippc/keepass2android/tree/master/src/DropboxBinding"
    click JFS "https://github.com/philippc/keepass2android/tree/master/src/JavaFileStorageBindings"
    click PCLD "https://github.com/philippc/keepass2android/tree/master/src/PCloudBindings"
    click PSK "https://github.com/philippc/keepass2android/tree/master/src/PluginSdkBinding"
    click PSK2 "https://github.com/philippc/keepass2android/tree/master/src/Keepass2AndroidPluginSDK2"
    click QRP "https://github.com/philippc/keepass2android/tree/master/src/PluginQR"
    click KT "https://github.com/philippc/keepass2android/tree/master/src/kp2akeytransform"
    click TF "https://github.com/philippc/keepass2android/tree/master/src/TwofishCipher"
    click ZA "https://github.com/philippc/keepass2android/tree/master/src/ZlibAndroid"
    click KPL "https://github.com/philippc/keepass2android/tree/master/src/KeePassLib2Android"
    click JM "https://github.com/philippc/keepass2android/tree/master/src/java"
    click KDB "https://github.com/philippc/keepass2android/tree/master/src/KP2AKdbLibrary"
    click SKB "https://github.com/philippc/keepass2android/tree/master/src/KP2ASoftkeyboard_AS"
    click ARG "https://github.com/philippc/keepass2android/tree/master/src/argon2"

    %% Styles
    classDef ui fill:#add8e6,stroke:#000,stroke-width:2px;
    classDef logic fill:#90ee90,stroke:#000,stroke-width:2px;
    classDef cloud fill:#ffa500,stroke:#000,stroke-width:2px;
    classDef plugin fill:#da70d6,stroke:#000,stroke-width:2px;
    classDef native fill:#d3d3d3,stroke:#000,stroke-width:2px;

    class UI ui;
    class BL logic;
    class AFC,DBX,JFS,PCLD cloud;
    class PSK,PSK2,QRP plugin;
    class KT,TF,ZA,KPL,JM,KDB,SKB,ARG native;
```
