How patomax31/verifyme works
1. What this repo is
IdentifyMe is a Python-based biometric access-control system for a Raspberry Pi 5. Its core function is facial registration and login, with persistence in SQLite and a backup .pkl model format. The repository contains both a newer modular architecture under src/ and an older/hybrid app under desktop_hybrid/.
2. Main runtime entry surfaces
The system can be started as a CLI-style workflow for registration/login, and also has a Flask-backed UI in desktop_hybrid/ (main.py, flask_server.py, templates/, static/). The hybrid app looks like a separate presentation layer, while the src/ tree is the cleaner backend architecture being adopted progressively.
3. Layered architecture in src/
The src/ tree is split into:
- src/domain/: interface definitions / ports
- src/application/: use cases and services
- src/infrastructure/: camera, recognition, persistence adapters
- src/hardware/: Raspberry Pi output devices and integration
- src/core/: shared config
This is the key boundary structure for diagramming the system.
4. Business flow orchestration
src/application/login_use_case.py and src/application/registration_use_case.py are the main orchestrators. They coordinate camera input, face matching, persistence, and access logging without depending directly on concrete hardware or storage implementations.
5. Domain boundary
src/domain/ports.py defines the abstractions that application services depend on. This keeps recognition, camera, and repository implementations swappable and is the main dependency inversion boundary in the system.
6. Camera subsystem
src/infrastructure/camera/opencv_camera.py is the camera adapter. Camera behavior is controlled through src/core/config.py and environment variables like CAMERA_INDEX, CAMERA_PROFILE, resolution, and FPS. The README indicates Raspberry Pi-specific camera support is expected via system libraries, so this subsystem is hardware-sensitive.
7. Face recognition pipeline
src/infrastructure/recognition/ contains the recognition stack:
- face_engine.py: main recognition logic
- matcher_adapter.py: matching adapter
- blink_liveness.py: liveness / anti-spoofing check
A separate face_recognition_tools/face_model.py suggests model/encoding handling. The data flow is frame capture → face processing/encoding → match decision → access outcome.
8. Persistence and data model
Persistence is primarily SQLite, implemented in src/infrastructure/persistence/sqlite_repository.py. There is also pkl_repository.py for compatibility with the older backup format. The database layer is further decomposed under database/sqlite/ into connection, migrations, student queries, access logging, encoding, paths, and reporting. The schema is defined in database/script.sql, with runtime DB files in database/ and desktop_hybrid/database/.
9. Legacy compatibility layer
database/sqlite_manager.py acts as a façade for older code paths. This is important architecturally because the repo is transitioning from a monolithic database access style to the modular src/ repository adapter, while still preserving backward compatibility.
10. Hardware feedback and edge integration
src/hardware/ manages Raspberry Pi outputs and diagnostics:
- audio.py and src/audio/audio_manager.py for sound feedback
- leds.py for visual status
- servomotor.py for door/actuator control
- hardware_integration.py for wiring the devices together
This is the boundary where software decisions become physical actions.
11. Registration vs login data flow
Registration captures a new face plus group metadata, stores the biometric encoding in SQLite, and also writes a backup .pkl file under data/. Login loads known active students from SQLite, compares the live encoding, applies tolerance/cooldown rules, then records access history. The README indicates SQLite is the primary source now, with PKL kept for fallback compatibility.
12. Hybrid web UI subsystem
desktop_hybrid/ is a self-contained presentation stack with Flask (app/server.py, flask_server.py), config/network/ui helpers, HTML templates, CSS, and JavaScript. It likely serves as a GUI wrapper around the same recognition/persistence concepts, and should be drawn as a separate interface layer rather than part of the core domain.
13. Testing, diagnostics, and operations
src/tests/ contains unit and integration tests for auth, registration, SQLite access, and security behavior. There are also Raspberry Pi and camera diagnostics (src/hardware/test_*, diagnose_camera.py, test_camera_simple.py, test_open_camera.py), plus admin/reporting tooling in scripts/db_queries.py and documentation/scripts under docs/ for setup and database queries. These support deployment and validation, especially on Raspberry Pi and Windows.
Main entry points: login_use_case.py Login use case · registration_use_case.py Register use case · server.py App layer · face_engine.py Face engine
Components 29
Core domain
Dependency inversion boundary and application-layer orchestration.
- Ports · Abstract camera, recognition, and repository interfaces used by application services.
src/domain/ports.py - Login use case · Coordinates capture, matching, policy checks, and access logging for authentication.
src/application/login_use_case.py - Register use case · Coordinates enrollment flow from face capture to persistence and backup model write.
src/application/registration_use_case.py - Auth service · Authentication rules and login policy helpers.
src/application/auth_service.py - Reg service · Registration policy and enrollment helpers.
src/application/registration_service.py - Config · Shared runtime settings such as camera and system parameters.
src/core/config.py
Infrastructure
Hardware, recognition, camera, and persistence adapters.
- Camera · OpenCV-based camera capture adapter for Raspberry Pi and desktop execution.
src/infrastructure/camera/opencv_camera.py - Face engine · Main face-processing pipeline that turns frames into recognition decisions.
src/infrastructure/recognition/face_engine.py - Matcher · Face comparison and matching adapter used by the engine.
src/infrastructure/recognition/matcher_adapter.py - Liveness · Blink-based liveness check used during capture and login.
src/infrastructure/recognition/blink_liveness.py - SQLite repo · Primary repository implementation for biometric records and access data.
src/infrastructure/persistence/sqlite_repository.py - PKL repo · Legacy backup model format kept for compatibility and fallback use.
src/infrastructure/persistence/pkl_repository.py
Hardware I/O
Raspberry Pi outputs and device integration.
- Audio mgr · Sound feedback manager for success, error, startup, and registration cues.
src/audio/audio_manager.py - Audio out · Hardware-facing audio control used on the Raspberry Pi.
src/hardware/audio.py - LEDs · Visual status indicator output for system and access events.
src/hardware/leds.py - Servo · Door or lock actuator control for access decisions.
src/hardware/servomotor.py - HW integration · Bundles output devices into a single Raspberry Pi integration layer.
src/hardware/hardware_integration.py
Hybrid app
Older Flask-backed presentation stack kept alongside the modular backend.
- Hybrid main · Top-level startup surface for the Flask-backed desktop hybrid app.
desktop_hybrid/main.py - Flask server · Hybrid presentation server exposing the UI and app routes.
desktop_hybrid/flask_server.py - App layer · Hybrid app helpers for config, networking, runner, checks, and UI coordination.
desktop_hybrid/app/server.py - Templates · HTML templates and partials for the desktop hybrid interface.
desktop_hybrid/templates/index.html
Data store
SQLite schema, repository helpers, and backup face-model artifacts.
- DB schema · Canonical SQLite schema and migration script.
database/script.sql - SQLite layer · Low-level database modules for connections, migrations, access, reporting, and student/staff queries.
database/sqlite/connection.py - Legacy DB mgr · Monolithic database facade retained for older code paths.
database/sqlite_manager.py - DB files · Persisted SQLite databases used by the core and hybrid stacks.
database/face_recognition.db - Model files · Serialized biometric backups stored under data/ and desktop_hybrid/data/.
data/est_5.pkl
Ops & diagnostics
Tests, scripts, and troubleshooting surfaces.
- Tests · Unit and integration tests covering auth, registration, SQLite access, and security behavior.
src/tests/test_login_use_case.py - Diagnostics · Camera, GPIO, and system verification utilities used during setup and troubleshooting.
diagnose_camera.py - DB scripts · Reporting and query helpers for administrative database inspection.
scripts/db_queries.py
Connections 33
- Login use case → Ports: depends on · Login use case uses abstract ports rather than concrete adapters.
- Register use case → Ports: depends on · Registration use case is built against the domain boundary.
- Auth service → Ports: shares boundary · Authentication service follows the same decoupled contracts.
- Reg service → Ports: shares boundary · Registration service also relies on abstractions.
- Login use case → Camera: captures frames · Login workflow acquires live images from the camera adapter.
- Register use case → Camera: captures frames · Enrollment workflow starts with camera input.
- Login use case → Face engine: recognizes · Login delegates face processing and matching to the engine.
- Register use case → Face engine: encodes face · Registration uses the recognition pipeline to build enrollment encodings.
- Face engine → Matcher: matches · The engine delegates similarity decisions to the matcher adapter.
- Face engine → Liveness: checks liveness · Anti-spoofing is part of the recognition pipeline.
- Login use case → SQLite repo: reads/writes · Login loads active identities and records access history.
- Register use case → SQLite repo: persists · Registration stores new biometric records in SQLite.
- Register use case → PKL repo: backs up · Enrollment also writes the compatibility backup model.
- SQLite repo → SQLite layer: built on · Repository adapter sits on top of the database helper layer.
- SQLite layer → DB schema: implements · Helper modules reflect the canonical schema and migrations.
- Legacy DB mgr → SQLite layer: façade over · Legacy calls are routed through the newer SQLite helper modules.
- Login use case → Audio mgr: signals · Use case triggers audio feedback for access outcomes.
- Audio mgr → Audio out: drives · Audio manager talks to hardware output primitives.
- HW integration → LEDs: bundles · Integration layer manages visual status output.
- HW integration → Servo: bundles · Integration layer manages access actuator control.
- Hybrid main → Flask server: starts · Desktop hybrid entrypoint boots the Flask server.
- Flask server → App layer: uses · Server depends on the app layer for routing and coordination.
- Flask server → Templates: renders · Flask UI is rendered from templates and partials.
- App layer → Legacy DB mgr: uses · Legacy app stack talks to the compatibility database facade.
- App layer → Camera: captures frames · Hybrid workflow can also use camera capture.
- App layer → Face engine: recognizes · Hybrid UI shares the same recognition concepts.
- App layer → HW integration: controls · Hybrid interactions can trigger physical outputs.
- Tests → Login use case: covers · Tests validate the authentication use case.
- Tests → Register use case: covers · Tests validate the registration use case.
- Tests → SQLite repo: covers · Integration tests exercise SQLite persistence.
- Diagnostics → Camera: checks · Diagnostics verify camera availability and behavior.
- DB scripts → SQLite layer: queries · Administrative scripts inspect database content and reports.
- Config → Camera: configures · Camera behavior is driven by shared runtime settings.