# abdelfadelachraf/ai-image-detector architecture

> Architecture diagram of the GitHub repository abdelfadelachraf/ai-image-detector, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abdelfadelachraf/ai-image-detector
- Repository: https://github.com/abdelfadelachraf/ai-image-detector

## Overview

AI Image Detector is a React interface backed by a FastAPI image-classification service using a trained EfficientNetB0 model. The main workflow is: a user selects an image, client-side validation and state manage submission, the API validates and preprocesses the upload, and the predictor returns a REAL/FAKE verdict and confidence, with an optional Grad-CAM heatmap displayed in the analysis view. The repository also documents dataset preparation, model training and evaluation in a notebook. Edges reflect excerpts, the source index, or README statements; unsampled implementation details are not inferred.

Main entry points: [`frontend/src/components/Hero.jsx`](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/components/Hero.jsx) (Upload workflow), [`backend/app/routers/predict.py`](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/backend/app/routers/predict.py) (Prediction endpoint), [`backend/app/services/predictor.py`](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/backend/app/services/predictor.py) (Classification and heatmap), [`backend/app/main.py`](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/backend/app/main.py) (FastAPI application)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_web["Web interface"]
  node_app["Page composition<br/>[App.jsx]"]
  node_hero["Upload workflow<br/>[Hero.jsx]"]
  node_dropzone["Image selection<br/>[Dropzone.jsx]"]
  node_detector_hook["Detection state<br/>[useDetector.js]"]
  node_validation["File validation<br/>[validation.js]"]
  node_api_client["HTTP client<br/>[detector.js]"]
  node_scanner["Scan animation<br/>[Scanner.jsx]"]
  node_result["Verdict panel<br/>[ResultPanel.jsx]"]
  node_verdict_axis["Verdict scale<br/>[VerdictAxis.jsx]"]
  node_analysis["Detailed analysis<br/>[Analysis.jsx]"]
  node_model_view["Heatmap view<br/>[ModelView.jsx]"]
  node_how_it_works["How it works<br/>[HowItWorks.jsx]"]
  node_limitations["Known limitations<br/>[Limitations.jsx]"]
end

subgraph group_api["API service"]
  node_backend_app["FastAPI application<br/>[main.py]"]
  node_config["Service configuration<br/>[config.py]"]
  node_health["Health endpoint<br/>[health.py]"]
  node_predict_route["Prediction endpoint<br/>[predict.py]"]
  node_dependencies["Predictor dependency<br/>[dependencies.py]"]
  node_schemas["Response schemas<br/>[schemas.py]"]
end

subgraph group_inference["Inference pipeline"]
  node_preprocessing["Image preprocessing<br/>[preprocessing.py]"]
  node_predictor["Classification and heatmap<br/>[predictor.py]"]
end

subgraph group_modeling["Model lifecycle"]
  node_model_file["Trained model<br/>[detector.keras]"]
  node_training["Data and model training"]
end

node_user(("Image user"))

node_user -->|"selects image"| node_hero
node_app -->|"renders"| node_hero
node_app -->|"renders"| node_how_it_works
node_app -->|"renders"| node_limitations
node_hero -->|"renders"| node_dropzone
node_hero -->|"uses state"| node_detector_hook
node_hero -->|"renders"| node_scanner
node_hero -->|"renders"| node_result
node_hero -->|"renders"| node_analysis
node_detector_hook -->|"validates file"| node_validation
node_detector_hook -->|"requests prediction"| node_api_client
node_api_client -->|"posts image"| node_predict_route
node_api_client -->|"checks status"| node_health
node_result -->|"renders"| node_verdict_axis
node_analysis -->|"renders heatmap"| node_model_view
node_backend_app -->|"registers route"| node_health
node_backend_app -->|"registers route"| node_predict_route
node_backend_app -->|"reads settings"| node_config
node_backend_app -->|"loads at startup"| node_predictor
node_predictor -->|"loads model"| node_model_file
node_predict_route -->|"checks upload limits"| node_config
node_predict_route -->|"gets predictor"| node_dependencies
node_predict_route -->|"preprocesses upload"| node_preprocessing
node_predict_route -->|"requests prediction"| node_predictor
node_predict_route -->|"declares response"| node_schemas
node_dependencies -->|"provides instance"| node_predictor
node_health -->|"uses response schema"| node_schemas
node_preprocessing -->|"reads image sizes"| node_config
node_predictor -->|"builds response"| node_schemas
node_training -.->|"produces trained artifact"| node_model_file

