# phucthinh2704/plantsenseai-llm architecture

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

- Interactive diagram: https://gitdiagram.com/phucthinh2704/plantsenseai-llm
- Repository: https://github.com/phucthinh2704/plantsenseai-llm

## Overview

PlantSense is an agricultural chatbot with a React client and FastAPI/MongoDB backend. The principal workflow is a user submitting a question or image, the chat service classifying it and producing a response, then persisting the conversation. The application also provides authentication, plant/disease/cultivation information, and admin management and indexing screens. Edges are limited to relationships shown in excerpts or SOURCE INDEX references; several frontend-to-API and unsampled indexing details are not established, so they are left unconnected.

Main entry points: [`backend_mdb/app/main.py`](https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/main.py) (API application), [`backend_mdb/app/router/plant_router.py`](https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/router/plant_router.py) (Plant endpoints), [`frontend/src/app/Router/routes.jsx`](https://github.com/phucthinh2704/plantsenseai-llm/blob/master/frontend/src/app/Router/routes.jsx) (Route map), [`backend_mdb/app/services/chat_service.py`](https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/services/chat_service.py) (Chat orchestration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Web client"]
  node_routes["Route map<br/>[routes.jsx]"]
  node_home["Chat screen<br/>[Home.jsx]"]
  node_login["Login screen<br/>[Login.jsx]"]
  node_adminui["Admin screens"]
end

subgraph group_api["API and identity"]
  node_main["API application<br/>[main.py]"]
  node_authroutes["Auth endpoints<br/>[auth_router.py]"]
  node_authservice["Auth logic<br/>[auth_service.py]"]
  node_userservice["User service<br/>[user_service.py]"]
  node_userstore[("MongoDB<br/>[database.py]")]
  node_chatroute["Chat endpoint<br/>[chat_router.py]"]
  node_convroutes["Conversation endpoints"]
end

subgraph group_chat["Chat and knowledge"]
  node_chatservice["Chat orchestration<br/>[chat_service.py]"]
  node_classifier["Image classifier<br/>[classify.py]"]
  node_prompts["Chat prompts<br/>[chat_prompts.py]"]
  node_convservice["Conversation service"]
  node_knowledge["Search indexing<br/>[indexing.py]"]
  node_tokenizer["Index tokenizer"]
end

subgraph group_domain["Agricultural data"]
  node_plantroute["Plant endpoints<br/>[plant_router.py]"]
  node_plantservice["Plant service<br/>[plant_service.py]"]
  node_diseaseservice["Disease service<br/>[disease_service.py]"]
  node_stageservice["Disease-stage service"]
  node_cultivationservice["Cultivation service"]
  node_domainroutes["Domain endpoints"]
end

node_user(("User"))

node_user -->|"opens app"| node_routes
node_routes -->|"routes home"| node_home
node_routes -->|"routes login"| node_login
node_routes -->|"routes admin"| node_adminui
node_main -->|"registers"| node_authroutes
node_main -->|"registers"| node_chatroute
node_main -->|"registers"| node_convroutes
node_main -->|"registers"| node_plantroute
node_main -->|"registers"| node_domainroutes
node_authroutes -->|"delegates Google login"| node_authservice
node_authroutes -->|"manages accounts"| node_userservice
node_authservice -->|"looks up users"| node_userservice
node_userservice -->|"reads and writes"| node_userstore
node_chatroute -->|"dispatches chat"| node_chatservice
node_chatservice -->|"classifies images"| node_classifier
node_chatservice -->|"uses prompts"| node_prompts
node_chatservice -->|"loads and saves"| node_convservice
node_convroutes -->|"delegates conversation"| node_convservice
node_convservice -->|"persists conversations"| node_userstore
node_plantroute -->|"manages plants"| node_plantservice
node_plantroute -->|"creates disease data"| node_diseaseservice
node_plantroute -->|"creates disease stages"| node_stageservice
node_plantroute -->|"creates techniques"| node_cultivationservice
node_adminui -.-> node_knowledge
node_knowledge -.-> node_tokenizer

click node_routes "https://github.com/phucthinh2704/plantsenseai-llm/blob/master/frontend/src/app/Router/routes.jsx"
click node_home "https://github.com/phucthinh2704/plantsenseai-llm/blob/master/frontend/src/pages/Home.jsx"
click node_login "https://github.com/phucthinh2704/plantsenseai-llm/blob/master/frontend/src/pages/Login.jsx"
click node_adminui "https://github.com/phucthinh2704/plantsenseai-llm/tree/master/frontend/src/pages/admin"
click node_main "https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/main.py"
click node_authroutes "https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/router/auth_router.py"
click node_authservice "https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/services/auth_service.py"
click node_userservice "https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/services/user_service.py"
click node_userstore "https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/core/database.py"
click node_chatroute "https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/router/chat_router.py"
click node_convroutes "https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/router/conversation_router.py"
click node_chatservice "https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/services/chat_service.py"
click node_classifier "https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/classification/classify.py"
click node_prompts "https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/prompts/chat_prompts.py"
click node_convservice "https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/services/conversation_service.py"
click node_knowledge "https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/indexing.py"
click node_tokenizer "https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/indexing_tokenizer.py"
click node_plantroute "https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/router/plant_router.py"
click node_plantservice "https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/services/plant_service.py"
click node_diseaseservice "https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/services/disease_service.py"
click node_stageservice "https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/services/disease_stage_service.py"
click node_cultivationservice "https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/services/cultivation_service.py"
click node_domainroutes "https://github.com/phucthinh2704/plantsenseai-llm/tree/master/backend_mdb/app/router"

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_routes,node_home,node_login,node_adminui,node_user toneBlue
class node_main,node_authroutes,node_authservice,node_userservice,node_userstore,node_chatroute,node_convroutes toneAmber
class node_chatservice,node_classifier,node_prompts,node_convservice,node_knowledge,node_tokenizer toneMint
class node_plantroute,node_plantservice,node_diseaseservice,node_stageservice,node_cultivationservice,node_domainroutes toneRose
```

## Components

### Web client

- [Route map](https://github.com/phucthinh2704/plantsenseai-llm/blob/master/frontend/src/app/Router/routes.jsx): `frontend/src/app/Router/routes.jsx`
- [Chat screen](https://github.com/phucthinh2704/plantsenseai-llm/blob/master/frontend/src/pages/Home.jsx): `frontend/src/pages/Home.jsx`
- [Login screen](https://github.com/phucthinh2704/plantsenseai-llm/blob/master/frontend/src/pages/Login.jsx): `frontend/src/pages/Login.jsx`
- [Admin screens](https://github.com/phucthinh2704/plantsenseai-llm/tree/master/frontend/src/pages/admin): `frontend/src/pages/admin`

### API and identity

- [API application](https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/main.py): `backend_mdb/app/main.py`
- [Auth endpoints](https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/router/auth_router.py): `backend_mdb/app/router/auth_router.py`
- [Auth logic](https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/services/auth_service.py): `backend_mdb/app/services/auth_service.py`
- [User service](https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/services/user_service.py): `backend_mdb/app/services/user_service.py`
- [MongoDB](https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/core/database.py): `backend_mdb/app/core/database.py`
- [Chat endpoint](https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/router/chat_router.py): `backend_mdb/app/router/chat_router.py`
- [Conversation endpoints](https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/router/conversation_router.py): `backend_mdb/app/router/conversation_router.py`

### Chat and knowledge

- [Chat orchestration](https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/services/chat_service.py): `backend_mdb/app/services/chat_service.py`
- [Image classifier](https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/classification/classify.py): `backend_mdb/app/classification/classify.py`
- [Chat prompts](https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/prompts/chat_prompts.py): `backend_mdb/app/prompts/chat_prompts.py`
- [Conversation service](https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/services/conversation_service.py): `backend_mdb/app/services/conversation_service.py`
- [Search indexing](https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/indexing.py): `backend_mdb/app/indexing.py`
- [Index tokenizer](https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/indexing_tokenizer.py): `backend_mdb/app/indexing_tokenizer.py`

### Agricultural data

- [Plant endpoints](https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/router/plant_router.py): `backend_mdb/app/router/plant_router.py`
- [Plant service](https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/services/plant_service.py): `backend_mdb/app/services/plant_service.py`
- [Disease service](https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/services/disease_service.py): `backend_mdb/app/services/disease_service.py`
- [Disease-stage service](https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/services/disease_stage_service.py): `backend_mdb/app/services/disease_stage_service.py`
- [Cultivation service](https://github.com/phucthinh2704/plantsenseai-llm/blob/master/backend_mdb/app/services/cultivation_service.py): `backend_mdb/app/services/cultivation_service.py`
- [Domain endpoints](https://github.com/phucthinh2704/plantsenseai-llm/tree/master/backend_mdb/app/router): `backend_mdb/app/router`

### Other components

- **User**

## Connections

- User → Route map: opens app (evidence: `frontend/src/app/Router/routes.jsx`)
- Route map → Chat screen: routes home (evidence: `frontend/src/app/Router/routes.jsx`)
- Route map → Login screen: routes login (evidence: `frontend/src/app/Router/routes.jsx`)
- Route map → Admin screens: routes admin (evidence: `frontend/src/app/Router/routes.jsx`)
- API application → Auth endpoints: registers (evidence: `backend_mdb/app/main.py`)
- API application → Chat endpoint: registers (evidence: `backend_mdb/app/main.py`)
- API application → Conversation endpoints: registers (evidence: `backend_mdb/app/main.py`)
- API application → Plant endpoints: registers (evidence: `backend_mdb/app/main.py`)
- API application → Domain endpoints: registers (evidence: `backend_mdb/app/main.py`)
- Auth endpoints → Auth logic: delegates Google login (evidence: `backend_mdb/app/router/auth_router.py`)
- Auth endpoints → User service: manages accounts (evidence: `backend_mdb/app/router/auth_router.py`)
- Auth logic → User service: looks up users (evidence: `backend_mdb/app/services/auth_service.py`)
- User service → MongoDB: reads and writes (evidence: `backend_mdb/app/services/user_service.py`)
- Chat endpoint → Chat orchestration: dispatches chat (evidence: `backend_mdb/app/router/chat_router.py`)
- Chat orchestration → Image classifier: classifies images (evidence: `backend_mdb/app/services/chat_service.py`)
- Chat orchestration → Chat prompts: uses prompts (evidence: `backend_mdb/app/services/chat_service.py`)
- Chat orchestration → Conversation service: loads and saves (evidence: `backend_mdb/app/services/chat_service.py`)
- Conversation endpoints → Conversation service: delegates conversation (evidence: `backend_mdb/app/router/conversation_router.py`)
- Conversation service → MongoDB: persists conversations (evidence: `backend_mdb/app/services/conversation_service.py`)
- Plant endpoints → Plant service: manages plants (evidence: `backend_mdb/app/router/plant_router.py`)
- Plant endpoints → Disease service: creates disease data (evidence: `backend_mdb/app/router/plant_router.py`)
- Plant endpoints → Disease-stage service: creates disease stages (evidence: `backend_mdb/app/router/plant_router.py`)
- Plant endpoints → Cultivation service: creates techniques (evidence: `backend_mdb/app/router/plant_router.py`)
- Admin screens → Search indexing
- Search indexing → Index tokenizer
