# ezykl/r2r-model architecture

> Architecture diagram of the GitHub repository ezykl/r2r-model, 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/ezykl/r2r-model
- Repository: https://github.com/ezykl/r2r-model

## Overview

R2R is a Flask image-classification API for the mobile app. Its main workflow accepts an uploaded image, validates and preprocesses it, runs the trained model, applies confidence thresholds and Accepted/Prohibited rules, then returns prediction results. A separate health route reports API availability. The README documents the model’s 180 classes and supported formats; the implementation is concentrated in app.py, so the graph represents those stages as responsibilities within that file rather than separate modules.

Main entry points: [`app.py`](https://github.com/ezykl/r2r-model/blob/main/app.py) (Flask routes), [`model/r2r_model.keras`](https://github.com/ezykl/r2r-model/blob/main/model/r2r_model.keras) (Trained model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["HTTP API"]
  node_api_routes["Flask routes<br/>[app.py]"]
  node_health["Health check<br/>[app.py]"]
  node_upload_validation["Upload validation<br/>[app.py]"]
  node_json_results["JSON results<br/>[app.py]"]
end

subgraph group_inference["Image Inference"]
  node_image_preprocessing["Image preprocessing<br/>[app.py]"]
  node_trained_model["Trained model<br/>[r2r_model.keras]"]
  node_model_inference["Model inference<br/>[app.py]"]
end

subgraph group_classification["Prediction Results"]
  node_confidence_filter["Confidence filtering<br/>[app.py]"]
  node_item_categories["Item categories<br/>[app.py]"]
end

node_client(("R2R app client"))

node_client -->|"sends request"| node_api_routes
node_api_routes -->|"dispatches health check"| node_health
node_api_routes -->|"dispatches prediction"| node_upload_validation
node_upload_validation -->|"passes valid image"| node_image_preprocessing
node_image_preprocessing -->|"passes image tensor"| node_model_inference
node_api_routes -->|"loads at startup"| node_trained_model
node_model_inference -->|"runs prediction"| node_trained_model
node_model_inference -->|"passes scores"| node_confidence_filter
node_confidence_filter -->|"categorizes candidates"| node_item_categories
node_health -->|"returns status"| node_json_results
node_confidence_filter -->|"formats predictions"| node_json_results
node_item_categories -->|"adds category"| node_json_results
node_json_results -->|"returns JSON"| node_client

click node_api_routes "https://github.com/ezykl/r2r-model/blob/main/app.py"
click node_health "https://github.com/ezykl/r2r-model/blob/main/app.py"
click node_upload_validation "https://github.com/ezykl/r2r-model/blob/main/app.py"
click node_image_preprocessing "https://github.com/ezykl/r2r-model/blob/main/app.py"
click node_trained_model "https://github.com/ezykl/r2r-model/blob/main/model/r2r_model.keras"
click node_model_inference "https://github.com/ezykl/r2r-model/blob/main/app.py"
click node_confidence_filter "https://github.com/ezykl/r2r-model/blob/main/app.py"
click node_item_categories "https://github.com/ezykl/r2r-model/blob/main/app.py"
click node_json_results "https://github.com/ezykl/r2r-model/blob/main/app.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_api_routes,node_health,node_upload_validation,node_json_results,node_client toneBlue
class node_image_preprocessing,node_trained_model,node_model_inference toneAmber
class node_confidence_filter,node_item_categories toneMint
```

## Components

### HTTP API

- [Flask routes](https://github.com/ezykl/r2r-model/blob/main/app.py): `app.py`
- [Health check](https://github.com/ezykl/r2r-model/blob/main/app.py): `app.py`
- [Upload validation](https://github.com/ezykl/r2r-model/blob/main/app.py): `app.py`
- [JSON results](https://github.com/ezykl/r2r-model/blob/main/app.py): `app.py`

### Image Inference

- [Image preprocessing](https://github.com/ezykl/r2r-model/blob/main/app.py): `app.py`
- [Trained model](https://github.com/ezykl/r2r-model/blob/main/model/r2r_model.keras): `model/r2r_model.keras`
- [Model inference](https://github.com/ezykl/r2r-model/blob/main/app.py): `app.py`

### Prediction Results

- [Confidence filtering](https://github.com/ezykl/r2r-model/blob/main/app.py): `app.py`
- [Item categories](https://github.com/ezykl/r2r-model/blob/main/app.py): `app.py`

### Other components

- **R2R app client**

## Connections

- R2R app client → Flask routes: sends request
- Flask routes → Health check: dispatches health check
- Flask routes → Upload validation: dispatches prediction
- Upload validation → Image preprocessing: passes valid image
- Image preprocessing → Model inference: passes image tensor
- Flask routes → Trained model: loads at startup
- Model inference → Trained model: runs prediction
- Model inference → Confidence filtering: passes scores
- Confidence filtering → Item categories: categorizes candidates
- Health check → JSON results: returns status
- Confidence filtering → JSON results: formats predictions
- Item categories → JSON results: adds category
- JSON results → R2R app client: returns JSON
