# prashant17d97/biometric-authentication- architecture

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

- Interactive diagram: https://gitdiagram.com/prashant17d97/biometric-authentication-
- Repository: https://github.com/prashant17d97/biometric-authentication-

## Overview

##### Project Type and Purpose
- This is a Kotlin Multiplatform (KMP) library module (“biometric”) bundled in a monorepo with two demo clients:
- composeApp – a multiplatform Compose UI sample for Android & iOS
- iosApp – a native SwiftUI-based iOS client
- The library offers a coroutine-friendly, unified API for biometric authentication and protected cryptography, plus a secure vault abstraction.

##### File-Structure Analysis
- Top-level modules:
- biometric/ – the reusable KMP library
- composeApp/ – Compose Multiplatform demo (Android + iOS)
- iosApp/ – SwiftUI iOS demo
- Inside biometric/:
- src/commonMain/ – domain models, use-cases, repository interfaces, utility code
- src/androidMain/ – Android-specific implementations (BiometricHostActivity, PromptGatewayAndroid, AndroidPayloadStore)
- src/iosMain/ – iOS-specific implementations (PromptGatewayIos, IosPayloadStore)
- build.gradle.kts files configure multiplatform targets and dependencies.
- README describes architecture (Clean Architecture + MVI for the sample app) and usage.

##### Key Components
a) Core Library (biometric) Layers
– Presentation Facade: BiometricManager
– Use-Case Layer: Authenticate, Encrypt, Decrypt, SecureVault flows
– Domain Repos (interfaces):
- BiometricAuthRepository
- BiometricCryptoRepository
- PromptGateway
- PayloadStore
– Platform Impl Layer:
- Android: PromptGatewayAndroid, AndroidPayloadStore
- iOS: PromptGatewayIos, IosPayloadStore
– SecureVaultRepository: orchestrates encrypt-store + retrieve-decrypt
b) Demo Clients
– ComposeApp (commonMain UI + ViewModel → calls BiometricManager)
– ComposeApp Android/iOS drivers
– iosApp SwiftUI client → direct calls to BiometricManager
c) External Services
– OS Biometric APIs (AndroidX Biometric, iOS LocalAuthentication/Secure Enclave)
– Local Storage (KeyStore on Android, Keychain on iOS)

##### Relationships and Data Flow
1) UI Layer (Compose or SwiftUI)
→ invokes BiometricManager.getInstance().auth()/encrypt()/decrypt()
2) BiometricManager (Facade)
→ dispatches to Use-Case classes
3) Use-Cases
→ call domain repository interfaces (AuthRepo, CryptoRepo, PromptGateway, PayloadStore)
4) Platform Implementations
→ PromptGatewayAndroid/PromptGatewayIos shows the native biometric prompt
→ BiometricCryptoRepository uses KeyStore/Keychain for cryptographic operations
→ PayloadStore implementations persist encrypted blobs
5) SecureVaultRepository
→ composes Crypto + PayloadStore for encrypt-store and retrieve-decrypt flows
6) Returns BiometricResult (Success/Failed/Canceled) back to UI

##### Architectural Patterns and Principles
- Clean Architecture: clear separation between domain, use-case, and implementation layers
- SOLID: each repo/use-case has a single responsibility, interfaces for dependency inversion
- MVI in ComposeApp: Intent → ViewModel → State → UI
- KMP Source Sets: share common code, isolate Android/iOS specifics

##### Technologies & Frameworks
- Kotlin Multiplatform (commonMain, androidMain, iosMain)
- Coroutines for async flows
- AndroidX Biometric, Android Keystore
- iOS LocalAuthentication, Keychain / Secure Enclave
- Jetpack Compose Multiplatform (composeApp)
- SwiftUI (iosApp)

