# shivighn/agridoc architecture

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

- Interactive diagram: https://gitdiagram.com/shivighn/agridoc
- Repository: https://github.com/shivighn/agridoc

## Overview

AgriDoc lets a signed-in user upload a plant image, receive a disease classification, consult the Plant Doctor, and optionally save and revisit the report. The frontend preprocesses images and sends prediction tensors to the API; the backend runs model inference and stores reports. Separate branches cover Google sign-in, user profiles, rate limiting, and diagnosis history. The README also describes LLM-backed chat and persistent conversations; chat implementation details and several routes were not sampled, so those relationships are shown only where documented or directly evidenced.

Main entry points: [`frontend/src/contexts/AuthContext.jsx`](https://github.com/shivighn/agridoc/blob/master/frontend/src/contexts/AuthContext.jsx) (Auth context), [`frontend/src/pages/Diagnose.jsx`](https://github.com/shivighn/agridoc/blob/master/frontend/src/pages/Diagnose.jsx) (Diagnose page), [`backend/src/server.js`](https://github.com/shivighn/agridoc/blob/master/backend/src/server.js) (Express server), [`frontend/src/App.jsx`](https://github.com/shivighn/agridoc/blob/master/frontend/src/App.jsx) (App routing)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend_diagnosis["Diagnosis experience"]
  node_diagnose_page["Diagnose page<br/>[Diagnose.jsx]"]
  node_image_upload["Image upload<br/>[ImageUpload.jsx]"]
  node_prediction_result["Prediction result"]
  node_plant_chat["Plant Doctor chat"]
end

subgraph group_frontend_account["User experience"]
  node_app["App routing<br/>[App.jsx]"]
  node_auth_context["Auth context<br/>[AuthContext.jsx]"]
  node_navbar["Navigation<br/>[Navbar.jsx]"]
  node_home_page["Home page<br/>[Home.jsx]"]
  node_profile_page["Profile page<br/>[Profile.jsx]"]
  node_api_config["API endpoint config<br/>[api.js]"]
  node_history_page["History page<br/>[History.jsx]"]
end

subgraph group_backend_api["API and domain"]
  node_server["Express server<br/>[server.js]"]
  node_auth_routes["Authentication routes<br/>[auth.js]"]
  node_disease_routes["Disease routes<br/>[disease.js]"]
  node_chat_routes["Chat routes<br/>[chat.js]"]
  node_history_routes["History routes<br/>[history.js]"]
  node_rate_limiter["Rate limiter<br/>[rateLimiter.js]"]
end

subgraph group_backend_data_ai["Data and AI"]
  node_db_config["Database connection<br/>[db.js]"]
  node_user_model[("User records<br/>[User.js]")]
  node_report_model[("Diagnosis reports<br/>[DiseaseReport.js]")]
  node_predictor["Model inference<br/>[modelPredictor.js]"]
  node_tf_model["TensorFlow model<br/>[model.json]"]
end

node_user(("Farmer or gardener"))
node_mongo[("MongoDB")]
node_google["Google OAuth"]
node_llm["LLM service"]

node_user -->|"uses"| node_app
node_app -->|"provides auth"| node_auth_context
node_app -->|"renders"| node_navbar
node_app -->|"routes to"| node_home_page
node_app -->|"routes to"| node_diagnose_page
node_app -->|"routes to"| node_history_page
node_app -->|"routes to"| node_profile_page
node_navbar -->|"reads auth"| node_auth_context
node_profile_page -->|"reads auth"| node_auth_context
node_auth_context -->|"gets API URL"| node_api_config
node_auth_context -->|"requests status"| node_auth_routes
node_auth_context -->|"starts login"| node_auth_routes
node_auth_context -->|"requests logout"| node_auth_routes
node_diagnose_page -->|"reads user"| node_auth_context
node_diagnose_page -->|"renders"| node_image_upload
node_diagnose_page -->|"renders"| node_prediction_result
node_diagnose_page -->|"renders"| node_plant_chat
node_diagnose_page -->|"gets API URL"| node_api_config
node_diagnose_page -->|"posts tensor"| node_disease_routes
node_diagnose_page -->|"saves report"| node_history_routes
node_plant_chat -->|"gets API URL"| node_api_config
node_plant_chat -->|"posts message"| node_chat_routes
node_history_page -->|"reads user"| node_auth_context
node_history_page -->|"gets API URL"| node_api_config
node_history_page -->|"loads or deletes"| node_history_routes
node_server -->|"connects database"| node_db_config
node_server -->|"mounts routes"| node_auth_routes
node_server -->|"mounts routes"| node_disease_routes
node_server -->|"mounts routes"| node_chat_routes
node_server -->|"mounts routes"| node_history_routes
node_server -->|"applies limiter"| node_rate_limiter
node_server -->|"serves model"| node_tf_model
node_auth_routes -->|"reads or creates"| node_user_model
node_db_config -->|"connects"| node_mongo
node_rate_limiter -.->|"limits via Redis"| node_mongo
node_disease_routes -->|"requests inference"| node_predictor
node_disease_routes -->|"stores diagnosis"| node_report_model
node_predictor -->|"loads model"| node_tf_model
node_history_routes -->|"manages history"| node_report_model
node_chat_routes -->|"uses report data"| node_report_model
node_chat_routes -.->|"requests responses"| node_llm
node_user_model -.->|"persists users"| node_mongo
node_report_model -.->|"persists reports"| node_mongo

click node_app "https://github.com/shivighn/agridoc/blob/master/frontend/src/App.jsx"
click node_auth_context "https://github.com/shivighn/agridoc/blob/master/frontend/src/contexts/AuthContext.jsx"
click node_navbar "https://github.com/shivighn/agridoc/blob/master/frontend/src/components/Navbar.jsx"
click node_home_page "https://github.com/shivighn/agridoc/blob/master/frontend/src/pages/Home.jsx"
click node_profile_page "https://github.com/shivighn/agridoc/blob/master/frontend/src/pages/Profile.jsx"
click node_diagnose_page "https://github.com/shivighn/agridoc/blob/master/frontend/src/pages/Diagnose.jsx"
click node_image_upload "https://github.com/shivighn/agridoc/blob/master/frontend/src/components/ImageUpload.jsx"
click node_prediction_result "https://github.com/shivighn/agridoc/blob/master/frontend/src/components/PredictionResult.jsx"
click node_plant_chat "https://github.com/shivighn/agridoc/blob/master/frontend/src/components/PlantDoctorChat.jsx"
click node_api_config "https://github.com/shivighn/agridoc/blob/master/frontend/src/config/api.js"
click node_history_page "https://github.com/shivighn/agridoc/blob/master/frontend/src/pages/History.jsx"
click node_server "https://github.com/shivighn/agridoc/blob/master/backend/src/server.js"
click node_auth_routes "https://github.com/shivighn/agridoc/blob/master/backend/src/routes/auth.js"
click node_disease_routes "https://github.com/shivighn/agridoc/blob/master/backend/src/routes/disease.js"
click node_chat_routes "https://github.com/shivighn/agridoc/blob/master/backend/src/routes/chat.js"
click node_history_routes "https://github.com/shivighn/agridoc/blob/master/backend/src/routes/history.js"
click node_rate_limiter "https://github.com/shivighn/agridoc/blob/master/backend/src/middleware/rateLimiter.js"
click node_db_config "https://github.com/shivighn/agridoc/blob/master/backend/src/config/db.js"
click node_user_model "https://github.com/shivighn/agridoc/blob/master/backend/src/models/User.js"
click node_report_model "https://github.com/shivighn/agridoc/blob/master/backend/src/models/DiseaseReport.js"
click node_predictor "https://github.com/shivighn/agridoc/blob/master/backend/src/utils/modelPredictor.js"
click node_tf_model "https://github.com/shivighn/agridoc/blob/master/backend/src/models/ML_model/tfjs_model1/model.json"

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_diagnose_page,node_image_upload,node_prediction_result,node_plant_chat toneBlue
class node_app,node_auth_context,node_navbar,node_home_page,node_profile_page,node_api_config,node_history_page,node_mongo toneAmber
class node_server,node_auth_routes,node_disease_routes,node_chat_routes,node_history_routes,node_rate_limiter toneMint
class node_db_config,node_user_model,node_report_model,node_predictor,node_tf_model toneRose
class node_user,node_google,node_llm toneIndigo
```

## Components

### Diagnosis experience

- [Diagnose page](https://github.com/shivighn/agridoc/blob/master/frontend/src/pages/Diagnose.jsx): `frontend/src/pages/Diagnose.jsx`
- [Image upload](https://github.com/shivighn/agridoc/blob/master/frontend/src/components/ImageUpload.jsx): `frontend/src/components/ImageUpload.jsx`
- [Prediction result](https://github.com/shivighn/agridoc/blob/master/frontend/src/components/PredictionResult.jsx): `frontend/src/components/PredictionResult.jsx`
- [Plant Doctor chat](https://github.com/shivighn/agridoc/blob/master/frontend/src/components/PlantDoctorChat.jsx): `frontend/src/components/PlantDoctorChat.jsx`

### User experience

- [App routing](https://github.com/shivighn/agridoc/blob/master/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Auth context](https://github.com/shivighn/agridoc/blob/master/frontend/src/contexts/AuthContext.jsx): `frontend/src/contexts/AuthContext.jsx`
- [Navigation](https://github.com/shivighn/agridoc/blob/master/frontend/src/components/Navbar.jsx): `frontend/src/components/Navbar.jsx`
- [Home page](https://github.com/shivighn/agridoc/blob/master/frontend/src/pages/Home.jsx): `frontend/src/pages/Home.jsx`
- [Profile page](https://github.com/shivighn/agridoc/blob/master/frontend/src/pages/Profile.jsx): `frontend/src/pages/Profile.jsx`
- [API endpoint config](https://github.com/shivighn/agridoc/blob/master/frontend/src/config/api.js): `frontend/src/config/api.js`
- [History page](https://github.com/shivighn/agridoc/blob/master/frontend/src/pages/History.jsx): `frontend/src/pages/History.jsx`

### API and domain

- [Express server](https://github.com/shivighn/agridoc/blob/master/backend/src/server.js): `backend/src/server.js`
- [Authentication routes](https://github.com/shivighn/agridoc/blob/master/backend/src/routes/auth.js): `backend/src/routes/auth.js`
- [Disease routes](https://github.com/shivighn/agridoc/blob/master/backend/src/routes/disease.js): `backend/src/routes/disease.js`
- [Chat routes](https://github.com/shivighn/agridoc/blob/master/backend/src/routes/chat.js): `backend/src/routes/chat.js`
- [History routes](https://github.com/shivighn/agridoc/blob/master/backend/src/routes/history.js): `backend/src/routes/history.js`
- [Rate limiter](https://github.com/shivighn/agridoc/blob/master/backend/src/middleware/rateLimiter.js): `backend/src/middleware/rateLimiter.js`

### Data and AI

- [Database connection](https://github.com/shivighn/agridoc/blob/master/backend/src/config/db.js): `backend/src/config/db.js`
- [User records](https://github.com/shivighn/agridoc/blob/master/backend/src/models/User.js): `backend/src/models/User.js`
- [Diagnosis reports](https://github.com/shivighn/agridoc/blob/master/backend/src/models/DiseaseReport.js): `backend/src/models/DiseaseReport.js`
- [Model inference](https://github.com/shivighn/agridoc/blob/master/backend/src/utils/modelPredictor.js): `backend/src/utils/modelPredictor.js`
- [TensorFlow model](https://github.com/shivighn/agridoc/blob/master/backend/src/models/ML_model/tfjs_model1/model.json): `backend/src/models/ML_model/tfjs_model1/model.json`

### Other components

- **Farmer or gardener**
- **MongoDB**
- **Google OAuth**
- **LLM service**

## Connections

- Farmer or gardener → App routing: uses (evidence: `README.md`)
- App routing → Auth context: provides auth (evidence: `frontend/src/App.jsx`)
- App routing → Navigation: renders (evidence: `frontend/src/App.jsx`)
- App routing → Home page: routes to (evidence: `frontend/src/App.jsx`)
- App routing → Diagnose page: routes to (evidence: `frontend/src/App.jsx`)
- App routing → History page: routes to (evidence: `frontend/src/App.jsx`)
- App routing → Profile page: routes to (evidence: `frontend/src/App.jsx`)
- Navigation → Auth context: reads auth (evidence: `frontend/src/components/Navbar.jsx`)
- Profile page → Auth context: reads auth (evidence: `frontend/src/pages/Profile.jsx`)
- Auth context → API endpoint config: gets API URL (evidence: `frontend/src/contexts/AuthContext.jsx`)
- Auth context → Authentication routes: requests status (evidence: `frontend/src/contexts/AuthContext.jsx`)
- Auth context → Authentication routes: starts login (evidence: `frontend/src/contexts/AuthContext.jsx`)
- Auth context → Authentication routes: requests logout (evidence: `frontend/src/contexts/AuthContext.jsx`)
- Diagnose page → Auth context: reads user (evidence: `frontend/src/pages/Diagnose.jsx`)
- Diagnose page → Image upload: renders (evidence: `frontend/src/pages/Diagnose.jsx`)
- Diagnose page → Prediction result: renders (evidence: `frontend/src/pages/Diagnose.jsx`)
- Diagnose page → Plant Doctor chat: renders (evidence: `frontend/src/pages/Diagnose.jsx`)
- Diagnose page → API endpoint config: gets API URL (evidence: `frontend/src/pages/Diagnose.jsx`)
- Diagnose page → Disease routes: posts tensor (evidence: `frontend/src/pages/Diagnose.jsx`)
- Diagnose page → History routes: saves report (evidence: `frontend/src/pages/Diagnose.jsx`)
- Plant Doctor chat → API endpoint config: gets API URL (evidence: `frontend/src/components/PlantDoctorChat.jsx`)
- Plant Doctor chat → Chat routes: posts message (evidence: `frontend/src/components/PlantDoctorChat.jsx`)
- History page → Auth context: reads user (evidence: `frontend/src/pages/History.jsx`)
- History page → API endpoint config: gets API URL (evidence: `frontend/src/pages/History.jsx`)
- History page → History routes: loads or deletes (evidence: `frontend/src/pages/History.jsx`)
- Express server → Database connection: connects database (evidence: `backend/src/server.js`)
- Express server → Authentication routes: mounts routes (evidence: `backend/src/server.js`)
- Express server → Disease routes: mounts routes (evidence: `backend/src/server.js`)
- Express server → Chat routes: mounts routes (evidence: `backend/src/server.js`)
- Express server → History routes: mounts routes (evidence: `backend/src/server.js`)
- Express server → Rate limiter: applies limiter (evidence: `backend/src/server.js`)
- Express server → TensorFlow model: serves model (evidence: `backend/src/server.js`)
- Authentication routes → User records: reads or creates (evidence: `backend/src/routes/auth.js`)
- Database connection → MongoDB: connects
- Rate limiter → MongoDB: limits via Redis
- Disease routes → Model inference: requests inference (evidence: `backend/src/routes/disease.js`)
- Disease routes → Diagnosis reports: stores diagnosis (evidence: `backend/src/routes/disease.js`)
- Model inference → TensorFlow model: loads model (evidence: `backend/src/utils/modelPredictor.js`)
- History routes → Diagnosis reports: manages history (evidence: `backend/src/routes/history.js`)
- Chat routes → Diagnosis reports: uses report data (evidence: `backend/src/routes/chat.js`)
- Chat routes → LLM service: requests responses
- User records → MongoDB: persists users
- Diagnosis reports → MongoDB: persists reports
