# patomax31/verifyme architecture

> Architecture diagram of the GitHub repository patomax31/verifyme, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/patomax31/verifyme
- Repository: https://github.com/patomax31/verifyme

## Overview

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: [`src/application/login_use_case.py`](https://github.com/patomax31/verifyme/blob/main/src/application/login_use_case.py) (Login use case), [`src/application/registration_use_case.py`](https://github.com/patomax31/verifyme/blob/main/src/application/registration_use_case.py) (Register use case), [`desktop_hybrid/app/server.py`](https://github.com/patomax31/verifyme/blob/main/desktop_hybrid/app/server.py) (App layer), [`src/infrastructure/recognition/face_engine.py`](https://github.com/patomax31/verifyme/blob/main/src/infrastructure/recognition/face_engine.py) (Face engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_grp_src_domain["Core domain"]
  node_n_ports["Ports<br/>[ports.py]"]
  node_n_login_uc["Login use case<br/>application use case<br/>[login_use_case.py]"]
  node_n_reg_uc["Register use case<br/>application use case"]
  node_n_auth_svc["Auth service<br/>application service<br/>[auth_service.py]"]
  node_n_reg_svc["Reg service<br/>application service"]
  node_n_config["Config<br/>[config.py]"]
end

subgraph group_grp_src_infra["Infrastructure"]
  node_n_cam["Camera<br/>opencv adapter<br/>[opencv_camera.py]"]
  node_n_face_engine["Face engine<br/>recognition engine<br/>[face_engine.py]"]
  node_n_matcher["Matcher<br/>recognition adapter<br/>[matcher_adapter.py]"]
  node_n_liveness["Liveness<br/>anti-spoofing<br/>[blink_liveness.py]"]
  node_n_sqlite_repo[("SQLite repo<br/>persistence adapter")]
  node_n_pkl_repo["PKL repo<br/>compatibility store<br/>[pkl_repository.py]"]
end

subgraph group_grp_src_hw["Hardware I/O"]
  node_n_audio_mgr["Audio mgr<br/>audio output<br/>[audio_manager.py]"]
  node_n_hw_audio["Audio out<br/>hardware adapter<br/>[audio.py]"]
  node_n_leds["LEDs<br/>status output<br/>[leds.py]"]
  node_n_servo["Servo<br/>actuator<br/>[servomotor.py]"]
  node_n_hw_int["HW integration<br/>device wiring"]
end

subgraph group_grp_legacy["Hybrid app"]
  node_n_hybrid_main["Hybrid main<br/>legacy entrypoint<br/>[main.py]"]
  node_n_hybrid_server["Flask server<br/>web runtime<br/>[flask_server.py]"]
  node_n_hybrid_app["App layer<br/>ui backend<br/>[server.py]"]
  node_n_hybrid_templates["Templates<br/>ui assets<br/>[index.html]"]
end

subgraph group_grp_data["Data store"]
  node_n_db_schema["DB schema<br/>sql schema<br/>[script.sql]"]
  node_n_db_layer[("SQLite layer<br/>database helpers<br/>[connection.py]")]
  node_n_db_mgr["Legacy DB mgr<br/>compat facade<br/>[sqlite_manager.py]"]
  node_n_db_file[("DB files<br/>runtime data")]
  node_n_data_pkl["Model files<br/>runtime data<br/>[est_5.pkl]"]
end

subgraph group_grp_ops["Ops & diagnostics"]
  node_n_tests["Tests<br/>test suite"]
  node_n_diag["Diagnostics<br/>ops scripts<br/>[diagnose_camera.py]"]
  node_n_scripts["DB scripts<br/>ops tooling<br/>[db_queries.py]"]
end

node_n_login_uc -->|"depends on"| node_n_ports
node_n_reg_uc -->|"depends on"| node_n_ports
node_n_auth_svc -->|"shares boundary"| node_n_ports
node_n_reg_svc -->|"shares boundary"| node_n_ports
node_n_login_uc -->|"captures frames"| node_n_cam
node_n_reg_uc -->|"captures frames"| node_n_cam
node_n_login_uc -->|"recognizes"| node_n_face_engine
node_n_reg_uc -->|"encodes face"| node_n_face_engine
node_n_face_engine -->|"matches"| node_n_matcher
node_n_face_engine -->|"checks liveness"| node_n_liveness
node_n_login_uc -->|"reads/writes"| node_n_sqlite_repo
node_n_reg_uc -->|"persists"| node_n_sqlite_repo
node_n_reg_uc -->|"backs up"| node_n_pkl_repo
node_n_sqlite_repo -->|"built on"| node_n_db_layer
node_n_db_layer -->|"implements"| node_n_db_schema
node_n_db_mgr -->|"façade over"| node_n_db_layer
node_n_login_uc -->|"signals"| node_n_audio_mgr
node_n_audio_mgr -->|"drives"| node_n_hw_audio
node_n_hw_int -->|"bundles"| node_n_leds
node_n_hw_int -->|"bundles"| node_n_servo
node_n_hybrid_main -->|"starts"| node_n_hybrid_server
node_n_hybrid_server -->|"uses"| node_n_hybrid_app
node_n_hybrid_server -->|"renders"| node_n_hybrid_templates
node_n_hybrid_app -->|"uses"| node_n_db_mgr
node_n_hybrid_app -->|"captures frames"| node_n_cam
node_n_hybrid_app -->|"recognizes"| node_n_face_engine
node_n_hybrid_app -->|"controls"| node_n_hw_int
node_n_tests -->|"covers"| node_n_login_uc
node_n_tests -->|"covers"| node_n_reg_uc
node_n_tests -->|"covers"| node_n_sqlite_repo
node_n_diag -->|"checks"| node_n_cam
node_n_scripts -->|"queries"| node_n_db_layer
node_n_config -->|"configures"| node_n_cam

click node_n_ports "https://github.com/patomax31/verifyme/blob/main/src/domain/ports.py"
click node_n_login_uc "https://github.com/patomax31/verifyme/blob/main/src/application/login_use_case.py"
click node_n_reg_uc "https://github.com/patomax31/verifyme/blob/main/src/application/registration_use_case.py"
click node_n_auth_svc "https://github.com/patomax31/verifyme/blob/main/src/application/auth_service.py"
click node_n_reg_svc "https://github.com/patomax31/verifyme/blob/main/src/application/registration_service.py"
click node_n_config "https://github.com/patomax31/verifyme/blob/main/src/core/config.py"
click node_n_cam "https://github.com/patomax31/verifyme/blob/main/src/infrastructure/camera/opencv_camera.py"
click node_n_face_engine "https://github.com/patomax31/verifyme/blob/main/src/infrastructure/recognition/face_engine.py"
click node_n_matcher "https://github.com/patomax31/verifyme/blob/main/src/infrastructure/recognition/matcher_adapter.py"
click node_n_liveness "https://github.com/patomax31/verifyme/blob/main/src/infrastructure/recognition/blink_liveness.py"
click node_n_sqlite_repo "https://github.com/patomax31/verifyme/blob/main/src/infrastructure/persistence/sqlite_repository.py"
click node_n_pkl_repo "https://github.com/patomax31/verifyme/blob/main/src/infrastructure/persistence/pkl_repository.py"
click node_n_audio_mgr "https://github.com/patomax31/verifyme/blob/main/src/audio/audio_manager.py"
click node_n_hw_audio "https://github.com/patomax31/verifyme/blob/main/src/hardware/audio.py"
click node_n_leds "https://github.com/patomax31/verifyme/blob/main/src/hardware/leds.py"
click node_n_servo "https://github.com/patomax31/verifyme/blob/main/src/hardware/servomotor.py"
click node_n_hw_int "https://github.com/patomax31/verifyme/blob/main/src/hardware/hardware_integration.py"
click node_n_hybrid_main "https://github.com/patomax31/verifyme/blob/main/desktop_hybrid/main.py"
click node_n_hybrid_server "https://github.com/patomax31/verifyme/blob/main/desktop_hybrid/flask_server.py"
click node_n_hybrid_app "https://github.com/patomax31/verifyme/blob/main/desktop_hybrid/app/server.py"
click node_n_hybrid_templates "https://github.com/patomax31/verifyme/blob/main/desktop_hybrid/templates/index.html"
click node_n_db_schema "https://github.com/patomax31/verifyme/blob/main/database/script.sql"
click node_n_db_layer "https://github.com/patomax31/verifyme/blob/main/database/sqlite/connection.py"
click node_n_db_mgr "https://github.com/patomax31/verifyme/blob/main/database/sqlite_manager.py"
click node_n_db_file "https://github.com/patomax31/verifyme/blob/main/database/face_recognition.db"
click node_n_data_pkl "https://github.com/patomax31/verifyme/blob/main/data/est_5.pkl"
click node_n_tests "https://github.com/patomax31/verifyme/blob/main/src/tests/test_login_use_case.py"
click node_n_diag "https://github.com/patomax31/verifyme/blob/main/diagnose_camera.py"
click node_n_scripts "https://github.com/patomax31/verifyme/blob/main/scripts/db_queries.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_n_ports,node_n_login_uc,node_n_reg_uc,node_n_auth_svc,node_n_reg_svc,node_n_config toneBlue
class node_n_cam,node_n_face_engine,node_n_matcher,node_n_liveness,node_n_sqlite_repo,node_n_pkl_repo toneAmber
class node_n_audio_mgr,node_n_hw_audio,node_n_leds,node_n_servo,node_n_hw_int toneMint
class node_n_hybrid_main,node_n_hybrid_server,node_n_hybrid_app,node_n_hybrid_templates toneRose
class node_n_db_schema,node_n_db_layer,node_n_db_mgr,node_n_db_file,node_n_data_pkl toneIndigo
class node_n_tests,node_n_diag,node_n_scripts toneTeal
```

## Components

### Core domain

Dependency inversion boundary and application-layer orchestration.

- [Ports](https://github.com/patomax31/verifyme/blob/main/src/domain/ports.py): domain ports · Abstract camera, recognition, and repository interfaces used by application services. · `src/domain/ports.py`
- [Login use case](https://github.com/patomax31/verifyme/blob/main/src/application/login_use_case.py): application use case · Coordinates capture, matching, policy checks, and access logging for authentication. · `src/application/login_use_case.py`
- [Register use case](https://github.com/patomax31/verifyme/blob/main/src/application/registration_use_case.py): application use case · Coordinates enrollment flow from face capture to persistence and backup model write. · `src/application/registration_use_case.py`
- [Auth service](https://github.com/patomax31/verifyme/blob/main/src/application/auth_service.py): application service · Authentication rules and login policy helpers. · `src/application/auth_service.py`
- [Reg service](https://github.com/patomax31/verifyme/blob/main/src/application/registration_service.py): application service · Registration policy and enrollment helpers. · `src/application/registration_service.py`
- [Config](https://github.com/patomax31/verifyme/blob/main/src/core/config.py): core config · Shared runtime settings such as camera and system parameters. · `src/core/config.py`

### Infrastructure

Hardware, recognition, camera, and persistence adapters.

- [Camera](https://github.com/patomax31/verifyme/blob/main/src/infrastructure/camera/opencv_camera.py): opencv adapter · OpenCV-based camera capture adapter for Raspberry Pi and desktop execution. · `src/infrastructure/camera/opencv_camera.py`
- [Face engine](https://github.com/patomax31/verifyme/blob/main/src/infrastructure/recognition/face_engine.py): recognition engine · Main face-processing pipeline that turns frames into recognition decisions. · `src/infrastructure/recognition/face_engine.py`
- [Matcher](https://github.com/patomax31/verifyme/blob/main/src/infrastructure/recognition/matcher_adapter.py): recognition adapter · Face comparison and matching adapter used by the engine. · `src/infrastructure/recognition/matcher_adapter.py`
- [Liveness](https://github.com/patomax31/verifyme/blob/main/src/infrastructure/recognition/blink_liveness.py): anti-spoofing · Blink-based liveness check used during capture and login. · `src/infrastructure/recognition/blink_liveness.py`
- [SQLite repo](https://github.com/patomax31/verifyme/blob/main/src/infrastructure/persistence/sqlite_repository.py): persistence adapter · Primary repository implementation for biometric records and access data. · `src/infrastructure/persistence/sqlite_repository.py`
- [PKL repo](https://github.com/patomax31/verifyme/blob/main/src/infrastructure/persistence/pkl_repository.py): compatibility store · 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](https://github.com/patomax31/verifyme/blob/main/src/audio/audio_manager.py): audio output · Sound feedback manager for success, error, startup, and registration cues. · `src/audio/audio_manager.py`
- [Audio out](https://github.com/patomax31/verifyme/blob/main/src/hardware/audio.py): hardware adapter · Hardware-facing audio control used on the Raspberry Pi. · `src/hardware/audio.py`
- [LEDs](https://github.com/patomax31/verifyme/blob/main/src/hardware/leds.py): status output · Visual status indicator output for system and access events. · `src/hardware/leds.py`
- [Servo](https://github.com/patomax31/verifyme/blob/main/src/hardware/servomotor.py): actuator · Door or lock actuator control for access decisions. · `src/hardware/servomotor.py`
- [HW integration](https://github.com/patomax31/verifyme/blob/main/src/hardware/hardware_integration.py): device wiring · 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](https://github.com/patomax31/verifyme/blob/main/desktop_hybrid/main.py): legacy entrypoint · Top-level startup surface for the Flask-backed desktop hybrid app. · `desktop_hybrid/main.py`
- [Flask server](https://github.com/patomax31/verifyme/blob/main/desktop_hybrid/flask_server.py): web runtime · Hybrid presentation server exposing the UI and app routes. · `desktop_hybrid/flask_server.py`
- [App layer](https://github.com/patomax31/verifyme/blob/main/desktop_hybrid/app/server.py): ui backend · Hybrid app helpers for config, networking, runner, checks, and UI coordination. · `desktop_hybrid/app/server.py`
- [Templates](https://github.com/patomax31/verifyme/blob/main/desktop_hybrid/templates/index.html): ui assets · 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](https://github.com/patomax31/verifyme/blob/main/database/script.sql): sql schema · Canonical SQLite schema and migration script. · `database/script.sql`
- [SQLite layer](https://github.com/patomax31/verifyme/blob/main/database/sqlite/connection.py): database helpers · Low-level database modules for connections, migrations, access, reporting, and student/staff queries. · `database/sqlite/connection.py`
- [Legacy DB mgr](https://github.com/patomax31/verifyme/blob/main/database/sqlite_manager.py): compat facade · Monolithic database facade retained for older code paths. · `database/sqlite_manager.py`
- [DB files](https://github.com/patomax31/verifyme/blob/main/database/face_recognition.db): runtime data · Persisted SQLite databases used by the core and hybrid stacks. · `database/face_recognition.db`
- [Model files](https://github.com/patomax31/verifyme/blob/main/data/est_5.pkl): runtime data · Serialized biometric backups stored under data/ and desktop_hybrid/data/. · `data/est_5.pkl`

### Ops & diagnostics

Tests, scripts, and troubleshooting surfaces.

- [Tests](https://github.com/patomax31/verifyme/blob/main/src/tests/test_login_use_case.py): test suite · Unit and integration tests covering auth, registration, SQLite access, and security behavior. · `src/tests/test_login_use_case.py`
- [Diagnostics](https://github.com/patomax31/verifyme/blob/main/diagnose_camera.py): ops scripts · Camera, GPIO, and system verification utilities used during setup and troubleshooting. · `diagnose_camera.py`
- [DB scripts](https://github.com/patomax31/verifyme/blob/main/scripts/db_queries.py): ops tooling · Reporting and query helpers for administrative database inspection. · `scripts/db_queries.py`

## Connections

- 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.
