# phanna125/cornapp architecture

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

- Interactive diagram: https://gitdiagram.com/phanna125/cornapp
- Repository: https://github.com/phanna125/cornapp

## Overview

Corn Leaf Doctor is an offline-first Telegram Mini App for identifying five corn-leaf conditions and presenting confidence scores and treatment advice. Farmers select or capture leaf images on Home; App orchestrates preprocessing and local ONNX/WASM inference, then saves results and displays analysis and diagnosis screens. The app also supports batch scans, sample leaves, recent-scan history, Telegram sharing and native controls, plus an included bot for launching the Mini App. README describes these capabilities; some component internals and the bot implementation were not excerpted.

Main entry points: [`src/App.tsx`](https://github.com/phanna125/cornapp/blob/main/src/App.tsx) (App orchestrator), [`src/components/HomeScreen.tsx`](https://github.com/phanna125/cornapp/blob/main/src/components/HomeScreen.tsx) (Home scanner), [`src/utils/inference.ts`](https://github.com/phanna125/cornapp/blob/main/src/utils/inference.ts) (Inference engine), [`src/utils/telegram.ts`](https://github.com/phanna125/cornapp/blob/main/src/utils/telegram.ts) (Telegram helpers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflow["Scan workflow"]
  node_app["App orchestrator<br/>[App.tsx]"]
  node_home["Home scanner<br/>[HomeScreen.tsx]"]
  node_analysis["Analysis screen"]
  node_diagnosis["Diagnosis screen"]
  node_topbar["Status and mode<br/>[TopBar.tsx]"]
  node_entry["React entry<br/>[main.tsx]"]
end

subgraph group_ml["On-device diagnosis"]
  node_inference["Inference engine<br/>[inference.ts]"]
  node_preprocess["Image preprocessing"]
  node_model["Corn ONNX model"]
end

subgraph group_content["Advice and history"]
  node_diseases["Disease catalog<br/>[diseases.ts]"]
  node_translations["UI translations<br/>[translations.ts]"]
  node_history["Scan history<br/>[history.ts]"]
  node_localstorage[("Browser storage")]
end

subgraph group_telegram["Telegram integration"]
  node_telegramutils["Telegram helpers<br/>[telegram.ts]"]
  node_telegram["Telegram platform"]
  node_bot["Launch bot<br/>[bot.py]"]
end

node_farmer(("Farmer"))

node_farmer -->|"selects images"| node_home
node_entry -->|"renders"| node_app
node_app -->|"renders"| node_home
node_app -->|"renders"| node_analysis
node_app -->|"renders"| node_diagnosis
node_app -->|"renders"| node_topbar
node_home -->|"submits images"| node_app
node_app -->|"runs diagnosis"| node_inference
node_inference -->|"preprocesses images"| node_preprocess
node_inference -->|"loads model"| node_model
node_inference -->|"maps classes"| node_diseases
node_app -->|"saves scans"| node_history
node_home -->|"loads demo scans"| node_history
node_history -->|"reads and writes"| node_localstorage
node_home -->|"builds sample scans"| node_diseases
node_app -->|"initializes controls"| node_telegramutils
node_topbar -->|"triggers haptics"| node_telegramutils
node_diagnosis -->|"shares results"| node_telegramutils
node_telegramutils -->|"uses WebApp API"| node_telegram
node_bot -.->|"configures launch"| node_telegram
node_home -->|"displays copy"| node_translations
node_diagnosis -->|"displays copy"| node_translations
node_app -->|"configures button"| node_translations

click node_app "https://github.com/phanna125/cornapp/blob/main/src/App.tsx"
click node_home "https://github.com/phanna125/cornapp/blob/main/src/components/HomeScreen.tsx"
click node_analysis "https://github.com/phanna125/cornapp/blob/main/src/components/AnalyzingScreen.tsx"
click node_diagnosis "https://github.com/phanna125/cornapp/blob/main/src/components/DiagnosisScreen.tsx"
click node_topbar "https://github.com/phanna125/cornapp/blob/main/src/components/TopBar.tsx"
click node_inference "https://github.com/phanna125/cornapp/blob/main/src/utils/inference.ts"
click node_preprocess "https://github.com/phanna125/cornapp/blob/main/src/utils/imagePreprocessing.ts"
click node_model "https://github.com/phanna125/cornapp/blob/main/public/models/mobilenetv3_corn_single.onnx"
click node_diseases "https://github.com/phanna125/cornapp/blob/main/src/data/diseases.ts"
click node_translations "https://github.com/phanna125/cornapp/blob/main/src/data/translations.ts"
click node_history "https://github.com/phanna125/cornapp/blob/main/src/utils/history.ts"
click node_telegramutils "https://github.com/phanna125/cornapp/blob/main/src/utils/telegram.ts"
click node_bot "https://github.com/phanna125/cornapp/blob/main/bot/bot.py"
click node_entry "https://github.com/phanna125/cornapp/blob/main/src/main.tsx"

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_app,node_home,node_analysis,node_diagnosis,node_topbar,node_entry toneBlue
class node_inference,node_preprocess,node_model toneAmber
class node_diseases,node_translations,node_history,node_localstorage toneMint
class node_telegramutils,node_telegram,node_bot toneRose
class node_farmer toneIndigo
```

## Components

### Scan workflow

- [App orchestrator](https://github.com/phanna125/cornapp/blob/main/src/App.tsx): `src/App.tsx`
- [Home scanner](https://github.com/phanna125/cornapp/blob/main/src/components/HomeScreen.tsx): `src/components/HomeScreen.tsx`
- [Analysis screen](https://github.com/phanna125/cornapp/blob/main/src/components/AnalyzingScreen.tsx): `src/components/AnalyzingScreen.tsx`
- [Diagnosis screen](https://github.com/phanna125/cornapp/blob/main/src/components/DiagnosisScreen.tsx): `src/components/DiagnosisScreen.tsx`
- [Status and mode](https://github.com/phanna125/cornapp/blob/main/src/components/TopBar.tsx): `src/components/TopBar.tsx`
- [React entry](https://github.com/phanna125/cornapp/blob/main/src/main.tsx): `src/main.tsx`

### On-device diagnosis

- [Inference engine](https://github.com/phanna125/cornapp/blob/main/src/utils/inference.ts): `src/utils/inference.ts`
- [Image preprocessing](https://github.com/phanna125/cornapp/blob/main/src/utils/imagePreprocessing.ts): `src/utils/imagePreprocessing.ts`
- [Corn ONNX model](https://github.com/phanna125/cornapp/blob/main/public/models/mobilenetv3_corn_single.onnx): `public/models/mobilenetv3_corn_single.onnx`

### Advice and history

- [Disease catalog](https://github.com/phanna125/cornapp/blob/main/src/data/diseases.ts): `src/data/diseases.ts`
- [UI translations](https://github.com/phanna125/cornapp/blob/main/src/data/translations.ts): `src/data/translations.ts`
- [Scan history](https://github.com/phanna125/cornapp/blob/main/src/utils/history.ts): `src/utils/history.ts`
- **Browser storage**

### Telegram integration

- [Telegram helpers](https://github.com/phanna125/cornapp/blob/main/src/utils/telegram.ts): `src/utils/telegram.ts`
- **Telegram platform**
- [Launch bot](https://github.com/phanna125/cornapp/blob/main/bot/bot.py): `bot/bot.py`

### Other components

- **Farmer**

## Connections

- Farmer → Home scanner: selects images (evidence: `README.md`)
- React entry → App orchestrator: renders (evidence: `src/main.tsx`)
- App orchestrator → Home scanner: renders (evidence: `src/App.tsx`)
- App orchestrator → Analysis screen: renders (evidence: `src/App.tsx`)
- App orchestrator → Diagnosis screen: renders (evidence: `src/App.tsx`)
- App orchestrator → Status and mode: renders (evidence: `src/App.tsx`)
- Home scanner → App orchestrator: submits images (evidence: `src/App.tsx`)
- App orchestrator → Inference engine: runs diagnosis (evidence: `src/App.tsx`)
- Inference engine → Image preprocessing: preprocesses images (evidence: `src/utils/inference.ts`)
- Inference engine → Corn ONNX model: loads model (evidence: `README.md`)
- Inference engine → Disease catalog: maps classes (evidence: `src/utils/inference.ts`)
- App orchestrator → Scan history: saves scans (evidence: `src/App.tsx`)
- Home scanner → Scan history: loads demo scans (evidence: `src/components/HomeScreen.tsx`)
- Scan history → Browser storage: reads and writes (evidence: `src/utils/history.ts`)
- Home scanner → Disease catalog: builds sample scans (evidence: `src/components/HomeScreen.tsx`)
- App orchestrator → Telegram helpers: initializes controls (evidence: `src/App.tsx`)
- Status and mode → Telegram helpers: triggers haptics (evidence: `src/components/TopBar.tsx`)
- Diagnosis screen → Telegram helpers: shares results (evidence: `src/components/DiagnosisScreen.tsx`)
- Telegram helpers → Telegram platform: uses WebApp API (evidence: `src/utils/telegram.ts`)
- Launch bot → Telegram platform: configures launch (evidence: `README.md`)
- Home scanner → UI translations: displays copy (evidence: `src/components/HomeScreen.tsx`)
- Diagnosis screen → UI translations: displays copy (evidence: `src/components/DiagnosisScreen.tsx`)
- App orchestrator → UI translations: configures button (evidence: `src/App.tsx`)
