# charleydcruze/cat_dog_image_classifier architecture

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

- Interactive diagram: https://gitdiagram.com/charleydcruze/cat_dog_image_classifier
- Repository: https://github.com/charleydcruze/cat_dog_image_classifier

## Overview

This repository is a cat-and-dog image-classification PWA with an image-analysis and report-export workflow: a user uploads or captures an image, the frontend requests a prediction, and the backend returns a label, confidence, class ID, and Grad-CAM heatmap; the user can then request a PDF report. Separate training and data-preparation scripts build the model checkpoint. The graph preserves the documented frontend and offline-PWA capabilities, but the frontend source was not excerpted, so those links rely on README statements.

Main entry points: [`index.html`](https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/index.html) (Classifier interface), [`serviceWorker.js`](https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/serviceWorker.js) (Offline caching), [`backend.py`](https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/backend.py) (Prediction API), [`train.py`](https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/train.py) (ResNet training)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["PWA client"]
  node_ui["Classifier interface<br/>[index.html]"]
  node_styles["Responsive styles<br/>[style.css]"]
  node_pwa["Offline caching<br/>[serviceWorker.js]"]
  node_manifest["PWA metadata<br/>[manifest.json]"]
end

subgraph group_api["Inference API"]
  node_predict["Prediction API<br/>[backend.py]"]
  node_inference["Image inference<br/>[backend.py]"]
  node_explain["Grad-CAM heatmap<br/>[backend.py]"]
  node_report["PDF report generation<br/>[backend.py]"]
end

subgraph group_training["Model preparation"]
  node_checkpoint["Model checkpoint"]
  node_trainer["ResNet training<br/>[train.py]"]
end

subgraph group_data["Dataset preparation"]
  node_petdata["Pet data preparation<br/>[get_clean_data.py]"]
  node_balancing["Cat dog balancing"]
  node_otherdata["Other-class data<br/>[get_other_data.py]"]
end

node_user(("Image user"))

node_user -->|"uploads or captures"| node_ui
node_ui -->|"requests prediction"| node_predict
node_predict -->|"handles image"| node_inference
node_inference -->|"computes heatmap"| node_explain
node_predict -->|"returns result"| node_ui
node_ui -->|"requests report"| node_report
node_report -->|"streams PDF"| node_ui
node_ui -->|"caches assets"| node_pwa
node_pwa -->|"caches asset"| node_styles
node_pwa -->|"caches asset"| node_manifest
node_pwa -->|"caches asset"| node_ui
node_trainer -->|"saves weights"| node_checkpoint
node_predict -->|"loads weights"| node_checkpoint
node_petdata -.->|"prepares training data"| node_trainer
node_balancing -.->|"prepares training data"| node_trainer
node_otherdata -.->|"prepares training data"| node_trainer

click node_ui "https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/index.html"
click node_styles "https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/CSS/style.css"
click node_pwa "https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/serviceWorker.js"
click node_manifest "https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/manifest.json"
click node_predict "https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/backend.py"
click node_inference "https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/backend.py"
click node_explain "https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/backend.py"
click node_report "https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/backend.py"
click node_checkpoint "https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/cat_dog_resnet18.pth"
click node_trainer "https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/train.py"
click node_petdata "https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/get_clean_data.py"
click node_balancing "https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/sort_and_balance.py"
click node_otherdata "https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/get_other_data.py"

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_ui,node_styles,node_pwa,node_manifest,node_user toneBlue
class node_predict,node_inference,node_explain,node_report toneAmber
class node_checkpoint,node_trainer toneMint
class node_petdata,node_balancing,node_otherdata toneRose
```

## Components

### PWA client

- [Classifier interface](https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/index.html): `index.html`
- [Responsive styles](https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/CSS/style.css): `CSS/style.css`
- [Offline caching](https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/serviceWorker.js): `serviceWorker.js`
- [PWA metadata](https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/manifest.json): `manifest.json`

### Inference API

- [Prediction API](https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/backend.py): `backend.py`
- [Image inference](https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/backend.py): `backend.py`
- [Grad-CAM heatmap](https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/backend.py): `backend.py`
- [PDF report generation](https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/backend.py): `backend.py`

### Model preparation

- [Model checkpoint](https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/cat_dog_resnet18.pth): `cat_dog_resnet18.pth`
- [ResNet training](https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/train.py): `train.py`

### Dataset preparation

- [Pet data preparation](https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/get_clean_data.py): `get_clean_data.py`
- [Cat dog balancing](https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/sort_and_balance.py): `sort_and_balance.py`
- [Other-class data](https://github.com/charleydcruze/cat_dog_image_classifier/blob/main/get_other_data.py): `get_other_data.py`

### Other components

- **Image user**

## Connections

- Image user → Classifier interface: uploads or captures (evidence: `README.md`)
- Classifier interface → Prediction API: requests prediction (evidence: `README.md`)
- Prediction API → Image inference: handles image (evidence: `README.md`)
- Image inference → Grad-CAM heatmap: computes heatmap (evidence: `README.md`)
- Prediction API → Classifier interface: returns result (evidence: `README.md`)
- Classifier interface → PDF report generation: requests report (evidence: `README.md`)
- PDF report generation → Classifier interface: streams PDF (evidence: `README.md`)
- Classifier interface → Offline caching: caches assets (evidence: `serviceWorker.js`)
- Offline caching → Responsive styles: caches asset (evidence: `serviceWorker.js`)
- Offline caching → PWA metadata: caches asset (evidence: `serviceWorker.js`)
- Offline caching → Classifier interface: caches asset (evidence: `serviceWorker.js`)
- ResNet training → Model checkpoint: saves weights (evidence: `train.py`)
- Prediction API → Model checkpoint: loads weights (evidence: `README.md`)
- Pet data preparation → ResNet training: prepares training data
- Cat dog balancing → ResNet training: prepares training data
- Other-class data → ResNet training: prepares training data
