# iitzirfan/deep-fake architecture

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

- Interactive diagram: https://gitdiagram.com/iitzirfan/deep-fake
- Repository: https://github.com/iitzirfan/deep-fake

## Overview

##### Project Type and Purpose
- This is a full-stack deep learning application for detecting deepfake videos.
- It consists of two main workflows:
a) The training pipeline (data ingestion, preprocessing, model training, evaluation, weight storage).
b) The inference service or web interface (serving predictions via a simple backend + browser UI).

##### Key Directories & Files
- data/: raw video folders (real/fake), entry point for the dataset.
- dataset.py + src/data_preprocessing.py: data I/O and preprocessing logic.
- train.py + src/cnn_model.py + src/config.py + src/evaluate.py: orchestrate training, model definition, hyper-parameters, evaluation metrics.
- best_model.h5 (implied by README): stores trained weights.
- frontend/app.py: lightweight web server (likely Flask) exposing an endpoint for video uploads and predictions.
- src/utils.py: shared utilities (e.g., loading model, image/video transforms).
- notebooks/: exploratory analysis and prototyping.

##### Architectural Patterns & Dependencies
- Layered architecture:
- Data layer (raw + processed) →
- Processing layer (dataset, preprocessing) →
- Model layer (training + evaluation) →
- Persistence layer (model weights file) →
- Service/API layer (inference endpoints) →
- Presentation layer (web UI).
- Technology stack: Python 3.7+, TensorFlow/Keras (implied by .h5), Flask or similar for frontend, Jupyter for notebooks.

##### Main Components
A. Data Source
- raw dataset directories (data/raw/real, data/raw/fake)
B. Data Processing Pipeline
- dataset.py, src/data_preprocessing.py
- outputs processed tensors/batches
C. Training Pipeline
- train.py orchestrates: loads config.py → imports cnn_model.py → trains model → calls evaluate.py → saves best_model.h5
D. Model Store
- best_model.h5 (artifact repository or local disk)
E. Inference Service
- frontend/app.py loads best_model.h5 via src/utils.py → exposes REST endpoint (/predict)
F. Web UI / Client
- Browser sends uploaded video to /predict → receives real/fake decision.

##### Architectural Patterns & Principles
- Separation of concerns: data ingestion vs. training vs. serving.
- Single responsibility: each module (dataset, model, utils, evaluate) has a clear role.
- Reusability: src/utils.py used by both train.py and frontend/app.py.
- Config-driven design: using config.py for hyper-parameters and paths.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Data Layer
    subgraph "Data Layer"
        DataRaw["Data Raw\n(data/raw/real, data/raw/fake)"]:::data
    end

    %% Processing Layer
    subgraph "Processing Layer"
        Dataset["dataset.py"]:::compute
        DataPreproc["src/data_preprocessing.py"]:::compute
    end

    %% Training Layer
    subgraph "Training Service"
        Config["src/config.py"]:::compute
        ModelDef["src/cnn_model.py"]:::compute
        Evaluate["src/evaluate.py"]:::compute
        Train["train.py"]:::compute
    end

    %% Persistence Layer
    ModelStore["Model Storage\n(best_model.h5)"]:::data

    %% Inference Layer
    subgraph "Inference Service"
        Utils["src/utils.py"]:::compute
        App["frontend/app.py"]:::api
    end

    %% Presentation Layer
    UI["Web UI (Browser)"]:::client

    %% Exploratory
    Notebook["notebooks/exploration.ipynb"]:::notes

    %% Data Flow
    DataRaw --> Dataset --> DataPreproc --> Train
    Config --> Train
    ModelDef --> Train
    Evaluate --> Train
    Train --> ModelStore
    ModelStore --> App
    Utils --> App
    UI --> App
    App --> UI

    %% Notebooks dotted connections
    Notebook -.-> DataRaw
    Notebook -.-> DataPreproc
    Notebook -.-> ModelDef

    %% Click Events
    click DataRaw "https://github.com/iitzirfan/deep-fake/tree/main/data/raw"
    click Dataset "https://github.com/iitzirfan/deep-fake/blob/main/dataset.py"
    click DataPreproc "https://github.com/iitzirfan/deep-fake/blob/main/src/data_preprocessing.py"
    click Config "https://github.com/iitzirfan/deep-fake/blob/main/src/config.py"
    click ModelDef "https://github.com/iitzirfan/deep-fake/blob/main/src/cnn_model.py"
    click Evaluate "https://github.com/iitzirfan/deep-fake/blob/main/src/evaluate.py"
    click Train "https://github.com/iitzirfan/deep-fake/blob/main/train.py"
    click ModelStore "https://github.com/iitzirfan/deep-fake/blob/main/best_model.h5"
    click Utils "https://github.com/iitzirfan/deep-fake/blob/main/src/utils.py"
    click App "https://github.com/iitzirfan/deep-fake/blob/main/frontend/app.py"
    click Notebook "https://github.com/iitzirfan/deep-fake/blob/main/notebooks/exploration.ipynb"

    %% Styles
    classDef data fill:#a2d5a2,stroke:#3e8e41,color:#000
    classDef compute fill:#a2c4e8,stroke:#1d4e89,color:#000
    classDef api fill:#f7c877,stroke:#d68e00,color:#000
    classDef client fill:#cccccc,stroke:#888888,color:#000
    classDef notes fill:#e0b0ff,stroke:#a04fa0,color:#000
```
