# aprendeingenia/control-de-acceso-facial-con-ia architecture

> Architecture diagram of the GitHub repository aprendeingenia/control-de-acceso-facial-con-ia, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aprendeingenia/control-de-acceso-facial-con-ia
- Repository: https://github.com/aprendeingenia/control-de-acceso-facial-con-ia

## Overview

##### Project Type and Purpose
- This is a standalone full‐stack Python application for “facial access control.”
- It combines a GUI frontend, computer‐vision/AI face‐processing backend, a simple file‐based database, and a hardware interface (serial COM) to actuate a door lock.

##### File Structure
Top‐level directories:
- door_control/ – Entry point for door hardware control (likely wraps serial interface).
- process/ – Core application logic, subdivided into:
– com_interface/ – Serial communication with the door lock device.
– database/ – File‐based storage of user records and face data.
– face_processing/ – AI/vision modules: detection, matching, mesh, signup, login, utilities.
– gui/ – User interface elements and setup images.
- examples/ – Sample usage scripts.
- test/ – Automated test artifacts for face matcher evaluation.
- main.py (and door_control/src/main.py) – Application entry points.
- requirements.txt – Third‐party dependencies (OpenCV, TensorFlow, NumPy, etc.).

##### Important Architectural Patterns
- Modular organization by concern (GUI, Face Processing, Database, COM Interface).
- Sequential data flow: GUI → Face Capture → Face Processing → Database Check → COM Interface → Door Actuation.
- File‐based database (no external DB server) simplifies deployment.
- Pluggable AI models (face_detect_models, face_matcher_models, face_mesh_models) for extensibility.

