How bgiraudr/facerec works
Main Components
• Mobile Application (Android) – This is the host environment.
• UI Layer – Represented by Android activities (MainActivity, FindResultsActivity, ManageFacesActivity) and fragments (MainFragment, FindFragment). Also include the various adapters (e.g., MainFaceAdapter, MatchingResultAdapter, PersonAdapter) used to populate UI elements.
• Data Layer – Includes the domain models (Face, PairResults, Person) and persistence implemented through Room (FaceRecDatabase, FaceDAO, PersonDAO, PersonWithFacesEntity). This layer manages data storage and retrieval.
• Model and Inference Layer – The utilization of the FaceNet model. Note that the model file (facenet_xnn.pte) is meant to reside in the assets, and the native library (libexecutorch.so) is used for executing the model. Also, the “models” folder contains a Python script (facenet_casia_webfaces_xnn.py) used to generate these resources.
• Build/Configuration – The build.gradle.kts files, gradle configurations, and other scripts indicate that Gradle is being used to build the project. While not part of the run-time components, they’re important for understanding how the system is packaged and deployed.
• External Dependencies – References include Material 3 (MDC-Android), the Facenet implementation (e.g., the Davidsandberg and facenet-pytorch repos), and Executorch for model execution.
Relationships and Interactions
• UI Components (Activities, Fragments, Adapters, and ViewModels) interact with the Data Layer. For example, user input that starts a face recognition process will trigger calls from an Activity which may go through a SharedViewModel, eventually reaching the Room database or invoking native inference via the Executorch library.
• The Data Layer (Room database) acts as the persistent storage for user faces, model results, and related entities.
• The Model and Inference Layer utilizes the preprocessed model file (facenet_xnn.pte) and the Executorch native library (libexecutorch.so) to perform computations. This component is integrated via JNI (as indicated by the presence of libexecutorch.so in jniLibs) and is fed with data from the UI/Data layers.
• The Build Layer orchestrates how these components are compiled and packaged.
Architectural Patterns & Design Principles
• Modular design: Separation of UI (activities/fragments), data management (Room and model classes), and business logic (potentially layered through ViewModels and adapters).
• MVVM Pattern: Evidenced by the use of SharedViewModel in the adapter packages and clear separation between UI controllers and data handling.
• Dependency Injection may be implied (even if not explicitly seen) to manage the interactions between these layers.
• Clear separation between native components (inference engine) and managed Android components.
Relevant Technologies and Frameworks
• Android SDK and Material 3 for UI styling.
• Kotlin/Java as main programming languages.
• Room for database abstraction.
• PyTorch Executorch for model handling.
• Gradle as the build tool.