# zahinsyukran/ai_image_detector architecture

> Architecture diagram of the GitHub repository zahinsyukran/ai_image_detector, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/zahinsyukran/ai_image_detector
- Repository: https://github.com/zahinsyukran/ai_image_detector

## Overview

The product is a browser-based AI-image detector. A user selects an image from Chrome, the extension uploads it to the local API, and the API analyzes face/detail quality, routes inference to ResNet or ViT, and returns a label with confidence and router details. The README documents a training pipeline, but the notebook was not sampled, so its internal behavior and connection to the shipped weights are not shown. Model routing and extension/API communication are supported by the sampled sources.

Main entry points: [`api/main.py`](https://github.com/zahinsyukran/ai_image_detector/blob/main/api/main.py) (Adaptive router), [`extension/background.js`](https://github.com/zahinsyukran/ai_image_detector/blob/main/extension/background.js) (Chrome image menu), [`api/resnet18_deepfake.pth`](https://github.com/zahinsyukran/ai_image_detector/blob/main/api/resnet18_deepfake.pth) (ResNet weights), [`model.ipynb`](https://github.com/zahinsyukran/ai_image_detector/blob/main/model.ipynb) (Training pipeline)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_browser["Browser Extension"]
  node_chrome["Chrome image menu<br/>[background.js]"]
  node_extension_upload["Image upload<br/>[background.js]"]
  node_result_alert["Result alert<br/>[background.js]"]
end

subgraph group_api["API Analysis"]
  node_api_endpoint["Prediction endpoint<br/>[main.py]"]
  node_image_validation["Image validation<br/>[main.py]"]
  node_face_crop["Face detection and crop<br/>[main.py]"]
  node_sharpness["Sharpness scoring<br/>[main.py]"]
  node_router["Adaptive router<br/>[main.py]"]
  node_classification["Label and confidence<br/>[main.py]"]
  node_api_response["Prediction response<br/>[main.py]"]
end

subgraph group_inference["Inference Engines"]
  node_resnet["ResNet-18 classifier<br/>[main.py]"]
  node_resnet_weights["ResNet weights"]
  node_vit["Vision Transformer<br/>[main.py]"]
end

subgraph group_training["Model Training"]
  node_training_notebook["Training pipeline<br/>[model.ipynb]"]
end

node_user(("Image user"))
node_image_host["Image host"]
node_huggingface["Hugging Face model"]

node_user -->|"selects image"| node_chrome
node_chrome -->|"fetches image"| node_image_host
node_chrome -->|"dispatches scan"| node_extension_upload
node_image_host -->|"returns image"| node_extension_upload
node_extension_upload -->|"uploads image"| node_api_endpoint
node_api_endpoint -->|"passes upload"| node_image_validation
node_image_validation -->|"decodes image"| node_face_crop
node_face_crop -->|"provides image crop"| node_sharpness
node_sharpness -->|"provides score"| node_router
node_router -->|"routes low detail"| node_resnet
node_router -->|"routes high detail"| node_vit
node_resnet_weights -->|"loads weights"| node_resnet
node_vit -.->|"loads pretrained model"| node_huggingface
node_resnet -->|"returns probabilities"| node_classification
node_vit -->|"returns probabilities"| node_classification
node_router -->|"provides routing details"| node_classification
node_classification -->|"formats result"| node_api_response
node_api_response -->|"returns JSON"| node_result_alert
node_result_alert -->|"displays result"| node_user
node_training_notebook -.->|"trains weights"| node_resnet_weights

click node_chrome "https://github.com/zahinsyukran/ai_image_detector/blob/main/extension/background.js"
click node_extension_upload "https://github.com/zahinsyukran/ai_image_detector/blob/main/extension/background.js"
click node_api_endpoint "https://github.com/zahinsyukran/ai_image_detector/blob/main/api/main.py"
click node_image_validation "https://github.com/zahinsyukran/ai_image_detector/blob/main/api/main.py"
click node_face_crop "https://github.com/zahinsyukran/ai_image_detector/blob/main/api/main.py"
click node_sharpness "https://github.com/zahinsyukran/ai_image_detector/blob/main/api/main.py"
click node_router "https://github.com/zahinsyukran/ai_image_detector/blob/main/api/main.py"
click node_resnet "https://github.com/zahinsyukran/ai_image_detector/blob/main/api/main.py"
click node_resnet_weights "https://github.com/zahinsyukran/ai_image_detector/blob/main/api/resnet18_deepfake.pth"
click node_vit "https://github.com/zahinsyukran/ai_image_detector/blob/main/api/main.py"
click node_classification "https://github.com/zahinsyukran/ai_image_detector/blob/main/api/main.py"
click node_api_response "https://github.com/zahinsyukran/ai_image_detector/blob/main/api/main.py"
click node_result_alert "https://github.com/zahinsyukran/ai_image_detector/blob/main/extension/background.js"
click node_training_notebook "https://github.com/zahinsyukran/ai_image_detector/blob/main/model.ipynb"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_chrome,node_extension_upload,node_result_alert,node_user toneBlue
class node_api_endpoint,node_image_validation,node_face_crop,node_sharpness,node_router,node_classification,node_api_response toneAmber
class node_resnet,node_resnet_weights,node_vit toneMint
class node_training_notebook toneRose
class node_image_host,node_huggingface toneIndigo
```

## Components

### Browser Extension

- [Chrome image menu](https://github.com/zahinsyukran/ai_image_detector/blob/main/extension/background.js): `extension/background.js`
- [Image upload](https://github.com/zahinsyukran/ai_image_detector/blob/main/extension/background.js): `extension/background.js`
- [Result alert](https://github.com/zahinsyukran/ai_image_detector/blob/main/extension/background.js): `extension/background.js`

### API Analysis

- [Prediction endpoint](https://github.com/zahinsyukran/ai_image_detector/blob/main/api/main.py): `api/main.py`
- [Image validation](https://github.com/zahinsyukran/ai_image_detector/blob/main/api/main.py): `api/main.py`
- [Face detection and crop](https://github.com/zahinsyukran/ai_image_detector/blob/main/api/main.py): `api/main.py`
- [Sharpness scoring](https://github.com/zahinsyukran/ai_image_detector/blob/main/api/main.py): `api/main.py`
- [Adaptive router](https://github.com/zahinsyukran/ai_image_detector/blob/main/api/main.py): `api/main.py`
- [Label and confidence](https://github.com/zahinsyukran/ai_image_detector/blob/main/api/main.py): `api/main.py`
- [Prediction response](https://github.com/zahinsyukran/ai_image_detector/blob/main/api/main.py): `api/main.py`

### Inference Engines

- [ResNet-18 classifier](https://github.com/zahinsyukran/ai_image_detector/blob/main/api/main.py): `api/main.py`
- [ResNet weights](https://github.com/zahinsyukran/ai_image_detector/blob/main/api/resnet18_deepfake.pth): `api/resnet18_deepfake.pth`
- [Vision Transformer](https://github.com/zahinsyukran/ai_image_detector/blob/main/api/main.py): `api/main.py`

### Model Training

- [Training pipeline](https://github.com/zahinsyukran/ai_image_detector/blob/main/model.ipynb): `model.ipynb`

### Other components

- **Image user**
- **Image host**
- **Hugging Face model**

## Connections

- Image user → Chrome image menu: selects image
- Chrome image menu → Image host: fetches image
- Chrome image menu → Image upload: dispatches scan
- Image host → Image upload: returns image
- Image upload → Prediction endpoint: uploads image
- Prediction endpoint → Image validation: passes upload
- Image validation → Face detection and crop: decodes image
- Face detection and crop → Sharpness scoring: provides image crop
- Sharpness scoring → Adaptive router: provides score
- Adaptive router → ResNet-18 classifier: routes low detail
- Adaptive router → Vision Transformer: routes high detail
- ResNet weights → ResNet-18 classifier: loads weights
- Vision Transformer → Hugging Face model: loads pretrained model
- ResNet-18 classifier → Label and confidence: returns probabilities
- Vision Transformer → Label and confidence: returns probabilities
- Adaptive router → Label and confidence: provides routing details
- Label and confidence → Prediction response: formats result
- Prediction response → Result alert: returns JSON
- Result alert → Image user: displays result
- Training pipeline → ResNet weights: trains weights