##### Main Components and Their Responsibilities
1. Frontend GUI
- Modules under process/gui/
- Captures user action (signup vs. login), displays camera feed, buttons, status.
2. Face Processing Backend
- Face detection (face_detect_models/face_detect.py)
- Face mesh (face_mesh_models/face_mesh.py)
- Face feature extraction/matching (face_matcher_models/face_matcher.py)
- Signup and login workflows (face_signup.py, face_login.py)
3. Database Layer
- File‐based storage of user IDs and associated face embeddings (database/users/*.txt, database/faces_path.py, users_path.py).
- Configurable paths (config.py).
4. Hardware Interface
- Serial communication to door lock controller (serial_com.py under com_interface/).
- Wrapped by door_control/src/main.py to provide high‐level “open door” API.
5. Entry Point(s)
- process/main.py orchestrates GUI startup, event loop, and backend interactions.
- examples/example.py shows usage.

##### Relationships and Data Flow
- User interacts with GUI → GUI captures image from camera.
- Image passed to Face Processing:
- Detection → Mesh → Embedding extraction → Matching/Signup.
- Decision (match/no‐match) triggers:
- On success: Database lookup/update, then signal COM interface to unlock door.
- On failure: GUI shows error, no COM signal.
- The COM interface sends serial commands to the hardware.

##### Guidance
a. Components to include:
- GUI Layer (process/gui/)
- Face Processing Layer (face_detect, face_mesh, face_matcher, signup/login modules)
- Database Layer (file store modules)
- COM Interface Layer (serial_com + door_control wrapper)
- External: Camera device, Door‐lock hardware
- Camera → GUI → Face Processing → Database
- Face Processing → (Decision) → COM Interface → Door Lock
- Database ←→ Face Processing (read/write)
c. Patterns:
- Modular, layered architecture
- Pluggable AI model components
- File‐based persistence
d. Technologies:
- Python 3.10, OpenCV, TensorFlow, NumPy
- Serial (pySerial) for COM interface

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% External Devices
    Camera["Camera Device"]:::hardware
    DoorLock["Door Lock Hardware"]:::hardware

    %% GUI Layer
    subgraph "Frontend GUI Layer"
        GUI["GUI Layer"]:::frontend
        ImagePaths["GUI Image Paths Module"]:::frontend
        SetupImages["GUI Setup Images Directory"]:::frontend
    end

    %% Face Processing Layer
    subgraph "Face Processing Backend"
        FaceDetect["Face Detection Module"]:::processing
        FaceMesh["Face Mesh Module"]:::processing
        FaceMatcher["Face Matcher Module"]:::processing
        FaceSignup["Face Signup Workflow"]:::processing
        FaceLogin["Face Login Workflow"]:::processing
        FaceUtils["Face Processing Utilities"]:::processing
    end

    %% Database Layer
    subgraph "Database Layer"
        Config["Database Configuration"]:::db
        FacesPath["Faces Path Helper"]:::db
        UsersPath["Users Path Helper"]:::db
        UserRecords["User Records (face embeddings)"]:::db
    end

    %% COM Interface Layer
    subgraph "Hardware Interface"
        SerialCom["Serial COM Interface"]:::processing
        DoorControlWrapper["Door-Control Wrapper"]:::processing
    end

    %% Entry and Examples
    MainApp["Main Application Entry Point"]:::processing
    ExampleScript["Example Usage Script"]:::processing

    %% Data Flows
    Camera -->|"captures image"| GUI
    GUI -->|"image data"| FaceDetect
    FaceDetect -->|"detections"| FaceMesh
    FaceMesh -->|"mesh output"| FaceMatcher
    FaceMatcher -->|"face embedding"| FaceSignup
    FaceMatcher -->|"face embedding"| FaceLogin
    FaceSignup -->|"new user data"| Config
    FaceLogin -->|"lookup request"| UsersPath
    Config -->|"path info"| FacesPath
    FacesPath --> UserRecords
    UsersPath --> UserRecords
    FaceMatcher -->|"read/write embeddings"| UserRecords
    FaceMatcher -->|"decision"| SerialCom
    SerialCom -->|"serial command"| DoorControlWrapper
    DoorControlWrapper -->|"unlock signal"| DoorLock

    %% Orchestration
    MainApp --> GUI
    MainApp --> FaceDetect
    MainApp --> SerialCom
    ExampleScript --> MainApp

    %% Click Events
    click GUI "https://github.com/aprendeingenia/control-de-acceso-facial-con-ia/tree/main/process/gui/"
    click ImagePaths "https://github.com/aprendeingenia/control-de-acceso-facial-con-ia/blob/main/process/gui/image_paths.py"
    click SetupImages "https://github.com/aprendeingenia/control-de-acceso-facial-con-ia/tree/main/process/gui/setup/images/"
    click FaceDetect "https://github.com/aprendeingenia/control-de-acceso-facial-con-ia/blob/main/process/face_processing/face_detect_models/face_detect.py"
    click FaceMesh "https://github.com/aprendeingenia/control-de-acceso-facial-con-ia/blob/main/process/face_processing/face_mesh_models/face_mesh.py"
    click FaceMatcher "https://github.com/aprendeingenia/control-de-acceso-facial-con-ia/blob/main/process/face_processing/face_matcher_models/face_matcher.py"
    click FaceSignup "https://github.com/aprendeingenia/control-de-acceso-facial-con-ia/blob/main/process/face_processing/face_signup.py"
    click FaceLogin "https://github.com/aprendeingenia/control-de-acceso-facial-con-ia/blob/main/process/face_processing/face_login.py"
    click FaceUtils "https://github.com/aprendeingenia/control-de-acceso-facial-con-ia/blob/main/process/face_processing/face_utils.py"
    click Config "https://github.com/aprendeingenia/control-de-acceso-facial-con-ia/blob/main/process/database/config.py"
    click FacesPath "https://github.com/aprendeingenia/control-de-acceso-facial-con-ia/blob/main/process/database/faces_path.py"
    click UsersPath "https://github.com/aprendeingenia/control-de-acceso-facial-con-ia/blob/main/process/database/users_path.py"
    click UserRecords "https://github.com/aprendeingenia/control-de-acceso-facial-con-ia/blob/main/process/database/users/*.txt"
    click SerialCom "https://github.com/aprendeingenia/control-de-acceso-facial-con-ia/blob/main/process/com_interface/serial_com.py"
    click DoorControlWrapper "https://github.com/aprendeingenia/control-de-acceso-facial-con-ia/blob/main/door_control/src/main.py"
    click MainApp "https://github.com/aprendeingenia/control-de-acceso-facial-con-ia/blob/main/process/main.py"
    click ExampleScript "https://github.com/aprendeingenia/control-de-acceso-facial-con-ia/blob/main/examples/example.py"

    %% Styles
    classDef frontend fill:#E0F7FA,stroke:#006064,color:#000000
    classDef processing fill:#FFF9C4,stroke:#FBC02D,color:#000000
    classDef db fill:#FFE0B2,stroke:#E65100,color:#000000
    classDef hardware fill:#ECEFF1,stroke:#90A4AE,color:#000000
```