click node_app "https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/App.jsx"
click node_hero "https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/components/Hero.jsx"
click node_dropzone "https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/components/Dropzone.jsx"
click node_detector_hook "https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/hooks/useDetector.js"
click node_validation "https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/utils/validation.js"
click node_api_client "https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/api/detector.js"
click node_scanner "https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/components/Scanner.jsx"
click node_result "https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/components/ResultPanel.jsx"
click node_verdict_axis "https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/components/VerdictAxis.jsx"
click node_analysis "https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/components/Analysis.jsx"
click node_model_view "https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/components/ModelView.jsx"
click node_how_it_works "https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/components/HowItWorks.jsx"
click node_limitations "https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/components/Limitations.jsx"
click node_backend_app "https://github.com/abdelfadelachraf/ai-image-detector/blob/main/backend/app/main.py"
click node_config "https://github.com/abdelfadelachraf/ai-image-detector/blob/main/backend/app/config.py"
click node_health "https://github.com/abdelfadelachraf/ai-image-detector/blob/main/backend/app/routers/health.py"
click node_predict_route "https://github.com/abdelfadelachraf/ai-image-detector/blob/main/backend/app/routers/predict.py"
click node_dependencies "https://github.com/abdelfadelachraf/ai-image-detector/blob/main/backend/app/dependencies.py"
click node_schemas "https://github.com/abdelfadelachraf/ai-image-detector/blob/main/backend/app/schemas.py"
click node_preprocessing "https://github.com/abdelfadelachraf/ai-image-detector/blob/main/backend/app/services/preprocessing.py"
click node_predictor "https://github.com/abdelfadelachraf/ai-image-detector/blob/main/backend/app/services/predictor.py"
click node_model_file "https://github.com/abdelfadelachraf/ai-image-detector/blob/main/backend/model/detector.keras"
click node_training "https://github.com/abdelfadelachraf/ai-image-detector/blob/main/notebooks/data%20processing%20and%20training%20the%20model%20.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_app,node_hero,node_dropzone,node_detector_hook,node_validation,node_api_client,node_scanner,node_result,node_verdict_axis,node_analysis,node_model_view,node_how_it_works,node_limitations,node_user toneBlue
class node_backend_app,node_config,node_health,node_predict_route,node_dependencies,node_schemas toneAmber
class node_preprocessing,node_predictor toneMint
class node_model_file,node_training toneRose
```

## Components

### Web interface

- [Page composition](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Upload workflow](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/components/Hero.jsx): `frontend/src/components/Hero.jsx`
- [Image selection](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/components/Dropzone.jsx): `frontend/src/components/Dropzone.jsx`
- [Detection state](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/hooks/useDetector.js): `frontend/src/hooks/useDetector.js`
- [File validation](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/utils/validation.js): `frontend/src/utils/validation.js`
- [HTTP client](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/api/detector.js): `frontend/src/api/detector.js`
- [Scan animation](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/components/Scanner.jsx): `frontend/src/components/Scanner.jsx`
- [Verdict panel](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/components/ResultPanel.jsx): `frontend/src/components/ResultPanel.jsx`
- [Verdict scale](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/components/VerdictAxis.jsx): `frontend/src/components/VerdictAxis.jsx`
- [Detailed analysis](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/components/Analysis.jsx): `frontend/src/components/Analysis.jsx`
- [Heatmap view](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/components/ModelView.jsx): `frontend/src/components/ModelView.jsx`
- [How it works](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/components/HowItWorks.jsx): `frontend/src/components/HowItWorks.jsx`
- [Known limitations](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/frontend/src/components/Limitations.jsx): `frontend/src/components/Limitations.jsx`

### API service

- [FastAPI application](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/backend/app/main.py): `backend/app/main.py`
- [Service configuration](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/backend/app/config.py): `backend/app/config.py`
- [Health endpoint](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/backend/app/routers/health.py): `backend/app/routers/health.py`
- [Prediction endpoint](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/backend/app/routers/predict.py): `backend/app/routers/predict.py`
- [Predictor dependency](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/backend/app/dependencies.py): `backend/app/dependencies.py`
- [Response schemas](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/backend/app/schemas.py): `backend/app/schemas.py`

### Inference pipeline

- [Image preprocessing](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/backend/app/services/preprocessing.py): `backend/app/services/preprocessing.py`
- [Classification and heatmap](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/backend/app/services/predictor.py): `backend/app/services/predictor.py`

### Model lifecycle

- [Trained model](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/backend/model/detector.keras): `backend/model/detector.keras`
- [Data and model training](https://github.com/abdelfadelachraf/ai-image-detector/blob/main/notebooks/data%20processing%20and%20training%20the%20model%20.ipynb): `notebooks/data processing and training the model .ipynb`

### Other components

- **Image user**

## Connections

- Image user → Upload workflow: selects image (evidence: `README.md`)
- Page composition → Upload workflow: renders (evidence: `frontend/src/App.jsx`)
- Page composition → How it works: renders (evidence: `frontend/src/App.jsx`)
- Page composition → Known limitations: renders (evidence: `frontend/src/App.jsx`)
- Upload workflow → Image selection: renders (evidence: `frontend/src/components/Hero.jsx`)
- Upload workflow → Detection state: uses state (evidence: `frontend/src/components/Hero.jsx`)
- Upload workflow → Scan animation: renders (evidence: `frontend/src/components/Hero.jsx`)
- Upload workflow → Verdict panel: renders (evidence: `frontend/src/components/Hero.jsx`)
- Upload workflow → Detailed analysis: renders (evidence: `frontend/src/components/Hero.jsx`)
- Detection state → File validation: validates file (evidence: `frontend/src/hooks/useDetector.js`)
- Detection state → HTTP client: requests prediction (evidence: `frontend/src/hooks/useDetector.js`)
- HTTP client → Prediction endpoint: posts image (evidence: `README.md`)
- HTTP client → Health endpoint: checks status (evidence: `README.md`)
- Verdict panel → Verdict scale: renders (evidence: `frontend/src/components/ResultPanel.jsx`)
- Detailed analysis → Heatmap view: renders heatmap (evidence: `frontend/src/components/Analysis.jsx`)
- FastAPI application → Health endpoint: registers route (evidence: `backend/app/main.py`)
- FastAPI application → Prediction endpoint: registers route (evidence: `backend/app/main.py`)
- FastAPI application → Service configuration: reads settings (evidence: `backend/app/main.py`)
- FastAPI application → Classification and heatmap: loads at startup (evidence: `backend/app/main.py`)
- Classification and heatmap → Trained model: loads model (evidence: `README.md`)
- Prediction endpoint → Service configuration: checks upload limits (evidence: `backend/app/routers/predict.py`)
- Prediction endpoint → Predictor dependency: gets predictor (evidence: `backend/app/routers/predict.py`)
- Prediction endpoint → Image preprocessing: preprocesses upload (evidence: `backend/app/routers/predict.py`)
- Prediction endpoint → Classification and heatmap: requests prediction (evidence: `backend/app/routers/predict.py`)
- Prediction endpoint → Response schemas: declares response (evidence: `backend/app/routers/predict.py`)
- Predictor dependency → Classification and heatmap: provides instance (evidence: `backend/app/dependencies.py`)
- Health endpoint → Response schemas: uses response schema (evidence: `backend/app/routers/health.py`)
- Image preprocessing → Service configuration: reads image sizes (evidence: `backend/app/services/preprocessing.py`)
- Classification and heatmap → Response schemas: builds response (evidence: `backend/app/services/predictor.py`)
- Data and model training → Trained model: produces trained artifact (evidence: `README.md`)
