# javipzv/facial-recognition architecture

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

- Interactive diagram: https://gitdiagram.com/javipzv/facial-recognition
- Repository: https://github.com/javipzv/facial-recognition

## Overview

Based on your project’s file tree and README, this system appears to be a multi-agent face recognition application built with Java (using an Eclipse project structure) and complemented by Python modules for image processing. The Java side handles the multi-agent coordination (leveraging the JADE framework) and GUI interactions, while the Python scripts (using libraries like deepface, OpenCV, and tf-keras) are used for computationally intensive tasks such as face detection, embedding calculation, and face comparison.

##### Main Components
- GUI Agent Module – represented by AgenteGUI (src/es/upm/ejemplo/AgenteGUI.java). This component captures user interactions like uploading images, initiating face recognition, and triggering name labeling.
- Broker Agent – implemented in Broker.java (AgenteBroker) and responsible for routing messages and coordinating other agents.
- Detector Agent – represented by AgenteDetector (DetectorCaras.java) which calls the face detection routines; its underlying heavy lifting might be offloaded to the Python script (scripts/detectorCaras.py) that utilizes computer vision libraries.
- Calculator Agent – implemented in CalculadoraEmbeddings.java (AgenteCalculadora) which computes face embeddings, potentially utilizing the Python script (scripts/calculadoraEmbeddings.py) alongside libraries like deepface and tf-keras.
- Comparator Agent – implemented in ComparadorCaras.java (AgenteComparador) for comparing faces based on embeddings; it has a corresponding Python script (scripts/comparadorCaras.py) that performs similar functions.
- Search Agent – realized in BuscadorFotos.java (AgenteBusqueda) that allows searching for images based on recognized names.
- Data & Configuration Resources – JSON files (in the json folder) serve as configuration data or may hold temporary states/configurations for each of these processes. Additionally, the image resources in the img folder and any additional Java-based resources (in src/resources) need to be represented.
- External Libraries/Frameworks – including JADE (for agent-based communication), Jackson (for JSON processing), and the Python libraries (deepface, opencv, tf-keras) that play central roles in image processing.

##### Relationships and Interactions
- The GUI Agent receives user inputs (uploading images, naming faces, searching by name) and passes requests to the Broker Agent.
- The Broker Agent handles inter-agent messaging, directing specific requests to the Detector, Calculator, Comparator, or Search Agents based on the functional needs.
- The Search Agent retrieves images based on processed data.
- Configuration and data files (JSON) can be depicted as shared resources or external data stores used by agents.

##### Architectural Patterns/Design Principles
- Separation of Concerns: Differentiate between the user interface layer (AgenteGUI), processing (other agents and Python modules), and data/configuration management (JSON files and resources).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User Interaction
    UI["User Action"]:::user

    %% Presentation Layer
    subgraph "Presentation Layer"
        AGUI["AgenteGUI"]:::javaAgent
    end

    %% Business/Communication Layer
    subgraph "Business/Communication Layer"
        AB["AgenteBroker"]:::javaAgent
        AD["AgenteDetector"]:::javaAgent
        AC["AgenteCalculadora"]:::javaAgent
        ACO["AgenteComparador"]:::javaAgent
        ABUS["AgenteBusqueda"]:::javaAgent
    end

    %% Image Processing Layer
    subgraph "Image Processing Layer"
        PD["Python Detector"]:::pythonModule
        PC["Python Calculator"]:::pythonModule
        PCO["Python Comparator"]:::pythonModule
    end

    %% Data & Configuration Resources
    subgraph "Data & Configuration"
        JSON["JSON Resources"]:::dataResource
        IMG["Image Resources"]:::dataResource
        RES["Java Resources"]:::dataResource
    end

    %% Connections between layers
    UI -->|"initiates"| AGUI
    AGUI -->|"sends_request"| AB

    AB -->|"routes_detection"| AD
    AB -->|"routes_calculation"| AC
    AB -->|"routes_comparison"| ACO
    AB -->|"routes_search"| ABUS

    AD -->|"calls_detection_module"| PD
    PD -->|"returns_detection"| AD

    AC -->|"calls_calculation_module"| PC
    PC -->|"returns_embeddings"| AC

    ACO -->|"calls_comparison_module"| PCO
    PCO -->|"returns_comparison"| ACO

    %% Agents accessing data/configuration
    AD ---|"config_access"| JSON
    AC ---|"config_access"| JSON
    ACO ---|"config_access"| JSON
    ABUS ---|"uses_resources"| RES
    ABUS ---|"uses_images"| IMG

    %% Classes for styling
    classDef javaAgent fill:#ADD8E6,stroke:#000,stroke-width:1px;
    classDef pythonModule fill:#90EE90,stroke:#000,stroke-width:1px;
    classDef dataResource fill:#FFFACD,stroke:#000,stroke-width:1px;
    classDef user fill:#FFB6C1,stroke:#000,stroke-width:1px;

    %% Click Events
    click AGUI "https://github.com/javipzv/facial-recognition/blob/main/src/es/upm/ejemplo/AgenteGUI.java"
    click AB "https://github.com/javipzv/facial-recognition/blob/main/src/es/upm/ejemplo/Broker.java"
    click AD "https://github.com/javipzv/facial-recognition/blob/main/src/es/upm/ejemplo/DetectorCaras.java"
    click PD "https://github.com/javipzv/facial-recognition/blob/main/scripts/detectorCaras.py"
    click AC "https://github.com/javipzv/facial-recognition/blob/main/src/es/upm/ejemplo/CalculadoraEmbeddings.java"
    click PC "https://github.com/javipzv/facial-recognition/blob/main/scripts/calculadoraEmbeddings.py"
    click ACO "https://github.com/javipzv/facial-recognition/blob/main/src/es/upm/ejemplo/ComparadorCaras.java"
    click PCO "https://github.com/javipzv/facial-recognition/blob/main/scripts/comparadorCaras.py"
    click ABUS "https://github.com/javipzv/facial-recognition/blob/main/src/es/upm/ejemplo/BuscadorFotos.java"
    click JSON "https://github.com/javipzv/facial-recognition/tree/main/json"
    click IMG "https://github.com/javipzv/facial-recognition/tree/main/img"
    click RES "https://github.com/javipzv/facial-recognition/tree/main/src/resources"
```
