# devasy23/facerec architecture

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

- Interactive diagram: https://gitdiagram.com/devasy23/facerec
- Repository: https://github.com/devasy23/facerec

## Overview

##### Project type and purpose
- This is a full‑stack face recognition application.
- Purpose: provide a web UI (Flask) for users to register, update, delete, and view face entries, backed by a FastAPI service that handles image processing (DeepFace), embedding extraction, and CRUD operations in MongoDB.
- Offline “Model‑Training” notebooks/scripts train and evaluate embedding models; a pre‑trained model is stored under `Model/`.

##### File structure
- Top‑level directories:
- API/ – the FastAPI service code, routes, DB connector, utilities
- FaceRec/ – the Flask application, static assets, HTML templates
- Model‑Training/ – Jupyter notebooks and Python scripts for training and evaluation
- Model/ – pretrained embedding model
- testing/ – pytest tests for API endpoints and database logic
- docs/ – Sphinx documentation
- Key files:
- main.py – entry point that spins up both Flask and FastAPI apps
- requirements.txt – combined dependencies (Flask, FastAPI, DeepFace, pymongo, etc.)
- API/database.py – MongoDB connection setup
- API/route.py – FastAPI endpoints for create/read/update/delete operations
- CI/CD and quality: .github/workflows, .gitlab-ci.yml, sonar-config, pre‑commit hooks.

##### README for additional insights
- Describes real‑time recognition via DeepFace, metadata management, and scalable architecture.
- Lists function flows (create_new_faceEntry, Data, update, read, delete).
- Database schema for faceEntries collection.

##### Essential architectural elements
1) UI lane (Browser ↔ Flask)
2) Backend lane (Flask ↔ FastAPI ↔ DeepFace ↔ MongoDB)
- Test suite as a note, showing “testing/” hitting API endpoints (optional)

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interface Layer"
        Browser["Browser/UI"]:::frontend
    end

    subgraph "Flask UI Server"
        Flask["Flask Web App"]:::frontend
    end

    subgraph "Entrypoint"
        Main["main.py"]:::deps
    end

    subgraph "Backend Services"
        subgraph "FastAPI Service"
            Init["API Package Init"]:::backend
            Route["FastAPI Endpoints"]:::backend
            DBconn["DB Connector"]:::backend
            Utils["Face Processing Module"]:::backend
        end
        DB["MongoDB"]:::db
    end

    subgraph "Offline Components"
        Training["Model Training Pipeline"]:::offline
        ModelStore["Pretrained Model Store"]:::model
    end

    subgraph "Support"
        Tests["Test Suite"]:::testing
        Docs["Documentation"]:::docs
        Deps["Project Dependencies"]:::deps
    end

    Browser -->|"HTTP (HTML/JS)"| Flask
    Main -->|starts| Flask
    Main -->|starts| Init

    Flask -->|"REST JSON"| Route
    Init -->|registers| Route
    Init -->|connects| DBconn
    Init -->|loads utils| Utils

    Route -->|"invoke DeepFace"| Utils
    Utils -->|"returns embeddings"| Route
    Route -->|"CRUD JSON"| DB
    DB -->|"data"| Route

    Training -->|"updates model"| ModelStore
    ModelStore -.->|"loaded by utils"| Utils

    Tests -->|tests endpoints| Route
    Docs -->|documents| Flask
    Deps -->|installed by| Main

    classDef frontend fill:#E3F2FD,stroke:#90CAF9,color:#0D47A1,stroke-width:2px;
    classDef backend fill:#F1F8E9,stroke:#AED581,color:#33691E,stroke-width:2px;
    classDef db fill:#FFF3E0,stroke:#FFB74D,color:#E65100,stroke-width:2px,shape:cylinder;
    classDef model fill:#EDE7F6,stroke:#9575CD,color:#4A148C,stroke-width:2px;
    classDef offline fill:#ECEFF1,stroke:#78909C,color:#263238,stroke-width:2px,shape:oval;
    classDef testing fill:#FFEBEE,stroke:#E57373,color:#B71C1C,stroke-width:2px;
    classDef docs fill:#FFFDE7,stroke:#FFF176,color:#F57F17,stroke-width:2px;
    classDef deps fill:#ECEFF1,stroke:#B0BEC5,color:#263238,stroke-width:2px;

    click Browser "https://github.com/devasy23/facerec/tree/main/FaceRec/static/"
    click Flask "https://github.com/devasy23/facerec/tree/main/FaceRec/app/"
    click Main "https://github.com/devasy23/facerec/blob/main/main.py"
    click Init "https://github.com/devasy23/facerec/blob/main/API/__init__.py"
    click Route "https://github.com/devasy23/facerec/blob/main/API/route.py"
    click DBconn "https://github.com/devasy23/facerec/blob/main/API/database.py"
    click Utils "https://github.com/devasy23/facerec/blob/main/API/utils.py"
    click ModelStore "https://github.com/devasy23/facerec/blob/main/Model/embedding_trial3.h5"
    click Training "https://github.com/devasy23/facerec/tree/main/Model-Training/"
    click Tests "https://github.com/devasy23/facerec/tree/main/testing/"
    click Docs "https://github.com/devasy23/facerec/tree/main/docs/"
    click Deps "https://github.com/devasy23/facerec/blob/main/requirements.txt"
```
