# ankithac46/face-sketch-construction-and-recognition-for-forensic architecture

> Architecture diagram of the GitHub repository ankithac46/face-sketch-construction-and-recognition-for-forensic, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-12). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/ankithac46/face-sketch-construction-and-recognition-for-forensic
- Repository: https://github.com/ankithac46/face-sketch-construction-and-recognition-for-forensic

## Overview

##### Project type and purpose
- This is a full‐stack web application for forensic face‐sketch construction and recognition.
- It provides a drag‐and‐drop UI (frontend) to assemble facial features into a composite sketch and a backend service (Flask + Python) that runs face‐recognition algorithms against a criminal database.

##### File structure
- Top level:
- Project Snapshots (screenshots folder)
- README.md
- static/ (all JS/CSS/images/assets)
– assets/ (SVG/PNG elements: eyes, nose, etc.)
– photos/, uploads/ (runtime image storage)
- templates/ (Jinja2 HTML views: index, start, construct, result)
- Missing from tree but implied: app.py (Flask entry point), a models/ or database module, and ML helper scripts.
- MVC-style split:
- View layer: templates + static files
- Controller layer: Flask routes in app.py
- Model layer: database schema + face_recognition logic

##### README for additional insights
- Frontend: JavaScript drag‐and‐drop assembly
- Backend: Python Flask for HTTP API and orchestration
- ML: `face_recognition`, OpenCV, NumPy, Pillow for encoding and matching
- Database: SQLite or PostgreSQL storing criminal face encodings and metadata

##### Main components & their interactions
a. Components
– Client Browser (UI)
– Static Asset Server (serves HTML, CSS, JS, feature‐images)
– Flask Application
– Face-Recognition Module (third-party libraries)
– Database (SQLite/PostgreSQL)
– File Storage (static/uploads, static/photos)
b. Relationships/Interactions
1. User opens index.html → drag-and-drop UI loads feature assets.
2. On “Submit Sketch” action, frontend sends POST (multipart/form‐data or base64 image) to Flask route.
3. Flask receives image, saves to static/uploads, passes it to face_recognition pipeline.
4. Pipeline loads stored face encodings from DB, compares distances, picks top matches.
5. Flask queries DB for matching records, renders result.html with thumbnails + similarity scores.
c. Architectural patterns/design principles
– Layered architecture (Presentation → Application → Data)
– Separation of concerns: UI logic in JS/HTML, backend logic in Python, ML logic in a dedicated module, persistence in DB
– MVC-ish:
- View = templates + static
- Controller = Flask routes
- Model = DB + encoding loader
– Pluggable assets: facial feature libraries are interchangeable
d. Key technologies/frameworks/libraries
– Flask
– face_recognition (dlib under the hood)
– OpenCV, NumPy, Pillow (image processing)
– SQLite/PostgreSQL (via SQLAlchemy or raw)
– JavaScript drag-and-drop libraries (native HTML5 or a small helper)
– Jinja2 templating

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Presentation Layer
    subgraph "Presentation Layer"
        direction TB
        Browser["Client Browser"]:::frontend
        subgraph "HTML Templates"
            direction TB
            Index["index.html"]:::frontend
            Start["start.html"]:::frontend
            Construct["Face_Construct.html"]:::frontend
            Result["result.html"]:::frontend
        end
        subgraph "Static Assets"
            direction TB
            Assets["Feature Assets"]:::frontend
            Eyebrows["assets/eyebrows"]:::frontend
            Eyes["assets/eyes"]:::frontend
            Hair["assets/hair"]:::frontend
            Head["assets/head"]:::frontend
            Lips["assets/lips"]:::frontend
            Mustache["assets/mustache"]:::frontend
            Nose["assets/nose"]:::frontend
            More["assets/more"]:::frontend
        end
    end

    %% Application Layer
    subgraph "Application Layer"
        direction TB
        FlaskApp["Flask Application"]:::backend
        subgraph "API / Routes"
            direction TB
            Routes["app.py (Routes)"]:::backend
        end
        subgraph "Sketch Construction Service"
            direction TB
            SketchService["Image Assembly Service"]:::backend
        end
        subgraph "Recognition Service"
            direction TB
            MLModule["face_recognition Module"]:::ml
            OpenCV["OpenCV / NumPy / Pillow"]:::ml
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        DB["SQLite / PostgreSQL"]:::data
        subgraph "File Storage"
            direction TB
            Uploads["static/uploads"]:::data
            Photos["static/photos"]:::data
        end
    end

    %% Project Documentation
    Docs["Project Snapshots"]:::data
    Readme["README.md"]:::data

    %% Connections
    Browser -->|"loads UI"| Index
    Browser -->|"loads UI"| Assets
    Index -->|"fetch assets"| Eyebrows
    Index -->|"fetch assets"| Eyes
    Index -->|"fetch assets"| Hair
    Index -->|"fetch assets"| Head
    Index -->|"fetch assets"| Lips
    Index -->|"fetch assets"| Mustache
    Index -->|"fetch assets"| Nose
    Index -->|"fetch assets"| More

    Browser -->|"POST sketch"| Routes
    Routes -->|"save image"| Uploads
    Routes -->|"call assemble"| SketchService
    Routes -->|"call recognize"| MLModule
    MLModule -->|"uses libs"| OpenCV
    MLModule -->|"query encodings"| DB
    MLModule -->|"store match results"| DB
    Routes -->|"render result"| Result

    %% Click Events
    click Index "https://github.com/ankithac46/face-sketch-construction-and-recognition-for-forensic/blob/main/templates/index.html"
    click Start "https://github.com/ankithac46/face-sketch-construction-and-recognition-for-forensic/blob/main/templates/start.html"
    click Construct "https://github.com/ankithac46/face-sketch-construction-and-recognition-for-forensic/blob/main/templates/Face_Construct.html"
    click Result "https://github.com/ankithac46/face-sketch-construction-and-recognition-for-forensic/blob/main/templates/result.html"
    click Eyebrows "https://github.com/ankithac46/face-sketch-construction-and-recognition-for-forensic/tree/main/static/assets/eyebrows"
    click Eyes "https://github.com/ankithac46/face-sketch-construction-and-recognition-for-forensic/tree/main/static/assets/eyes"
    click Hair "https://github.com/ankithac46/face-sketch-construction-and-recognition-for-forensic/tree/main/static/assets/hair"
    click Head "https://github.com/ankithac46/face-sketch-construction-and-recognition-for-forensic/tree/main/static/assets/head"
    click Lips "https://github.com/ankithac46/face-sketch-construction-and-recognition-for-forensic/tree/main/static/assets/lips"
    click Mustache "https://github.com/ankithac46/face-sketch-construction-and-recognition-for-forensic/tree/main/static/assets/mustache"
    click Nose "https://github.com/ankithac46/face-sketch-construction-and-recognition-for-forensic/tree/main/static/assets/nose"
    click More "https://github.com/ankithac46/face-sketch-construction-and-recognition-for-forensic/tree/main/static/assets/more"
    click Uploads "https://github.com/ankithac46/face-sketch-construction-and-recognition-for-forensic/tree/main/static/uploads"
    click Photos "https://github.com/ankithac46/face-sketch-construction-and-recognition-for-forensic/tree/main/static/photos"

    %% Styles
    classDef frontend fill:#BBDEFB,stroke:#1E88E5,color:#0D47A1
    classDef backend fill:#C8E6C9,stroke:#43A047,color:#1B5E20
    classDef ml fill:#E1BEE7,stroke:#8E24AA,color:#4A148C
    classDef data fill:#FFE082,stroke:#FB8C00,color:#E65100
```
