# icorrect0165/tomato-guard architecture

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

- Interactive diagram: https://gitdiagram.com/icorrect0165/tomato-guard
- Repository: https://github.com/icorrect0165/tomato-guard

## Overview

Tomato Guard AI is an offline-first Flutter app for farmers. Its main workflow is capturing or selecting a leaf image, running on-device pest and disease detection, recording results, and consulting treatment advice. Separate branches support treatment history and reminders, bilingual settings, news, backups, and report/audio services. The README documents the high-level data and service connections; Dart implementation was not sampled, so finer call ownership and some persistence wiring remain uncertain.

Main entry points: [`lib/features/detection/presentation/detection_provider.dart`](https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/detection/presentation/detection_provider.dart) (Detection State), [`lib/features/tracking/presentation/tracking_provider.dart`](https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/tracking/presentation/tracking_provider.dart) (Treatment Tracking), [`lib/features/detection/presentation/camera_screen.dart`](https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/detection/presentation/camera_screen.dart) (Capture / Upload), [`lib/features/detection/data/tflite_detection_repo.dart`](https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/detection/data/tflite_detection_repo.dart) (On-device Inference)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_diagnosis["Diagnosis"]
  node_camera["Capture / Upload<br/>[camera_screen.dart]"]
  node_detect_state["Detection State"]
  node_tflite["On-device Inference"]
  node_model["YOLOv8 Model<br/>[best_int8.tflite]"]
  node_results["Detection Results<br/>[result_screen.dart]"]
  node_details["Detection Details"]
  node_detection_store[("Detection History")]
end

subgraph group_care["Treatment &amp; Advice"]
  node_advisory_screen["Advisory Screen"]
  node_advisory_state["Advisory State"]
  node_advisory_repo["Advisory Data<br/>[advisory_repo.dart]"]
  node_treatments["Treatment Knowledge<br/>[treatments.json]"]
  node_tracking["Treatment Tracking"]
  node_treatment_repo[("Treatment Records")]
  node_add_treatment["Log Treatment"]
  node_history["Treatment History"]
  node_notifications["Reminder Service"]
end

subgraph group_support["Farmer Support"]
  node_backup_screen["Backup / Restore<br/>[backup_screen.dart]"]
  node_backup_repo["Backup Data<br/>[backup_repo.dart]"]
  node_news_screen["News Feed<br/>[news_screen.dart]"]
  node_news_state["News State<br/>[news_provider.dart]"]
  node_news_service["RSS Service<br/>[news_service.dart]"]
  node_pdf["PDF Reports<br/>[pdf_service.dart]"]
  node_tts["Read Aloud<br/>[tts_service.dart]"]
end

subgraph group_platform["Shared Platform"]
  node_settings["Settings"]
  node_language["Language State"]
  node_localizations["English / Kiswahili"]
end

node_farmer(("Farmer"))
node_rss["Google RSS"]

node_farmer -->|"captures image"| node_camera
node_camera -->|"submits image"| node_detect_state
node_detect_state -->|"runs inference"| node_tflite
node_tflite -->|"loads model"| node_model
node_detect_state -->|"presents result"| node_results
node_results -->|"opens details"| node_details
node_detect_state -->|"records detection"| node_detection_store
node_farmer -->|"requests advice"| node_advisory_screen
node_advisory_screen -->|"requests advice"| node_advisory_state
node_advisory_state -->|"loads recommendations"| node_advisory_repo
node_advisory_repo -->|"reads treatments"| node_treatments
node_farmer -->|"logs treatment"| node_add_treatment
node_add_treatment -->|"submits treatment"| node_tracking
node_tracking -->|"saves records"| node_treatment_repo
node_history -->|"loads history"| node_tracking
node_tracking -->|"schedules reminders"| node_notifications
node_farmer -->|"manages backup"| node_backup_screen
node_backup_screen -->|"exports / restores"| node_backup_repo
node_farmer -->|"views news"| node_news_screen
node_news_screen -->|"requests articles"| node_news_state
node_news_state -->|"fetches feed"| node_news_service
node_news_service -.->|"fetches RSS"| node_rss
node_farmer -->|"changes language"| node_settings
node_settings -->|"updates locale"| node_language
node_language -->|"selects strings"| node_localizations

