# tangnguyendeveloper/face_identify architecture

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

- Interactive diagram: https://gitdiagram.com/tangnguyendeveloper/face_identify
- Repository: https://github.com/tangnguyendeveloper/face_identify

## Overview

##### Project Type and Purpose
- This is a C++ full-stack application for real-time face detection and embedding extraction.
- It comprises a processing backend (MTCNN + ResNetv1 TFLite), a storage layer (self-developed embedding DB), and a lightweight web UI for monitoring.

##### File Structure
- Top-level directories:
- src/       – implementation folders: camera (RTSP/Internal), config, mtcnn detector, embedding
- models/    – Caffe MTCNN model files (.prototxt/.caffemodel) and the ResNetv1 embedding model (.tflite)
- etc/       – configuration files for camera and models
- embedding_db.db – SQLite DB for storing face embeddings
- webconsole/– static web UI (index.html, root.js, styles.css)

##### Architectural Patterns
- Modules are loosely coupled via interfaces (e.g. ICamera, IConfig, IDetector, IEmbedder).
- Configuration-driven initialization from etc/*.conf.
- Streaming pipeline: camera → detector → embedder → storage/UI.
- Web UI served by the backend over a lightweight HTTP/WebSocket.

##### Main Components & Their Interactions
a. Input Layer
- Camera Module (two implementations):
- InternalCamera (src/camera/internal_camera.cpp)
- RTSPCamera (src/camera/rtsp_camera.cpp)
- Configured via etc/camera_and_models.conf
b. Detection Layer
- MTCNN Detector (src/mtcnn/*) using Caffe models (models/det1–3)
c. Preprocessing & Embedding Layer
- Face alignment/cropping → ResNetv1 Embedding Extractor (face_embedding.cpp)
- Model is TensorFlow→TFLite converted (models/embedding_20180402-114759.tflite)
d. Storage Layer
- Self-developed embeddingDB (SQLite, embedding_db.db) with C++ wrapper (embedding_db_impl.hpp)
e. Presentation & Logging
- logging.hpp records events
- stream.hpp pushes frames and data to webconsole
f. Web UI
- index.html + root.js + styles.css serve live video and embedding info

##### Technologies & Frameworks
- CMake (build orchestrator)
- OpenCV (image I/O & drawing)
- TensorFlow Lite (inference engine for ResNetv1 embedding)
- Caffe (runtime for MTCNN detector)
- SQLite (embedding_db.db)
- Embedded HTTP/WebSocket server (from stream.hpp)
- JavaScript/HTML/CSS for webconsole

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Configuration"
        Config["Configuration\n(etc/camera_and_models.conf)"]:::config
    end

    subgraph "Input Layer"
        InternalCam["Internal Camera"]:::input
        RTSPCam["RTSP Camera"]:::input
    end

    Config --> InternalCam
    Config --> RTSPCam

    subgraph "Detection Layer"
        Detector["MTCNN Detector"]:::process
        DetModels["Caffe MTCNN Models"]:::process
    end

    InternalCam --> Detector
    RTSPCam --> Detector
    Detector --> DetModels

    subgraph "Embedding Layer"
        Embedder["ResNetv1 Embedding Extractor"]:::process
        EmbedModel["TFLite Embedding Model"]:::process
    end

    DetModels --> Embedder
    Embedder --> EmbedModel

    subgraph "Storage Layer"
        DB["EmbeddingDB (SQLite)"]:::storage
    end

    EmbedModel --> DB

    subgraph "Presentation & Streaming"
        Renderer["Drawing & Streaming\n(draw.hpp, logging.hpp, stream.hpp)"]:::ui
    end

    DB --> Renderer

    subgraph "Web UI"
        WebUI["Web Console\n(index.html, root.js, styles.css)"]:::ui
    end

    Renderer --> WebUI

    %% Click Events
    click InternalCam "https://github.com/tangnguyendeveloper/face_identify/blob/main/src/camera/internal_camera.cpp"
    click RTSPCam "https://github.com/tangnguyendeveloper/face_identify/blob/main/src/camera/rtsp_camera.cpp"
    click Config "https://github.com/tangnguyendeveloper/face_identify/blob/main/etc/camera_and_models.conf"
    click Detector "https://github.com/tangnguyendeveloper/face_identify/blob/main/src/mtcnn/detector.cpp"
    click Embedder "https://github.com/tangnguyendeveloper/face_identify/blob/main/src/embedding/face_embedding.cpp"
    click EmbedModel "https://github.com/tangnguyendeveloper/face_identify/blob/main/models/embedding_20180402-114759.tflite"
    click DB "https://github.com/tangnguyendeveloper/face_identify/blob/main/src/embedding/embedding_db_impl.hpp"
    click Renderer "https://github.com/tangnguyendeveloper/face_identify/blob/main/app/stream.hpp"
    click WebUI "https://github.com/tangnguyendeveloper/face_identify/blob/main/webconsole/index.html"

    %% Styles
    classDef input fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef process fill:#90EE90,stroke:#333,stroke-width:1px
    classDef storage fill:#FFA500,stroke:#333,stroke-width:1px
    classDef ui fill:#DDA0DD,stroke:#333,stroke-width:1px
    classDef config fill:#D3D3D3,stroke:#333,stroke-width:1px
```