##### Final Recommendations
- Be exhaustive: don’t leave out the PromptGateway or PayloadStore interfaces.
- Platform-specific classes in dedicated sections.
- Use arrowheads to indicate request vs. callback flows.
- Interface-implementation pairs are visible to illustrate Clean Architecture dependency inversion.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Demo Clients
    subgraph "Demo Clients"
        subgraph "ComposeApp (Multiplatform MVI)"
            direction TB
            Intent["Intent"]:::ui
            State["State"]:::ui
            AppViewModel["AppViewModel"]:::ui
            AppUI["App.kt"]:::ui
            Intent -->|dispatches| AppViewModel
            AppViewModel -->|"updates"| State
            AppUI -->|"renders"| State
            AppViewModel -->|calls| BiometricManager
        end
        subgraph "ComposeApp Android Driver"
            direction TB
            BioAuthApp["BioAuthApplication"]:::android
            MainActivity["MainActivity"]:::android
            BioAuthApp --> MainActivity
            MainActivity -->|launches| AppUI
        end
        subgraph "ComposeApp iOS Driver"
            direction TB
            MainVC["MainViewController"]:::ios
            MainVC -->|hosts| AppUI
        end
        subgraph "iosApp (SwiftUI Client)"
            direction TB
            IOSApp["iOSApp.swift"]:::ui
            ContentView["ContentView.swift"]:::ui
            IOSApp --> ContentView
            ContentView -->|calls| BiometricManager
        end
    end

    %% Biometric Library Layers
    subgraph "Biometric KMP Library"
        direction TB
        BiometricManager["BiometricManager"]:::common

        subgraph "Use-Case Layer"
            direction TB
            Authenticate["Authenticate"]:::common
            Encrypt["Encrypt"]:::common
            Decrypt["Decrypt"]:::common
            EncryptVault["EncryptWithSecureVault"]:::common
            DecryptVault["DecryptFromVault"]:::common
            Delete["Delete"]:::common
            GetCapability["GetCapability"]:::common
        end

        SecureVaultRepo["SecureVaultRepository"]:::common

        subgraph "Domain Repositories"
            direction TB
            AuthRepo["BiometricAuthRepository"]:::common
            CryptoRepo["BiometricCryptoRepository"]:::common
            PromptInterface["PromptGateway"]:::common
            PayloadInterface["PayloadStore"]:::common
        end

        subgraph "Android Implementation" 
            direction TB
            PromptAndroid["PromptGatewayAndroid"]:::android
            PayloadAndroid["AndroidPayloadStore"]:::android
            ControllerImpl["BiometricControllerImpl"]:::android
        end

        subgraph "iOS Implementation"
            direction TB
            PromptiOS["PromptGatewayIos"]:::ios
            PayloadiOS["IosPayloadStore"]:::ios
        end

        %% Connections in library
        BiometricManager -->|"invokes"| Authenticate
        BiometricManager --> Encrypt
        BiometricManager --> Decrypt
        BiometricManager --> EncryptVault
        BiometricManager --> DecryptVault
        BiometricManager --> Delete
        BiometricManager --> GetCapability

        Authenticate --> AuthRepo
        Encrypt --> CryptoRepo
        Decrypt --> CryptoRepo
        EncryptVault --> SecureVaultRepo
        DecryptVault --> SecureVaultRepo
        Delete --> AuthRepo
        GetCapability --> PromptInterface

        SecureVaultRepo --> CryptoRepo
        SecureVaultRepo --> PayloadInterface

        AuthRepo --> ControllerImpl
        PromptInterface --> PromptAndroid
        PayloadInterface --> PayloadAndroid

        AuthRepo --> BiometricControllerImpl
        ControllerImpl -->|uses| AndroidBiometric
        PromptAndroid -->|shows prompt via| AndroidBiometric
        PayloadAndroid -->|stores blob to| AndroidKeystore

        PromptInterface --> PromptiOS
        PayloadInterface --> PayloadiOS
        PromptiOS -->|shows prompt via| IosLocalAuth
        PayloadiOS -->|stores blob to| IosKeychain
    end

    %% External OS Services
    subgraph "OS Services"
        direction TB
        AndroidBiometric["AndroidX Biometric"]:::external
        AndroidKeystore["Android Keystore"]:::external
        IosLocalAuth["iOS LocalAuthentication"]:::external
        IosKeychain["iOS Keychain/Secure Enclave"]:::external
    end

    %% Legend
    subgraph "Legend"
        direction LR
        C["Common"]:::common
        A["Android"]:::android
        I["iOS"]:::ios
        U["UI"]:::ui
        E["External"]:::external
    end

    %% Click Events
    click BiometricManager "https://github.com/prashant17d97/biometric-authentication-/blob/master/biometric/src/commonMain/kotlin/app/biometric/authenticate/BiometricManager.kt"
    click Authenticate "https://github.com/prashant17d97/biometric-authentication-/blob/master/biometric/src/commonMain/kotlin/app/biometric/authenticate/domain/usecase/Authenticate.kt"
    click Encrypt "https://github.com/prashant17d97/biometric-authentication-/blob/master/biometric/src/commonMain/kotlin/app/biometric/authenticate/domain/usecase/Encrypt.kt"
    click Decrypt "https://github.com/prashant17d97/biometric-authentication-/blob/master/biometric/src/commonMain/kotlin/app/biometric/authenticate/domain/usecase/Decrypt.kt"
    click EncryptVault "https://github.com/prashant17d97/biometric-authentication-/blob/master/biometric/src/commonMain/kotlin/app/biometric/authenticate/domain/usecase/EncryptWithSecureVault.kt"
    click DecryptVault "https://github.com/prashant17d97/biometric-authentication-/blob/master/biometric/src/commonMain/kotlin/app/biometric/authenticate/domain/usecase/DecryptFromVault.kt"
    click Delete "https://github.com/prashant17d97/biometric-authentication-/blob/master/biometric/src/commonMain/kotlin/app/biometric/authenticate/domain/usecase/Delete.kt"
    click GetCapability "https://github.com/prashant17d97/biometric-authentication-/blob/master/biometric/src/commonMain/kotlin/app/biometric/authenticate/domain/usecase/GetCapability.kt"
    click AuthRepo "https://github.com/prashant17d97/biometric-authentication-/blob/master/biometric/src/commonMain/kotlin/app/biometric/authenticate/domain/repo/BiometricAuthRepository.kt"
    click CryptoRepo "https://github.com/prashant17d97/biometric-authentication-/blob/master/biometric/src/commonMain/kotlin/app/biometric/authenticate/domain/repo/BiometricCryptoRepository.kt"
    click PromptInterface "https://github.com/prashant17d97/biometric-authentication-/blob/master/biometric/src/commonMain/kotlin/app/biometric/authenticate/domain/repo/PromptGateway.kt"
    click PayloadInterface "https://github.com/prashant17d97/biometric-authentication-/blob/master/biometric/src/commonMain/kotlin/app/biometric/authenticate/domain/repo/PayloadStore.kt"
    click SecureVaultRepo "https://github.com/prashant17d97/biometric-authentication-/blob/master/biometric/src/commonMain/kotlin/app/biometric/authenticate/data/SecureVaultRepository.kt"
    click PromptAndroid "https://github.com/prashant17d97/biometric-authentication-/blob/master/biometric/src/androidMain/kotlin/app/biometric/authenticate/data/prompt/PromptGatewayAndroid.kt"
    click PayloadAndroid "https://github.com/prashant17d97/biometric-authentication-/blob/master/biometric/src/androidMain/kotlin/app/biometric/authenticate/data/AndroidPayloadStore.kt"
    click ControllerImpl "https://github.com/prashant17d97/biometric-authentication-/blob/master/biometric/src/androidMain/kotlin/app/biometric/authenticate/data/repo/BiometricControllerImpl.kt"
    click PromptiOS "https://github.com/prashant17d97/biometric-authentication-/blob/master/biometric/src/iosMain/kotlin/app/biometric/authenticate/data/prompt/PromptGatewayIos.kt"
    click PayloadiOS "https://github.com/prashant17d97/biometric-authentication-/blob/master/biometric/src/iosMain/kotlin/app/biometric/authenticate/data/IosPayloadStore.kt"
    click AppUI "https://github.com/prashant17d97/biometric-authentication-/blob/master/composeApp/src/commonMain/kotlin/com/prashant/bioauth/presentation/App.kt"
    click AppViewModel "https://github.com/prashant17d97/biometric-authentication-/blob/master/composeApp/src/commonMain/kotlin/com/prashant/bioauth/presentation/AppViewModel.kt"
    click Intent "https://github.com/prashant17d97/biometric-authentication-/blob/master/composeApp/src/commonMain/kotlin/com/prashant/bioauth/presentation/Intent.kt"
    click State "https://github.com/prashant17d97/biometric-authentication-/blob/master/composeApp/src/commonMain/kotlin/com/prashant/bioauth/presentation/State.kt"
    click BioAuthApp "https://github.com/prashant17d97/biometric-authentication-/blob/master/composeApp/src/androidMain/kotlin/com/prashant/bioauth/BioAuthApplication.kt"
    click MainActivity "https://github.com/prashant17d97/biometric-authentication-/blob/master/composeApp/src/androidMain/kotlin/com/prashant/bioauth/MainActivity.kt"
    click MainVC "https://github.com/prashant17d97/biometric-authentication-/blob/master/composeApp/src/iosMain/kotlin/com/prashant/bioauth/MainViewController.kt"
    click IOSApp "https://github.com/prashant17d97/biometric-authentication-/blob/master/iosApp/iosApp/iOSApp.swift"
    click ContentView "https://github.com/prashant17d97/biometric-authentication-/blob/master/iosApp/iosApp/ContentView.swift"

    %% Styles
    classDef common fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef android fill:#90EE90,stroke:#333,stroke-width:1px
    classDef ios fill:#FFA500,stroke:#333,stroke-width:1px
    classDef ui fill:#D8BFD8,stroke:#333,stroke-width:1px
    classDef external fill:#D3D3D3,stroke:#333,stroke-width:1px
```