click node_camera "https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/detection/presentation/camera_screen.dart"
click node_detect_state "https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/detection/presentation/detection_provider.dart"
click node_tflite "https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/detection/data/tflite_detection_repo.dart"
click node_model "https://github.com/icorrect0165/tomato-guard/blob/main/assets/models/best_int8.tflite"
click node_results "https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/detection/presentation/result_screen.dart"
click node_details "https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/detection/presentation/detection_detail_screen.dart"
click node_detection_store "https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/detection/data/detection_local_repo.dart"
click node_advisory_screen "https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/advisory/presentation/advisory_screen.dart"
click node_advisory_state "https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/advisory/presentation/advisory_provider.dart"
click node_advisory_repo "https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/advisory/data/advisory_repo.dart"
click node_treatments "https://github.com/icorrect0165/tomato-guard/blob/main/assets/data/treatments.json"
click node_tracking "https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/tracking/presentation/tracking_provider.dart"
click node_treatment_repo "https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/tracking/data/treatment_repo.dart"
click node_add_treatment "https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/tracking/presentation/add_treatment_screen.dart"
click node_history "https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/tracking/presentation/history_screen.dart"
click node_notifications "https://github.com/icorrect0165/tomato-guard/blob/main/lib/services/notification_service.dart"
click node_backup_screen "https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/backup_restore/presentation/backup_screen.dart"
click node_backup_repo "https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/backup_restore/data/backup_repo.dart"
click node_news_screen "https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/news/presentation/news_screen.dart"
click node_news_state "https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/news/presentation/news_provider.dart"
click node_news_service "https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/news/data/news_service.dart"
click node_pdf "https://github.com/icorrect0165/tomato-guard/blob/main/lib/services/pdf_service.dart"
click node_tts "https://github.com/icorrect0165/tomato-guard/blob/main/lib/services/tts_service.dart"
click node_settings "https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/settings/presentation/settings_screen.dart"
click node_language "https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/settings/presentation/language_provider.dart"
click node_localizations "https://github.com/icorrect0165/tomato-guard/blob/main/lib/l10n/app_localizations.dart"

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_camera,node_detect_state,node_tflite,node_model,node_results,node_details,node_detection_store toneBlue
class node_advisory_screen,node_advisory_state,node_advisory_repo,node_treatments,node_tracking,node_treatment_repo,node_add_treatment,node_history,node_notifications toneAmber
class node_backup_screen,node_backup_repo,node_news_screen,node_news_state,node_news_service,node_pdf,node_tts toneMint
class node_settings,node_language,node_localizations toneRose
class node_farmer,node_rss toneIndigo
```

## Components

### Diagnosis

- [Capture / Upload](https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/detection/presentation/camera_screen.dart): `lib/features/detection/presentation/camera_screen.dart`
- [Detection State](https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/detection/presentation/detection_provider.dart): `lib/features/detection/presentation/detection_provider.dart`
- [On-device Inference](https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/detection/data/tflite_detection_repo.dart): `lib/features/detection/data/tflite_detection_repo.dart`
- [YOLOv8 Model](https://github.com/icorrect0165/tomato-guard/blob/main/assets/models/best_int8.tflite): `assets/models/best_int8.tflite`
- [Detection Results](https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/detection/presentation/result_screen.dart): `lib/features/detection/presentation/result_screen.dart`
- [Detection Details](https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/detection/presentation/detection_detail_screen.dart): `lib/features/detection/presentation/detection_detail_screen.dart`
- [Detection History](https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/detection/data/detection_local_repo.dart): `lib/features/detection/data/detection_local_repo.dart`

### Treatment & Advice

- [Advisory Screen](https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/advisory/presentation/advisory_screen.dart): `lib/features/advisory/presentation/advisory_screen.dart`
- [Advisory State](https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/advisory/presentation/advisory_provider.dart): `lib/features/advisory/presentation/advisory_provider.dart`
- [Advisory Data](https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/advisory/data/advisory_repo.dart): `lib/features/advisory/data/advisory_repo.dart`
- [Treatment Knowledge](https://github.com/icorrect0165/tomato-guard/blob/main/assets/data/treatments.json): `assets/data/treatments.json`
- [Treatment Tracking](https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/tracking/presentation/tracking_provider.dart): `lib/features/tracking/presentation/tracking_provider.dart`
- [Treatment Records](https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/tracking/data/treatment_repo.dart): `lib/features/tracking/data/treatment_repo.dart`
- [Log Treatment](https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/tracking/presentation/add_treatment_screen.dart): `lib/features/tracking/presentation/add_treatment_screen.dart`
- [Treatment History](https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/tracking/presentation/history_screen.dart): `lib/features/tracking/presentation/history_screen.dart`
- [Reminder Service](https://github.com/icorrect0165/tomato-guard/blob/main/lib/services/notification_service.dart): `lib/services/notification_service.dart`

### Farmer Support

- [Backup / Restore](https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/backup_restore/presentation/backup_screen.dart): `lib/features/backup_restore/presentation/backup_screen.dart`
- [Backup Data](https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/backup_restore/data/backup_repo.dart): `lib/features/backup_restore/data/backup_repo.dart`
- [News Feed](https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/news/presentation/news_screen.dart): `lib/features/news/presentation/news_screen.dart`
- [News State](https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/news/presentation/news_provider.dart): `lib/features/news/presentation/news_provider.dart`
- [RSS Service](https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/news/data/news_service.dart): `lib/features/news/data/news_service.dart`
- [PDF Reports](https://github.com/icorrect0165/tomato-guard/blob/main/lib/services/pdf_service.dart): `lib/services/pdf_service.dart`
- [Read Aloud](https://github.com/icorrect0165/tomato-guard/blob/main/lib/services/tts_service.dart): `lib/services/tts_service.dart`

### Shared Platform

- [Settings](https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/settings/presentation/settings_screen.dart): `lib/features/settings/presentation/settings_screen.dart`
- [Language State](https://github.com/icorrect0165/tomato-guard/blob/main/lib/features/settings/presentation/language_provider.dart): `lib/features/settings/presentation/language_provider.dart`
- [English / Kiswahili](https://github.com/icorrect0165/tomato-guard/blob/main/lib/l10n/app_localizations.dart): `lib/l10n/app_localizations.dart`

### Other components

- **Farmer**
- **Google RSS**

## Connections

- Farmer → Capture / Upload: captures image
- Capture / Upload → Detection State: submits image
- Detection State → On-device Inference: runs inference
- On-device Inference → YOLOv8 Model: loads model
- Detection State → Detection Results: presents result
- Detection Results → Detection Details: opens details
- Detection State → Detection History: records detection
- Farmer → Advisory Screen: requests advice
- Advisory Screen → Advisory State: requests advice
- Advisory State → Advisory Data: loads recommendations
- Advisory Data → Treatment Knowledge: reads treatments
- Farmer → Log Treatment: logs treatment
- Log Treatment → Treatment Tracking: submits treatment
- Treatment Tracking → Treatment Records: saves records
- Treatment History → Treatment Tracking: loads history
- Treatment Tracking → Reminder Service: schedules reminders
- Farmer → Backup / Restore: manages backup
- Backup / Restore → Backup Data: exports / restores
- Farmer → News Feed: views news
- News Feed → News State: requests articles
- News State → RSS Service: fetches feed
- RSS Service → Google RSS: fetches RSS
- Farmer → Settings: changes language
- Settings → Language State: updates locale
- Language State → English / Kiswahili: selects strings
