# mt-photos/mt-photos-deepface architecture

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

- Interactive diagram: https://gitdiagram.com/mt-photos/mt-photos-deepface
- Repository: https://github.com/mt-photos/mt-photos-deepface

## Overview

##### Project type and purpose
- This is a containerized, standalone REST-style microservice for face detection and feature extraction.
- It’s built in Python (FastAPI/Uvicorn) and wraps the DeepFace library to expose two endpoints: `/check` (health/auth check) and `/represent` (face analysis).

##### File structure
- Top-level files:
- `server.py` – FastAPI application entrypoint defining routes and orchestrating DeepFace.
- `requirements.txt` – Python dependencies (FastAPI, Uvicorn, DeepFace, etc.).
- `.env.example` – template for environment variables (`API_AUTH_KEY`, `DETECTOR_BACKEND`, `RECOGNITION_MODEL`).
- `Dockerfile` – container image build instructions.
- `.github/workflows/build.yml` – CI pipeline for automated build/test.
- `sources.list` – apt sources for base image.
- No separate “frontend” or “lib” directories: the service is a single Python monolith packaged in Docker.

##### README for additional insights
- The service allows configurable detection backends (retinaface, opencv, etc.) and recognition models (Facenet512, ArcFace, etc.) via env variables.
- It supports mounting a host `/models` volume for faster loading of pretrained weights.
- Usage covers Docker pull/run commands and local Python startup.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client
    Client["Client (curl, mobile app)"]:::client

    %% Service Container
    subgraph "Dockerized Service" 
        direction TB
        Ingress["FastAPI App\n(Uvicorn HTTP Ingress)"]:::runtime
        Auth["Auth Layer\n(API_AUTH_KEY Middleware)"]:::runtime
        Core["Recognition Engine\n(DeepFace Orchestration)"]:::runtime
        subgraph "DeepFace Components"
            direction TB
            Detector["Detector Backend\n(retinaface, MTCNN, etc.)"]:::runtime
            Recognizer["Recognition Model\n(Facenet512, ArcFace, etc.)"]:::runtime
        end
        EnvConfig["Env Configuration\n(.env variables)"]:::config
    end

    %% Storage
    Models["Model Storage\n(Container /models Volume)"]:::storage

    %% CI/CD Pipeline
    subgraph "CI/CD & Deployment"
        direction TB
        CI["GitHub Actions\n(build.yml)"]:::pipeline
        Registry["Container Registry\n(Docker Hub)"]:::pipeline
        Deployment["Deployment\n(Container Runtime)"]:::pipeline
    end

    %% File & Metadata
    Dependencies["Dependencies\n(requirements.txt)"]:::config
    Metadata["README.md"]:::config
    GitIgnore[".gitignore"]:::config
    ContainerFiles["Dockerfile & sources.list"]:::config

    %% Connections
    Client -->|HTTP POST /check, /represent| Ingress
    Ingress -->|verify API key| Auth
    Auth -->|call| Core
    Core -->|load detector| Detector
    Core -->|load model| Recognizer
    Detector -->|read weights| Models
    Recognizer -->|read weights| Models
    Core -->|return JSON| Ingress
    Ingress -->|HTTP Response| Client

    CI -->|build & test| ContainerFiles
    CI -->|push image| Registry
    Registry -->|deploy image| Deployment

    %% Click Events
    click Ingress "https://github.com/mt-photos/mt-photos-deepface/blob/master/server.py"
    click Auth "https://github.com/mt-photos/mt-photos-deepface/blob/master/server.py"
    click Core "https://github.com/mt-photos/mt-photos-deepface/blob/master/server.py"
    click Detector "https://github.com/mt-photos/mt-photos-deepface/blob/master/server.py"
    click Recognizer "https://github.com/mt-photos/mt-photos-deepface/blob/master/server.py"
    click Dependencies "https://github.com/mt-photos/mt-photos-deepface/blob/master/requirements.txt"
    click EnvConfig "https://github.com/mt-photos/mt-photos-deepface/blob/master/.env.example"
    click ContainerFiles "https://github.com/mt-photos/mt-photos-deepface/tree/master/Dockerfile"
    click ContainerFiles "https://github.com/mt-photos/mt-photos-deepface/blob/master/sources.list"
    click CI "https://github.com/mt-photos/mt-photos-deepface/blob/master/.github/workflows/build.yml"
    click Metadata "https://github.com/mt-photos/mt-photos-deepface/blob/master/README.md"
    click GitIgnore "https://github.com/mt-photos/mt-photos-deepface/blob/master/.gitignore"

    %% Styles
    classDef runtime fill:#D6EAF8,stroke:#3498DB,color:#1B4F72,stroke-width:1px;
    classDef storage fill:#D5F5E3,stroke:#27AE60,color:#145A32,stroke-width:1px;
    classDef pipeline fill:#FCF3CF,stroke:#F1C40F,color:#7D6608,stroke-width:1px;
    classDef client fill:#F2F3F4,stroke:#7B7D7D,color:#1C2833,stroke-width:1px;
    classDef config fill:#FADBD8,stroke:#E74C3C,color:#641E16,stroke-width:1px;
```
