# ganapatinaik1/smart-food-spoilage-detector architecture

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

- Interactive diagram: https://gitdiagram.com/ganapatinaik1/smart-food-spoilage-detector
- Repository: https://github.com/ganapatinaik1/smart-food-spoilage-detector

## Overview

FreshnessAI is an Android food-spoilage detector: a user captures a smart label, the app extracts QR product context and the indicator’s color, then sends the image and context to Gemini for a structured freshness assessment. Scan results are stored locally and surfaced through result, history, and detail screens. The repository also contains a color-based analysis engine and calibration data path; their runtime relationship to the Gemini workflow is not established by the excerpts. Edges reflect shown calls, indexed references, or README claims; unsampled wiring is omitted.

Main entry points: [`FreshnessAI/app/src/main/java/com/freshnessai/ui/ScanFragment.kt`](https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/ui/ScanFragment.kt) (Camera Scan), [`FreshnessAI/app/src/main/java/com/freshnessai/data/ScanHistoryDatabase.kt`](https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/data/ScanHistoryDatabase.kt) (Scan History DB), [`FreshnessAI/app/src/main/java/com/freshnessai/analysis/GeminiAnalyzer.kt`](https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/analysis/GeminiAnalyzer.kt) (Gemini Analysis), [`FreshnessAI/app/src/main/java/com/freshnessai/ui/HistoryFragment.kt`](https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/ui/HistoryFragment.kt) (History Screen)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_capture["Capture and Scan"]
  node_scan["Camera Scan<br/>[ScanFragment.kt]"]
end

subgraph group_analysis["Freshness Analysis"]
  node_qr["QR Parser<br/>[QRDataParser.kt]"]
  node_calibrator["Color Calibrator<br/>[ColorCalibrator.kt]"]
  node_extractor["Sensor Extractor"]
  node_gemini["Gemini Analysis<br/>[GeminiAnalyzer.kt]"]
  node_color_analyzer["Color Analysis<br/>[ColorAnalyzer.kt]"]
  node_freshness_engine["Freshness Engine<br/>[FreshnessEngine.kt]"]
  node_color_data["Color Data"]
  node_color_asset["Color Mapping"]
  node_food_info["Food Models<br/>[Models.kt]"]
end

subgraph group_storage["Local Records"]
  node_records["Scan Records<br/>[Models.kt]"]
  node_database[("Scan History DB")]
end

subgraph group_experience["App Experience"]
  node_result["Scan Result<br/>[ResultFragment.kt]"]
  node_home["Home Screen<br/>[HomeFragment.kt]"]
  node_history["History Screen<br/>[HistoryFragment.kt]"]
  node_history_adapter["History Adapter"]
  node_detail["Scan Detail<br/>[DetailFragment.kt]"]
  node_gauge["Freshness Gauge"]
end

node_user(("Food Scanner"))
node_cloud{{"Gemini Cloud"}}

node_user -->|"captures label"| node_scan
node_scan -->|"parses QR"| node_qr
node_scan -->|"requests calibration"| node_calibrator
node_scan -->|"extracts sensor"| node_extractor
node_extractor -->|"applies correction"| node_calibrator
node_scan -->|"submits image"| node_gemini
node_gemini -->|"requests inference"| node_cloud
node_cloud -->|"returns analysis"| node_gemini
node_gemini -->|"creates record"| node_records
node_qr -->|"builds context"| node_food_info
node_scan -->|"saves scan"| node_database
node_freshness_engine -->|"uses mappings"| node_color_data
node_color_data -->|"loads asset"| node_color_asset
node_result -->|"reads scans"| node_database
node_home -->|"reads scans"| node_database
node_history -->|"reads and clears"| node_database
node_history -->|"updates list"| node_history_adapter
node_detail -->|"loads and deletes"| node_database
node_detail -->|"sets score"| node_gauge

