# mwakidenis/smart-farmer architecture

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

- Interactive diagram: https://gitdiagram.com/mwakidenis/smart-farmer
- Repository: https://github.com/mwakidenis/smart-farmer

## Overview

AI Crop Doctor is a farmer-facing plant-health platform. Its central workflow is to upload a plant image, receive an AI-assisted disease assessment and treatment guidance, and review scan history; the README also describes expert consultations, community discussion, disease reference, learning videos, timeline tracking, and agricultural intelligence. The sampled router and scan page show the application entry and scan UI; unsampled feature internals are represented by their exact tree paths, with uncertain implementation links omitted or marked unverified.

Main entry points: [`src/App.tsx`](https://github.com/mwakidenis/smart-farmer/blob/main/src/App.tsx) (App routing), [`src/pages/Index.tsx`](https://github.com/mwakidenis/smart-farmer/blob/main/src/pages/Index.tsx) (Scan workflow), [`src/components/AuthProvider.tsx`](https://github.com/mwakidenis/smart-farmer/blob/main/src/components/AuthProvider.tsx) (Authentication state), [`src/pages/SpecialistChat.tsx`](https://github.com/mwakidenis/smart-farmer/blob/main/src/pages/SpecialistChat.tsx) (Specialist consultations)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Application access"]
  node_router["App routing<br/>[App.tsx]"]
  node_landing["Landing experience<br/>[Landing.tsx]"]
end

subgraph group_diagnosis["Plant diagnosis"]
  node_scan["Scan workflow<br/>[Index.tsx]"]
  node_upload["Image upload<br/>[ImageUpload.tsx]"]
  node_ai["AI analysis"]
  node_diagnosisresult["Diagnosis results"]
  node_history["Scan history"]
end

subgraph group_knowledge["Expertise and learning"]
  node_chat["Specialist consultations<br/>[SpecialistChat.tsx]"]
  node_chatui["Consultation interface<br/>[ChatInterface.tsx]"]
  node_forum["Community forum<br/>[CommunityForum.tsx]"]
  node_forumhook["Forum data access<br/>[use-forum.tsx]"]
  node_diseases["Disease encyclopedia<br/>[DiseaseLibrary.tsx]"]
  node_diseasedata["Disease reference data<br/>[diseases.ts]"]
  node_videos["Educational videos<br/>[VideoLibrary.tsx]"]
end

subgraph group_intelligence["Crop intelligence"]
  node_timeline["Plant health timeline<br/>[PlantTimeline.tsx]"]
  node_pest["Pest prediction<br/>[PestPrediction.tsx]"]
  node_analytics["Agricultural analytics"]
  node_weather["Weather service<br/>[weatherService.ts]"]
end

subgraph group_platform["Identity and services"]
  node_authpage["Sign in and registration<br/>[Auth.tsx]"]
  node_auth["Authentication state<br/>[AuthProvider.tsx]"]
  node_supabase[("Supabase backend<br/>[client.ts]")]
  node_mock[("Mock data fallback<br/>[mockDataService.ts]")]
  node_payment["M-Pesa payments<br/>[mpesaService.ts]"]
end

node_grower(("Grower"))

node_grower -->|"opens app"| node_router
node_router -->|"routes to"| node_landing
node_router -->|"routes to"| node_authpage
node_router -->|"routes to"| node_scan
node_router -->|"routes to"| node_chat
node_router -->|"routes to"| node_forum
node_router -->|"routes to"| node_diseases
node_router -->|"routes to"| node_videos
node_router -->|"routes to"| node_timeline
node_authpage -->|"uses auth"| node_auth
node_auth -->|"checks session"| node_supabase
node_auth -->|"falls back to"| node_mock
node_scan -->|"renders"| node_upload
node_scan -.->|"analyzes image"| node_ai
node_scan -.->|"shows assessment"| node_diagnosisresult
node_scan -.->|"shows history"| node_history
node_chat -.->|"uses interface"| node_chatui
node_forum -.->|"uses data hook"| node_forumhook
node_forumhook -->|"queries backend"| node_supabase
node_diseases -.->|"uses reference"| node_diseasedata
node_grower -->|"tracks health"| node_timeline
node_grower -->|"checks predictions"| node_pest
node_grower -->|"learns from"| node_videos
node_grower -->|"consults experts"| node_chat
node_grower -->|"shares knowledge"| node_forum
node_grower -->|"looks up diseases"| node_diseases

click node_router "https://github.com/mwakidenis/smart-farmer/blob/main/src/App.tsx"
click node_landing "https://github.com/mwakidenis/smart-farmer/blob/main/src/pages/Landing.tsx"
click node_authpage "https://github.com/mwakidenis/smart-farmer/blob/main/src/pages/Auth.tsx"
click node_auth "https://github.com/mwakidenis/smart-farmer/blob/main/src/components/AuthProvider.tsx"
click node_supabase "https://github.com/mwakidenis/smart-farmer/blob/main/src/integrations/supabase/client.ts"
click node_mock "https://github.com/mwakidenis/smart-farmer/blob/main/src/services/mockDataService.ts"
click node_scan "https://github.com/mwakidenis/smart-farmer/blob/main/src/pages/Index.tsx"
click node_upload "https://github.com/mwakidenis/smart-farmer/blob/main/src/components/scan/ImageUpload.tsx"
click node_ai "https://github.com/mwakidenis/smart-farmer/blob/main/src/services/enhancedAIService.ts"
click node_diagnosisresult "https://github.com/mwakidenis/smart-farmer/blob/main/src/components/scan/DiagnosisResult.tsx"
click node_history "https://github.com/mwakidenis/smart-farmer/blob/main/src/components/history/ScanHistoryList.tsx"
click node_chat "https://github.com/mwakidenis/smart-farmer/blob/main/src/pages/SpecialistChat.tsx"
click node_chatui "https://github.com/mwakidenis/smart-farmer/blob/main/src/components/chat/ChatInterface.tsx"
click node_forum "https://github.com/mwakidenis/smart-farmer/blob/main/src/pages/CommunityForum.tsx"
click node_forumhook "https://github.com/mwakidenis/smart-farmer/blob/main/src/hooks/use-forum.tsx"
click node_diseases "https://github.com/mwakidenis/smart-farmer/blob/main/src/pages/DiseaseLibrary.tsx"
click node_diseasedata "https://github.com/mwakidenis/smart-farmer/blob/main/src/data/diseases.ts"
click node_videos "https://github.com/mwakidenis/smart-farmer/blob/main/src/pages/VideoLibrary.tsx"
click node_timeline "https://github.com/mwakidenis/smart-farmer/blob/main/src/pages/PlantTimeline.tsx"
click node_pest "https://github.com/mwakidenis/smart-farmer/blob/main/src/pages/PestPrediction.tsx"
click node_analytics "https://github.com/mwakidenis/smart-farmer/blob/main/src/components/analytics/AdvancedAnalytics.tsx"
click node_weather "https://github.com/mwakidenis/smart-farmer/blob/main/src/services/weatherService.ts"
click node_payment "https://github.com/mwakidenis/smart-farmer/blob/main/src/services/mpesaService.ts"

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_router,node_landing toneBlue
class node_scan,node_upload,node_ai,node_diagnosisresult,node_history toneAmber
class node_chat,node_chatui,node_forum,node_forumhook,node_diseases,node_diseasedata,node_videos toneMint
class node_timeline,node_pest,node_analytics,node_weather toneRose
class node_authpage,node_auth,node_supabase,node_mock,node_payment,node_grower toneIndigo
```

## Components

### Application access

- [App routing](https://github.com/mwakidenis/smart-farmer/blob/main/src/App.tsx): `src/App.tsx`
- [Landing experience](https://github.com/mwakidenis/smart-farmer/blob/main/src/pages/Landing.tsx): `src/pages/Landing.tsx`

### Plant diagnosis

- [Scan workflow](https://github.com/mwakidenis/smart-farmer/blob/main/src/pages/Index.tsx): `src/pages/Index.tsx`
- [Image upload](https://github.com/mwakidenis/smart-farmer/blob/main/src/components/scan/ImageUpload.tsx): `src/components/scan/ImageUpload.tsx`
- [AI analysis](https://github.com/mwakidenis/smart-farmer/blob/main/src/services/enhancedAIService.ts): `src/services/enhancedAIService.ts`
- [Diagnosis results](https://github.com/mwakidenis/smart-farmer/blob/main/src/components/scan/DiagnosisResult.tsx): `src/components/scan/DiagnosisResult.tsx`
- [Scan history](https://github.com/mwakidenis/smart-farmer/blob/main/src/components/history/ScanHistoryList.tsx): `src/components/history/ScanHistoryList.tsx`

### Expertise and learning

- [Specialist consultations](https://github.com/mwakidenis/smart-farmer/blob/main/src/pages/SpecialistChat.tsx): `src/pages/SpecialistChat.tsx`
- [Consultation interface](https://github.com/mwakidenis/smart-farmer/blob/main/src/components/chat/ChatInterface.tsx): `src/components/chat/ChatInterface.tsx`
- [Community forum](https://github.com/mwakidenis/smart-farmer/blob/main/src/pages/CommunityForum.tsx): `src/pages/CommunityForum.tsx`
- [Forum data access](https://github.com/mwakidenis/smart-farmer/blob/main/src/hooks/use-forum.tsx): `src/hooks/use-forum.tsx`
- [Disease encyclopedia](https://github.com/mwakidenis/smart-farmer/blob/main/src/pages/DiseaseLibrary.tsx): `src/pages/DiseaseLibrary.tsx`
- [Disease reference data](https://github.com/mwakidenis/smart-farmer/blob/main/src/data/diseases.ts): `src/data/diseases.ts`
- [Educational videos](https://github.com/mwakidenis/smart-farmer/blob/main/src/pages/VideoLibrary.tsx): `src/pages/VideoLibrary.tsx`

### Crop intelligence

- [Plant health timeline](https://github.com/mwakidenis/smart-farmer/blob/main/src/pages/PlantTimeline.tsx): `src/pages/PlantTimeline.tsx`
- [Pest prediction](https://github.com/mwakidenis/smart-farmer/blob/main/src/pages/PestPrediction.tsx): `src/pages/PestPrediction.tsx`
- [Agricultural analytics](https://github.com/mwakidenis/smart-farmer/blob/main/src/components/analytics/AdvancedAnalytics.tsx): `src/components/analytics/AdvancedAnalytics.tsx`
- [Weather service](https://github.com/mwakidenis/smart-farmer/blob/main/src/services/weatherService.ts): `src/services/weatherService.ts`

### Identity and services

- [Sign in and registration](https://github.com/mwakidenis/smart-farmer/blob/main/src/pages/Auth.tsx): `src/pages/Auth.tsx`
- [Authentication state](https://github.com/mwakidenis/smart-farmer/blob/main/src/components/AuthProvider.tsx): `src/components/AuthProvider.tsx`
- [Supabase backend](https://github.com/mwakidenis/smart-farmer/blob/main/src/integrations/supabase/client.ts): `src/integrations/supabase/client.ts`
- [Mock data fallback](https://github.com/mwakidenis/smart-farmer/blob/main/src/services/mockDataService.ts): `src/services/mockDataService.ts`
- [M-Pesa payments](https://github.com/mwakidenis/smart-farmer/blob/main/src/services/mpesaService.ts): `src/services/mpesaService.ts`

### Other components

- **Grower**

## Connections

- Grower → App routing: opens app (evidence: `README.md`)
- App routing → Landing experience: routes to (evidence: `src/App.tsx`)
- App routing → Sign in and registration: routes to (evidence: `src/App.tsx`)
- App routing → Scan workflow: routes to (evidence: `src/App.tsx`)
- App routing → Specialist consultations: routes to (evidence: `src/App.tsx`)
- App routing → Community forum: routes to (evidence: `src/App.tsx`)
- App routing → Disease encyclopedia: routes to (evidence: `src/App.tsx`)
- App routing → Educational videos: routes to (evidence: `src/App.tsx`)
- App routing → Plant health timeline: routes to (evidence: `src/App.tsx`)
- Sign in and registration → Authentication state: uses auth (evidence: `src/pages/Auth.tsx`)
- Authentication state → Supabase backend: checks session (evidence: `src/components/AuthProvider.tsx`)
- Authentication state → Mock data fallback: falls back to (evidence: `src/components/AuthProvider.tsx`)
- Scan workflow → Image upload: renders (evidence: `src/pages/Index.tsx`)
- Scan workflow → AI analysis: analyzes image (evidence: `src/pages/Index.tsx`)
- Scan workflow → Diagnosis results: shows assessment (evidence: `src/pages/Index.tsx`)
- Scan workflow → Scan history: shows history (evidence: `src/pages/Index.tsx`)
- Specialist consultations → Consultation interface: uses interface
- Community forum → Forum data access: uses data hook
- Forum data access → Supabase backend: queries backend (evidence: `src/hooks/use-forum.tsx`)
- Disease encyclopedia → Disease reference data: uses reference
- Grower → Plant health timeline: tracks health (evidence: `README.md`)
- Grower → Pest prediction: checks predictions (evidence: `README.md`)
- Grower → Educational videos: learns from (evidence: `README.md`)
- Grower → Specialist consultations: consults experts (evidence: `README.md`)
- Grower → Community forum: shares knowledge (evidence: `README.md`)
- Grower → Disease encyclopedia: looks up diseases (evidence: `README.md`)
