# birajbgt/dog-breed-prediction architecture

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

- Interactive diagram: https://gitdiagram.com/birajbgt/dog-breed-prediction
- Repository: https://github.com/birajbgt/dog-breed-prediction

## Overview

Dog Breed Predictor is a browser-based image classifier. A user selects an image in the React UI, which uploads it to FastAPI’s prediction route; the route validates and scores it through the breed service, then returns the predicted breed and confidence for display. The service loads the saved model when available and otherwise builds breed prototypes from training images. The backend also exposes root and health routes. Source excerpts establish backend wiring and inference details; the README documents the browser/API exchange and fallback, while other deployment and validation capabilities are not runtime workflow components.

Main entry points: [`backend/app.py`](https://github.com/birajbgt/dog-breed-prediction/blob/main/backend/app.py) (FastAPI app), [`backend/services/dogbreed.py`](https://github.com/birajbgt/dog-breed-prediction/blob/main/backend/services/dogbreed.py) (Breed inference service), [`backend/routes/predict.py`](https://github.com/birajbgt/dog-breed-prediction/blob/main/backend/routes/predict.py) (Prediction endpoint), [`frontend/src/App.jsx`](https://github.com/birajbgt/dog-breed-prediction/blob/main/frontend/src/App.jsx) (Upload and results UI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser UI"]
  node_ui["Upload and results UI<br/>[App.jsx]"]
  node_frontend_entry["React entry<br/>[main.jsx]"]
end

subgraph group_api["API Routes"]
  node_api_entry["API import entry<br/>[api.py]"]
  node_app["FastAPI app<br/>[app.py]"]
  node_predict["Prediction endpoint<br/>[predict.py]"]
  node_root["Root endpoint<br/>[root.py]"]
  node_health["Health endpoint<br/>[health.py]"]
end

subgraph group_inference["Breed Inference"]
  node_breed_service["Breed inference service<br/>[dogbreed.py]"]
  node_model["Saved model<br/>[dog_breed_model.h5]"]
  node_train_data["Breed training images"]
end

node_user(("Image submitter"))
node_mobilenet["MobileNetV2 features"]
node_docs["Swagger docs"]

node_user -->|"selects image"| node_ui
node_frontend_entry -->|"renders"| node_ui
node_ui -->|"uploads image"| node_predict
node_predict -->|"prepares inference"| node_breed_service
node_breed_service -->|"extracts features"| node_mobilenet
node_breed_service -->|"loads model"| node_model
node_breed_service -->|"reads samples"| node_train_data
node_predict -->|"returns prediction"| node_ui
node_api_entry -->|"imports app"| node_app
node_app -->|"registers route"| node_predict
node_app -->|"registers route"| node_root
node_app -->|"registers route"| node_health
node_user -->|"requests status"| node_root
node_user -->|"checks health"| node_health
node_user -->|"opens API docs"| node_docs

click node_ui "https://github.com/birajbgt/dog-breed-prediction/blob/main/frontend/src/App.jsx"
click node_frontend_entry "https://github.com/birajbgt/dog-breed-prediction/blob/main/frontend/src/main.jsx"
click node_api_entry "https://github.com/birajbgt/dog-breed-prediction/blob/main/api.py"
click node_app "https://github.com/birajbgt/dog-breed-prediction/blob/main/backend/app.py"
click node_predict "https://github.com/birajbgt/dog-breed-prediction/blob/main/backend/routes/predict.py"
click node_root "https://github.com/birajbgt/dog-breed-prediction/blob/main/backend/routes/root.py"
click node_health "https://github.com/birajbgt/dog-breed-prediction/blob/main/backend/routes/health.py"
click node_breed_service "https://github.com/birajbgt/dog-breed-prediction/blob/main/backend/services/dogbreed.py"
click node_model "https://github.com/birajbgt/dog-breed-prediction/blob/main/dog_breed_model.h5"
click node_train_data "https://github.com/birajbgt/dog-breed-prediction/tree/main/train"

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_frontend_entry toneBlue
class node_api_entry,node_app,node_predict,node_root,node_health toneAmber
class node_breed_service,node_model,node_train_data toneMint
class node_user,node_mobilenet,node_docs toneIndigo
```

## Components

### Browser UI

- [Upload and results UI](https://github.com/birajbgt/dog-breed-prediction/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [React entry](https://github.com/birajbgt/dog-breed-prediction/blob/main/frontend/src/main.jsx): `frontend/src/main.jsx`

### API Routes

- [API import entry](https://github.com/birajbgt/dog-breed-prediction/blob/main/api.py): `api.py`
- [FastAPI app](https://github.com/birajbgt/dog-breed-prediction/blob/main/backend/app.py): `backend/app.py`
- [Prediction endpoint](https://github.com/birajbgt/dog-breed-prediction/blob/main/backend/routes/predict.py): `backend/routes/predict.py`
- [Root endpoint](https://github.com/birajbgt/dog-breed-prediction/blob/main/backend/routes/root.py): `backend/routes/root.py`
- [Health endpoint](https://github.com/birajbgt/dog-breed-prediction/blob/main/backend/routes/health.py): `backend/routes/health.py`

### Breed Inference

- [Breed inference service](https://github.com/birajbgt/dog-breed-prediction/blob/main/backend/services/dogbreed.py): `backend/services/dogbreed.py`
- [Saved model](https://github.com/birajbgt/dog-breed-prediction/blob/main/dog_breed_model.h5): `dog_breed_model.h5`
- [Breed training images](https://github.com/birajbgt/dog-breed-prediction/tree/main/train): `train`

### Other components

- **Image submitter**
- **MobileNetV2 features**
- **Swagger docs**

## Connections

- Image submitter → Upload and results UI: selects image (evidence: `frontend/src/App.jsx`)
- React entry → Upload and results UI: renders (evidence: `frontend/src/main.jsx`)
- Upload and results UI → Prediction endpoint: uploads image (evidence: `README.md`)
- Prediction endpoint → Breed inference service: prepares inference (evidence: `backend/routes/predict.py`)
- Breed inference service → MobileNetV2 features: extracts features (evidence: `backend/services/dogbreed.py`)
- Breed inference service → Saved model: loads model (evidence: `backend/services/dogbreed.py`)
- Breed inference service → Breed training images: reads samples (evidence: `backend/services/dogbreed.py`)
- Prediction endpoint → Upload and results UI: returns prediction (evidence: `README.md`)
- API import entry → FastAPI app: imports app (evidence: `api.py`)
- FastAPI app → Prediction endpoint: registers route (evidence: `backend/app.py`)
- FastAPI app → Root endpoint: registers route (evidence: `backend/app.py`)
- FastAPI app → Health endpoint: registers route (evidence: `backend/app.py`)
- Image submitter → Root endpoint: requests status (evidence: `backend/routes/root.py`)
- Image submitter → Health endpoint: checks health (evidence: `backend/routes/health.py`)
- Image submitter → Swagger docs: opens API docs (evidence: `README.md`)
