How prashant17d97/biometric-authentication- works
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.