# recognito-vision/android-facerecognition-facelivenessdetection architecture

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

- Interactive diagram: https://gitdiagram.com/recognito-vision/android-facerecognition-facelivenessdetection
- Repository: https://github.com/recognito-vision/android-facerecognition-facelivenessdetection

## Overview

##### Main Components
- Android Application (UI / Activities): Highlight the “app” folder with its source code, activities (MainActivity, CameraActivity, ResultActivity, SettingsActivity) and supporting classes (such as DBManager, PersonAdapter, Person, CircleImageView, and FaceView). These components drive the user interface, handle user interactions, and manage data display.
- Recognito Face Recognition SDK (Native/Library Integration): Include both “libfacesdk” and “libfotoapparat” modules. These are integrated via Gradle to provide native functions like face detection, template extraction, similarity calculation, and YUV to Bitmap conversion. Indicate that these libraries are essential for the core functionality.
- Assets and Configuration: Represent configuration assets such as the “license” file (placed under app/src/main/assets) that holds the application licensing information. Also include XML files (layouts, values, preferences, backup, and data extraction rules) that configure the UI, theming, and certain behavioral elements.
- Test Components: Acknowledge the presence of unit and instrumented tests in the “app/src/test” and “app/src/androidTest” directories as part of ensuring the proper functioning of the application.

##### Component Interactions and Data Flow
- Configuration & Licensing -> SDK Initialization: Represent that the SDK initialization using the license file, as well as settings configuration from XML resources, feeds into the application startup (usually in MainActivity).
- External Interactions: Optionally, note that even though the application is “fully-offline” there is a reference to an external API integration for demonstration purposes (for instance, for 1:N face search demo) that could be represented if needed.

##### Architectural Patterns and Design Principles
- Modularity: The clear separation between the Android application code and the native library components (libfacesdk and libfotoapparat) is a key architectural choice.
- Native Integration: The use of native methods (via JNI) is crucial in this project's architecture, ensuring performance critical operations like face detection run efficiently.
- UI/Presentation Separation: The Android UI (activities, layouts, adapters) is separated from the business logic (SDK interactions, DBManager for person data). This division supports a clean, maintainable structure.

## Diagram (Mermaid)

```mermaid
flowchart TD

    %% User Interface Layer
    subgraph "User Interface Layer"
        MA["MainActivity"]:::ui
        CA["CameraActivity"]:::ui
        RA["ResultActivity"]:::ui
        SA["SettingsActivity"]:::ui
        PA["PersonAdapter"]:::ui
        DB["DBManager"]:::ui
        P["Person"]:::ui
        CIV["CircleImageView"]:::ui
        FV["FaceView"]:::ui
        UT["Utils"]:::ui
    end

    %% Business/Logic & SDK Integration Layer
    subgraph "SDK & Native Libraries"
        SDK1["libfacesdk"]:::sdk
        SDK2["libfotoapparat"]:::sdk
        FP["FaceProcessing\n(setActivation,init,faceDetection,\ntemplateExtraction,similarityCalculation,\nyuv2Bitmap)"]:::sdk
    end

    %% Assets & Configuration Layer
    subgraph "Assets & Configuration"
        LF["License File"]:::config
        XML["XML Config"]:::config
    end

    %% Test Components Layer
    subgraph "Test Components"
        UTst["Unit Tests"]:::test
        ITst["Instrumented Tests"]:::test
    end

    %% Data Flow Arrows
    MA -->|"load_license"| LF
    LF -->|"initialize_SDK"| SDK1
    XML -->|"provide_config"| MA
    XML -->|"provide_config"| SA

    CA -->|"capture_frame"| FP
    FP -->|"process_result"| RA

    MA -->|"call_activation"| SDK1
    SDK1 -->|"integrates_with"| SDK2

    PA ---|"binds_data"| DB
    DB ---|"manages"| P

    %% Click Events for Android Application UI Components
    click MA "https://github.com/recognito-vision/android-facerecognition-facelivenessdetection/blob/facesdk_core/app/src/main/java/com/bio/facerecognition/MainActivity.kt"
    click CA "https://github.com/recognito-vision/android-facerecognition-facelivenessdetection/blob/facesdk_core/app/src/main/java/com/bio/facerecognition/CameraActivityKt.kt"
    click RA "https://github.com/recognito-vision/android-facerecognition-facelivenessdetection/blob/facesdk_core/app/src/main/java/com/bio/facerecognition/ResultActivity.kt"
    click SA "https://github.com/recognito-vision/android-facerecognition-facelivenessdetection/blob/facesdk_core/app/src/main/java/com/bio/facerecognition/SettingsActivity.kt"
    click PA "https://github.com/recognito-vision/android-facerecognition-facelivenessdetection/blob/facesdk_core/app/src/main/java/com/bio/facerecognition/PersonAdapter.java"
    click DB "https://github.com/recognito-vision/android-facerecognition-facelivenessdetection/blob/facesdk_core/app/src/main/java/com/bio/facerecognition/DBManager.java"
    click P "https://github.com/recognito-vision/android-facerecognition-facelivenessdetection/blob/facesdk_core/app/src/main/java/com/bio/facerecognition/Person.java"
    click CIV "https://github.com/recognito-vision/android-facerecognition-facelivenessdetection/blob/facesdk_core/app/src/main/java/com/bio/facerecognition/CircleImageView.java"
    click FV "https://github.com/recognito-vision/android-facerecognition-facelivenessdetection/blob/facesdk_core/app/src/main/java/com/bio/facerecognition/FaceView.java"
    click UT "https://github.com/recognito-vision/android-facerecognition-facelivenessdetection/blob/facesdk_core/app/src/main/java/com/bio/facerecognition/Utils.java"

    %% Click Events for SDK Components
    click SDK1 "https://github.com/recognito-vision/android-facerecognition-facelivenessdetection/tree/facesdk_core/libfacesdk/"
    click SDK2 "https://github.com/recognito-vision/android-facerecognition-facelivenessdetection/tree/facesdk_core/libfotoapparat/"

    %% Click Events for Assets & Configurations
    click LF "https://github.com/recognito-vision/android-facerecognition-facelivenessdetection/tree/facesdk_core/app/src/main/assets/license"
    click XML "https://github.com/recognito-vision/android-facerecognition-facelivenessdetection/tree/facesdk_core/app/src/main/res/"

    %% Click Events for Test Components
    click UTst "https://github.com/recognito-vision/android-facerecognition-facelivenessdetection/tree/facesdk_core/app/src/test/java/com/bio/facerecognition/"
    click ITst "https://github.com/recognito-vision/android-facerecognition-facelivenessdetection/tree/facesdk_core/app/src/androidTest/java/com/bio/facerecognition/"

    %% Styles
    classDef ui fill:#AEDFF7,stroke:#333,stroke-width:2px;
    classDef sdk fill:#F7D6A1,stroke:#333,stroke-width:2px;
    classDef config fill:#C8E6C9,stroke:#333,stroke-width:2px;
    classDef test fill:#FFD180,stroke:#333,stroke-width:2px;
```