click node_scan "https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/ui/ScanFragment.kt"
click node_qr "https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/analysis/QRDataParser.kt"
click node_calibrator "https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/analysis/ColorCalibrator.kt"
click node_extractor "https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/analysis/SensorColorExtractor.kt"
click node_gemini "https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/analysis/GeminiAnalyzer.kt"
click node_color_analyzer "https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/analysis/ColorAnalyzer.kt"
click node_freshness_engine "https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/analysis/FreshnessEngine.kt"
click node_color_data "https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/data/FreshnessColorData.kt"
click node_color_asset "https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/assets/freshness_color_data.json"
click node_food_info "https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/data/Models.kt"
click node_records "https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/data/Models.kt"
click node_database "https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/data/ScanHistoryDatabase.kt"
click node_result "https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/ui/ResultFragment.kt"
click node_home "https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/ui/HomeFragment.kt"
click node_history "https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/ui/HistoryFragment.kt"
click node_history_adapter "https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/ui/ScanHistoryAdapter.kt"
click node_detail "https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/ui/DetailFragment.kt"
click node_gauge "https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/ui/FreshnessGaugeView.kt"

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_scan toneBlue
class node_qr,node_calibrator,node_extractor,node_gemini,node_color_analyzer,node_freshness_engine,node_color_data,node_color_asset,node_food_info toneAmber
class node_records,node_database toneMint
class node_result,node_home,node_history,node_history_adapter,node_detail,node_gauge toneRose
class node_user,node_cloud toneIndigo
```

## Components

### Capture and Scan

- [Camera Scan](https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/ui/ScanFragment.kt): `FreshnessAI/app/src/main/java/com/freshnessai/ui/ScanFragment.kt`

### Freshness Analysis

- [QR Parser](https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/analysis/QRDataParser.kt): `FreshnessAI/app/src/main/java/com/freshnessai/analysis/QRDataParser.kt`
- [Color Calibrator](https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/analysis/ColorCalibrator.kt): `FreshnessAI/app/src/main/java/com/freshnessai/analysis/ColorCalibrator.kt`
- [Sensor Extractor](https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/analysis/SensorColorExtractor.kt): `FreshnessAI/app/src/main/java/com/freshnessai/analysis/SensorColorExtractor.kt`
- [Gemini Analysis](https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/analysis/GeminiAnalyzer.kt): `FreshnessAI/app/src/main/java/com/freshnessai/analysis/GeminiAnalyzer.kt`
- [Color Analysis](https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/analysis/ColorAnalyzer.kt): `FreshnessAI/app/src/main/java/com/freshnessai/analysis/ColorAnalyzer.kt`
- [Freshness Engine](https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/analysis/FreshnessEngine.kt): `FreshnessAI/app/src/main/java/com/freshnessai/analysis/FreshnessEngine.kt`
- [Color Data](https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/data/FreshnessColorData.kt): `FreshnessAI/app/src/main/java/com/freshnessai/data/FreshnessColorData.kt`
- [Color Mapping](https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/assets/freshness_color_data.json): `FreshnessAI/app/src/main/assets/freshness_color_data.json`
- [Food Models](https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/data/Models.kt): `FreshnessAI/app/src/main/java/com/freshnessai/data/Models.kt`

### Local Records

- [Scan Records](https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/data/Models.kt): `FreshnessAI/app/src/main/java/com/freshnessai/data/Models.kt`
- [Scan History DB](https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/data/ScanHistoryDatabase.kt): `FreshnessAI/app/src/main/java/com/freshnessai/data/ScanHistoryDatabase.kt`

### App Experience

- [Scan Result](https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/ui/ResultFragment.kt): `FreshnessAI/app/src/main/java/com/freshnessai/ui/ResultFragment.kt`
- [Home Screen](https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/ui/HomeFragment.kt): `FreshnessAI/app/src/main/java/com/freshnessai/ui/HomeFragment.kt`
- [History Screen](https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/ui/HistoryFragment.kt): `FreshnessAI/app/src/main/java/com/freshnessai/ui/HistoryFragment.kt`
- [History Adapter](https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/ui/ScanHistoryAdapter.kt): `FreshnessAI/app/src/main/java/com/freshnessai/ui/ScanHistoryAdapter.kt`
- [Scan Detail](https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/ui/DetailFragment.kt): `FreshnessAI/app/src/main/java/com/freshnessai/ui/DetailFragment.kt`
- [Freshness Gauge](https://github.com/ganapatinaik1/smart-food-spoilage-detector/blob/main/FreshnessAI/app/src/main/java/com/freshnessai/ui/FreshnessGaugeView.kt): `FreshnessAI/app/src/main/java/com/freshnessai/ui/FreshnessGaugeView.kt`

### Other components

- **Food Scanner**
- **Gemini Cloud**

## Connections

- Food Scanner → Camera Scan: captures label (evidence: `README.md`)
- Camera Scan → QR Parser: parses QR (evidence: `FreshnessAI/app/src/main/java/com/freshnessai/ui/ScanFragment.kt`)
- Camera Scan → Color Calibrator: requests calibration (evidence: `FreshnessAI/app/src/main/java/com/freshnessai/ui/ScanFragment.kt`)
- Camera Scan → Sensor Extractor: extracts sensor (evidence: `FreshnessAI/app/src/main/java/com/freshnessai/ui/ScanFragment.kt`)
- Sensor Extractor → Color Calibrator: applies correction (evidence: `FreshnessAI/app/src/main/java/com/freshnessai/analysis/SensorColorExtractor.kt`)
- Camera Scan → Gemini Analysis: submits image (evidence: `FreshnessAI/app/src/main/java/com/freshnessai/ui/ScanFragment.kt`)
- Gemini Analysis → Gemini Cloud: requests inference (evidence: `README.md`)
- Gemini Cloud → Gemini Analysis: returns analysis (evidence: `README.md`)
- Gemini Analysis → Scan Records: creates record (evidence: `FreshnessAI/app/src/main/java/com/freshnessai/analysis/GeminiAnalyzer.kt`)
- QR Parser → Food Models: builds context (evidence: `FreshnessAI/app/src/main/java/com/freshnessai/analysis/QRDataParser.kt`)
- Camera Scan → Scan History DB: saves scan (evidence: `FreshnessAI/app/src/main/java/com/freshnessai/ui/ScanFragment.kt`)
- Freshness Engine → Color Data: uses mappings (evidence: `FreshnessAI/app/src/main/java/com/freshnessai/analysis/FreshnessEngine.kt`)
- Color Data → Color Mapping: loads asset (evidence: `FreshnessAI/app/src/main/java/com/freshnessai/data/FreshnessColorData.kt`)
- Scan Result → Scan History DB: reads scans (evidence: `FreshnessAI/app/src/main/java/com/freshnessai/ui/ResultFragment.kt`)
- Home Screen → Scan History DB: reads scans (evidence: `FreshnessAI/app/src/main/java/com/freshnessai/ui/HomeFragment.kt`)
- History Screen → Scan History DB: reads and clears (evidence: `FreshnessAI/app/src/main/java/com/freshnessai/ui/HistoryFragment.kt`)
- History Screen → History Adapter: updates list (evidence: `FreshnessAI/app/src/main/java/com/freshnessai/ui/HistoryFragment.kt`)
- Scan Detail → Scan History DB: loads and deletes (evidence: `FreshnessAI/app/src/main/java/com/freshnessai/ui/DetailFragment.kt`)
- Scan Detail → Freshness Gauge: sets score (evidence: `FreshnessAI/app/src/main/java/com/freshnessai/ui/DetailFragment.kt`)
