# shreya-1831/leafy-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/shreya-1831/leafy-chatbot
- Repository: https://github.com/shreya-1831/leafy-chatbot

## Overview

Leafy is a plant-health companion whose main journey runs from an authenticated image upload through streamed diagnosis and care advice, with results and scans retained for later use. The React client also provides chat, history, analytics, reports, weather, and theme controls; FastAPI routes connect these capabilities to model, chatbot, and MongoDB services. Relationships reflect the sampled source and README; unsampled route and dashboard details are represented only where documented.

Main entry points: [`frontend/src/App.tsx`](https://github.com/shreya-1831/leafy-chatbot/blob/main/frontend/src/App.tsx) (App shell), [`leafy-backend/main.py`](https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/main.py) (FastAPI app), [`leafy-backend/routes/predict.py`](https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/routes/predict.py) (Prediction stream), [`leafy-backend/db.py`](https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/db.py) (MongoDB)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web client"]
  node_app["App shell<br/>[App.tsx]"]
  node_authui["Sign-in gate<br/>[AuthGate.tsx]"]
  node_authstate["Auth state<br/>[AuthContext.tsx]"]
  node_upload["Image upload<br/>[DragDropUpload.tsx]"]
  node_chatui["Chat interface<br/>[ChatInterface.tsx]"]
  node_api_client["API client<br/>[api.ts]"]
end

subgraph group_api["API workflows"]
  node_backend["FastAPI app<br/>[main.py]"]
  node_authroutes["Auth routes<br/>[auth.py]"]
  node_predictroute["Prediction stream<br/>[predict.py]"]
  node_chatroutes["Chat and sessions<br/>[chat.py]"]
  node_historyroute["Scan history<br/>[history.py]"]
  node_analyticsroute["User analytics<br/>[analytics.py]"]
  node_reportroute["PDF download<br/>[report.py]"]
end

subgraph group_intelligence["Diagnosis and advice"]
  node_model["Disease model<br/>[model_service.py]"]
  node_severity["Severity grading<br/>[severity.py]"]
  node_chatservice["Chat streaming<br/>[chatbot_service.py]"]
  node_chatbot["Plant assistant<br/>[chatbot.py]"]
end

subgraph group_persistence["Identity and data"]
  node_database[("MongoDB<br/>[db.py]")]
end

subgraph group_capabilities["Plant-care features"]
  node_pdfservice["Report generator<br/>[pdf_service.py]"]
  node_dashboard["Analytics dashboard<br/>[Dashboard.tsx]"]
  node_scan_history["History browser<br/>[ScanHistory.tsx]"]
  node_summary["Diagnosis summary<br/>[SummaryCard.tsx]"]
  node_weather["Weather widget<br/>[WeatherWidget.tsx]"]
end

node_gardener(("Gardener"))
node_weather_api["Weather service"]

node_gardener -->|"uses"| node_app
node_app -->|"shows"| node_authui
node_app -->|"shows"| node_upload
node_app -->|"shows"| node_chatui
node_app -->|"shows"| node_dashboard
node_app -->|"shows"| node_scan_history
node_app -->|"shows"| node_summary
node_app -->|"shows"| node_weather
node_authui -.->|"uses"| node_authstate
node_authui -->|"authenticates"| node_authroutes
node_authstate -->|"restores session"| node_authroutes
node_upload -->|"requests diagnosis"| node_api_client
node_api_client -->|"calls API"| node_backend
node_backend -->|"registers"| node_authroutes
node_backend -->|"registers"| node_predictroute
node_backend -->|"registers"| node_chatroutes
node_backend -->|"registers"| node_historyroute
node_backend -->|"registers"| node_analyticsroute
node_backend -->|"registers"| node_reportroute
node_predictroute -->|"predicts with"| node_model
node_predictroute -->|"grades confidence"| node_severity
node_predictroute -->|"streams advice"| node_chatservice
node_chatroutes -->|"streams replies"| node_chatservice
node_chatservice -->|"delegates"| node_chatbot
node_predictroute -->|"saves scan"| node_database
node_chatroutes -->|"stores sessions"| node_database
node_authroutes -->|"stores users"| node_database
node_historyroute -.->|"reads scans"| node_database
node_analyticsroute -.->|"queries records"| node_database
node_reportroute -->|"generates report"| node_pdfservice
node_upload -->|"streams image"| node_predictroute
node_chatui -->|"streams chat"| node_chatroutes
node_dashboard -->|"loads metrics"| node_analyticsroute
node_scan_history -->|"loads scans"| node_historyroute
node_summary -.->|"shows diagnosis"| node_chatui
node_weather -.->|"fetches conditions"| node_weather_api
node_reportroute -->|"downloads PDF"| node_gardener

click node_app "https://github.com/shreya-1831/leafy-chatbot/blob/main/frontend/src/App.tsx"
click node_authui "https://github.com/shreya-1831/leafy-chatbot/blob/main/frontend/src/components/AuthGate.tsx"
click node_authstate "https://github.com/shreya-1831/leafy-chatbot/blob/main/frontend/src/context/AuthContext.tsx"
click node_upload "https://github.com/shreya-1831/leafy-chatbot/blob/main/frontend/src/components/DragDropUpload.tsx"
click node_chatui "https://github.com/shreya-1831/leafy-chatbot/blob/main/frontend/src/components/ChatInterface.tsx"
click node_api_client "https://github.com/shreya-1831/leafy-chatbot/blob/main/frontend/src/services/api.ts"
click node_backend "https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/main.py"
click node_authroutes "https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/routes/auth.py"
click node_predictroute "https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/routes/predict.py"
click node_chatroutes "https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/routes/chat.py"
click node_historyroute "https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/routes/history.py"
click node_analyticsroute "https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/routes/analytics.py"
click node_reportroute "https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/routes/report.py"
click node_model "https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/services/model_service.py"
click node_severity "https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/utils/severity.py"
click node_chatservice "https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/services/chatbot_service.py"
click node_chatbot "https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/services/chatbot.py"
click node_database "https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/db.py"
click node_pdfservice "https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/services/pdf_service.py"
click node_dashboard "https://github.com/shreya-1831/leafy-chatbot/blob/main/frontend/src/components/Dashboard.tsx"
click node_scan_history "https://github.com/shreya-1831/leafy-chatbot/blob/main/frontend/src/components/ScanHistory.tsx"
click node_summary "https://github.com/shreya-1831/leafy-chatbot/blob/main/frontend/src/components/SummaryCard.tsx"
click node_weather "https://github.com/shreya-1831/leafy-chatbot/blob/main/frontend/src/components/WeatherWidget.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_authui,node_authstate,node_upload,node_chatui,node_api_client toneBlue
class node_backend,node_authroutes,node_predictroute,node_chatroutes,node_historyroute,node_analyticsroute,node_reportroute toneAmber
class node_model,node_severity,node_chatservice,node_chatbot toneMint
class node_database toneRose
class node_pdfservice,node_dashboard,node_scan_history,node_summary,node_weather,node_gardener,node_weather_api toneIndigo
```

## Components

### Web client

- [App shell](https://github.com/shreya-1831/leafy-chatbot/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Sign-in gate](https://github.com/shreya-1831/leafy-chatbot/blob/main/frontend/src/components/AuthGate.tsx): `frontend/src/components/AuthGate.tsx`
- [Auth state](https://github.com/shreya-1831/leafy-chatbot/blob/main/frontend/src/context/AuthContext.tsx): `frontend/src/context/AuthContext.tsx`
- [Image upload](https://github.com/shreya-1831/leafy-chatbot/blob/main/frontend/src/components/DragDropUpload.tsx): `frontend/src/components/DragDropUpload.tsx`
- [Chat interface](https://github.com/shreya-1831/leafy-chatbot/blob/main/frontend/src/components/ChatInterface.tsx): `frontend/src/components/ChatInterface.tsx`
- [API client](https://github.com/shreya-1831/leafy-chatbot/blob/main/frontend/src/services/api.ts): `frontend/src/services/api.ts`

### API workflows

- [FastAPI app](https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/main.py): `leafy-backend/main.py`
- [Auth routes](https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/routes/auth.py): `leafy-backend/routes/auth.py`
- [Prediction stream](https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/routes/predict.py): `leafy-backend/routes/predict.py`
- [Chat and sessions](https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/routes/chat.py): `leafy-backend/routes/chat.py`
- [Scan history](https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/routes/history.py): `leafy-backend/routes/history.py`
- [User analytics](https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/routes/analytics.py): `leafy-backend/routes/analytics.py`
- [PDF download](https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/routes/report.py): `leafy-backend/routes/report.py`

### Diagnosis and advice

- [Disease model](https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/services/model_service.py): `leafy-backend/services/model_service.py`
- [Severity grading](https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/utils/severity.py): `leafy-backend/utils/severity.py`
- [Chat streaming](https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/services/chatbot_service.py): `leafy-backend/services/chatbot_service.py`
- [Plant assistant](https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/services/chatbot.py): `leafy-backend/services/chatbot.py`

### Identity and data

- [MongoDB](https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/db.py): `leafy-backend/db.py`

### Plant-care features

- [Report generator](https://github.com/shreya-1831/leafy-chatbot/blob/main/leafy-backend/services/pdf_service.py): `leafy-backend/services/pdf_service.py`
- [Analytics dashboard](https://github.com/shreya-1831/leafy-chatbot/blob/main/frontend/src/components/Dashboard.tsx): `frontend/src/components/Dashboard.tsx`
- [History browser](https://github.com/shreya-1831/leafy-chatbot/blob/main/frontend/src/components/ScanHistory.tsx): `frontend/src/components/ScanHistory.tsx`
- [Diagnosis summary](https://github.com/shreya-1831/leafy-chatbot/blob/main/frontend/src/components/SummaryCard.tsx): `frontend/src/components/SummaryCard.tsx`
- [Weather widget](https://github.com/shreya-1831/leafy-chatbot/blob/main/frontend/src/components/WeatherWidget.tsx): `frontend/src/components/WeatherWidget.tsx`

### Other components

- **Gardener**
- **Weather service**

## Connections

- Gardener → App shell: uses (evidence: `README.md`)
- App shell → Sign-in gate: shows (evidence: `frontend/src/App.tsx`)
- App shell → Image upload: shows (evidence: `frontend/src/App.tsx`)
- App shell → Chat interface: shows (evidence: `frontend/src/App.tsx`)
- App shell → Analytics dashboard: shows (evidence: `frontend/src/App.tsx`)
- App shell → History browser: shows (evidence: `frontend/src/App.tsx`)
- App shell → Diagnosis summary: shows (evidence: `frontend/src/App.tsx`)
- App shell → Weather widget: shows (evidence: `frontend/src/App.tsx`)
- Sign-in gate → Auth state: uses
- Sign-in gate → Auth routes: authenticates (evidence: `README.md`)
- Auth state → Auth routes: restores session (evidence: `frontend/src/context/AuthContext.tsx`)
- Image upload → API client: requests diagnosis (evidence: `frontend/src/components/DragDropUpload.tsx`)
- API client → FastAPI app: calls API (evidence: `README.md`)
- FastAPI app → Auth routes: registers (evidence: `leafy-backend/main.py`)
- FastAPI app → Prediction stream: registers (evidence: `leafy-backend/main.py`)
- FastAPI app → Chat and sessions: registers (evidence: `leafy-backend/main.py`)
- FastAPI app → Scan history: registers (evidence: `leafy-backend/main.py`)
- FastAPI app → User analytics: registers (evidence: `leafy-backend/main.py`)
- FastAPI app → PDF download: registers (evidence: `leafy-backend/main.py`)
- Prediction stream → Disease model: predicts with (evidence: `leafy-backend/routes/predict.py`)
- Prediction stream → Severity grading: grades confidence (evidence: `leafy-backend/routes/predict.py`)
- Prediction stream → Chat streaming: streams advice (evidence: `leafy-backend/routes/predict.py`)
- Chat and sessions → Chat streaming: streams replies (evidence: `leafy-backend/routes/chat.py`)
- Chat streaming → Plant assistant: delegates (evidence: `leafy-backend/services/chatbot_service.py`)
- Prediction stream → MongoDB: saves scan (evidence: `leafy-backend/routes/predict.py`)
- Chat and sessions → MongoDB: stores sessions (evidence: `leafy-backend/routes/chat.py`)
- Auth routes → MongoDB: stores users (evidence: `leafy-backend/routes/auth.py`)
- Scan history → MongoDB: reads scans
- User analytics → MongoDB: queries records
- PDF download → Report generator: generates report (evidence: `leafy-backend/routes/report.py`)
- Image upload → Prediction stream: streams image (evidence: `README.md`)
- Chat interface → Chat and sessions: streams chat (evidence: `README.md`)
- Analytics dashboard → User analytics: loads metrics (evidence: `README.md`)
- History browser → Scan history: loads scans (evidence: `README.md`)
- Diagnosis summary → Chat interface: shows diagnosis
- Weather widget → Weather service: fetches conditions (evidence: `README.md`)
- PDF download → Gardener: downloads PDF (evidence: `README.md`)
