# aibhavesh/verdantguard architecture

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

- Interactive diagram: https://gitdiagram.com/aibhavesh/verdantguard
- Repository: https://github.com/aibhavesh/verdantguard

## Overview

#### Purpose and topology
VerdantGuard is a three-service leaf-disease diagnosis system: a React browser client submits leaf images, an Express API handles identity, persistence, and uploads, and a Flask/TensorFlow service classifies images. MongoDB retains users, contact messages, and upload/result history. Primary service entry points are `frontend/src/main.jsx`, `backend/app.js`, and `model/api4.py`.

#### Frontend application
The Vite/React frontend owns user-facing navigation, forms, upload initiation, and result/history presentation. Routing is centralized in `frontend/src/routes/AllRoutes.jsx`; the application shell is `frontend/src/App.jsx`. Key workflow pages are `frontend/src/pages/SignIn.jsx`, `frontend/src/pages/SignUp.jsx`, `frontend/src/pages/Upload.jsx`, and `frontend/src/pages/Data.jsx`. API base/endpoints are configured through `frontend/src/constant/API_URL.jsx`, allowing the browser-to-Express boundary to be environment-driven.

#### Express API gateway
`backend/app.js` is the Node.js/Express entry point and integration boundary for CORS/security, database startup, health checks, and versioned API routing. `backend/routes/Allroutes.js` aggregates route modules, with externally meaningful resources separated into authentication, uploads, and contact endpoints:
- `backend/routes/Singninauth.js`
- `backend/routes/UploadRoutes.js`
- `backend/routes/ContactusRoutes.js`

The API is expected at `/api/v1`; it is the frontend’s primary backend dependency and mediates communication with the ML service rather than exposing model internals to normal application flows.

#### Identity and authorization
Account creation and login are handled by `backend/controllers/SignUpController.js` and `backend/controllers/Signinauthcontroller.js`, backed by the user document model in `backend/models/SignupSchema.js`. Passwords are bcrypt-hashed and successful authentication yields JWTs. `backend/middlewares/authMiddleware.js` protects authenticated operations, notably image upload. This creates a control boundary between public sign-up/sign-in/contact traffic and user-associated diagnostic activity.

#### Upload-to-prediction pipeline
The core workflow begins at `frontend/src/pages/Upload.jsx`: the client sends multipart image data and leaf metadata to the Express upload endpoint. `backend/middlewares/multer.js` validates/places uploaded files on local disk; `backend/controllers/UploadController.js` coordinates persistence and the outbound HTTP request to the Flask prediction endpoint. Upload records, including image path, leaf type, and prediction output, are represented by `backend/models/UploadSchema.js`. Images are filesystem-backed rather than object-storage-backed, with repository-level storage locations `uploads/` and `model/uploads/`.

#### ML inference service
`model/api4.py` is a standalone Flask API exposing prediction and health behavior. It loads the trained Keras artifact `model/Potato_Disease_Classification_Model.keras`, preprocesses received images using Pillow/NumPy, invokes TensorFlow/Keras inference, and returns predicted disease class plus confidence. The modeled scope is explicitly potato disease classification; support for other crops would require model/service changes, not only frontend metadata changes.

#### Persistence, runtime, and operational dependencies
The system requires Node.js 18+ for Express, Python 3.8+ for Flask/TensorFlow, and a reachable MongoDB instance. MongoDB connection ownership is in `backend/config/conn.js`; data domains are user accounts, uploads, and contact submissions (`backend/models/ConatactUsSchema.js`). Runtime configuration is environment-based: the backend needs Mongo URI, JWT secret, frontend origin, and Flask prediction URL; the frontend needs its Express API URL. Local default topology is React/Vite on 5173, Express on 3000, Flask on 5000, plus MongoDB.

Main entry points: [`frontend/src/routes/AllRoutes.jsx`](https://github.com/aibhavesh/verdantguard/blob/main/frontend/src/routes/AllRoutes.jsx) (Route registry), [`backend/routes/Allroutes.js`](https://github.com/aibhavesh/verdantguard/blob/main/backend/routes/Allroutes.js) (Route aggregator), [`frontend/src/constant/API_URL.jsx`](https://github.com/aibhavesh/verdantguard/blob/main/frontend/src/constant/API_URL.jsx) (API endpoint config), [`backend/app.js`](https://github.com/aibhavesh/verdantguard/blob/main/backend/app.js) (Express entry point)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["React frontend"]
  node_client(("Browser client"))
  node_frontend_app["App shell<br/>React application<br/>[App.jsx]"]
  node_routes["Route registry<br/>React routes<br/>[AllRoutes.jsx]"]
  node_auth_pages["Sign-in &amp; sign-up<br/>React pages<br/>[SignIn.jsx]"]
  node_upload_page["Image upload<br/>React page<br/>[Upload.jsx]"]
  node_history_page["Results &amp; history<br/>React page<br/>[Data.jsx]"]
  node_api_config["API endpoint config<br/>frontend config<br/>[API_URL.jsx]"]
end

subgraph group_backend["Express API"]
  node_express_app{{"Express entry point<br/>Node.js service<br/>[app.js]"}}
  node_route_aggregator["Route aggregator<br/>Express routes<br/>[Allroutes.js]"]
  node_auth_api["Authentication API<br/>Express routes<br/>[Singninauth.js]"]
  node_upload_api["Upload API<br/>Express routes<br/>[UploadRoutes.js]"]
  node_contact_api["Contact API<br/>Express routes<br/>[ContactusRoutes.js]"]
  node_auth_controller["Identity controllers<br/>Express controllers"]
  node_upload_controller["Upload controller<br/>Express controller"]
  node_upload_guard["Auth &amp; multipart middleware<br/>Express middleware<br/>[authMiddleware.js]"]
end

subgraph group_ml["ML inference"]
  node_flask_api{{"Flask prediction API<br/>Python service<br/>[api4.py]"}}
  node_keras_model["Trained Keras model<br/>TensorFlow artifact"]
end

subgraph group_data["Persistence &amp; storage"]
  node_mongo_connection["MongoDB connection<br/>database connection<br/>[conn.js]"]
  node_mongodb[("MongoDB<br/>database")]
  node_local_uploads["Local image storage<br/>filesystem"]
end

node_client -->|"uses"| node_frontend_app
node_frontend_app -->|"renders"| node_routes
node_routes -->|"maps auth views"| node_auth_pages
node_routes -->|"maps upload view"| node_upload_page
node_routes -->|"maps history view"| node_history_page
node_auth_pages -.->|"reads endpoint"| node_api_config
node_upload_page -.->|"reads endpoint"| node_api_config
node_history_page -.->|"reads endpoint"| node_api_config
node_api_config -->|"HTTPS API calls"| node_express_app
node_express_app -->|"initializes"| node_mongo_connection
node_mongo_connection -->|"connects"| node_mongodb
node_express_app -->|"mounts /api/v1"| node_route_aggregator
node_route_aggregator -->|"registers"| node_auth_api
node_route_aggregator -->|"registers"| node_upload_api
node_route_aggregator -->|"registers"| node_contact_api
node_auth_api -->|"handles credentials"| node_auth_controller
node_auth_controller -->|"stores users"| node_mongodb
node_upload_api -->|"protects and parses"| node_upload_guard
node_upload_guard -->|"passes image"| node_upload_controller
node_upload_guard -->|"writes file"| node_local_uploads
node_upload_controller -->|"stores upload/result"| node_mongodb
node_upload_controller -->|"prediction request"| node_flask_api
node_flask_api -->|"loads and infers"| node_keras_model
node_contact_api -->|"stores messages"| node_mongodb

click node_frontend_app "https://github.com/aibhavesh/verdantguard/blob/main/frontend/src/App.jsx"
click node_routes "https://github.com/aibhavesh/verdantguard/blob/main/frontend/src/routes/AllRoutes.jsx"
click node_auth_pages "https://github.com/aibhavesh/verdantguard/blob/main/frontend/src/pages/SignIn.jsx"
click node_upload_page "https://github.com/aibhavesh/verdantguard/blob/main/frontend/src/pages/Upload.jsx"
click node_history_page "https://github.com/aibhavesh/verdantguard/blob/main/frontend/src/pages/Data.jsx"
click node_api_config "https://github.com/aibhavesh/verdantguard/blob/main/frontend/src/constant/API_URL.jsx"
click node_express_app "https://github.com/aibhavesh/verdantguard/blob/main/backend/app.js"
click node_route_aggregator "https://github.com/aibhavesh/verdantguard/blob/main/backend/routes/Allroutes.js"
click node_auth_api "https://github.com/aibhavesh/verdantguard/blob/main/backend/routes/Singninauth.js"
click node_upload_api "https://github.com/aibhavesh/verdantguard/blob/main/backend/routes/UploadRoutes.js"
click node_contact_api "https://github.com/aibhavesh/verdantguard/blob/main/backend/routes/ContactusRoutes.js"
click node_auth_controller "https://github.com/aibhavesh/verdantguard/blob/main/backend/controllers/Signinauthcontroller.js"
click node_upload_controller "https://github.com/aibhavesh/verdantguard/blob/main/backend/controllers/UploadController.js"
click node_upload_guard "https://github.com/aibhavesh/verdantguard/blob/main/backend/middlewares/authMiddleware.js"
click node_mongo_connection "https://github.com/aibhavesh/verdantguard/blob/main/backend/config/conn.js"
click node_flask_api "https://github.com/aibhavesh/verdantguard/blob/main/model/api4.py"
click node_keras_model "https://github.com/aibhavesh/verdantguard/blob/main/model/Potato_Disease_Classification_Model.keras"

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_client,node_frontend_app,node_routes,node_auth_pages,node_upload_page,node_history_page,node_api_config toneBlue
class node_express_app,node_route_aggregator,node_auth_api,node_upload_api,node_contact_api,node_auth_controller,node_upload_controller,node_upload_guard toneAmber
class node_flask_api,node_keras_model toneMint
class node_mongo_connection,node_mongodb,node_local_uploads toneRose
```

## Components

### React frontend

Browser application served by Vite.

- **Browser client**: browser
- [App shell](https://github.com/aibhavesh/verdantguard/blob/main/frontend/src/App.jsx): React application · `frontend/src/App.jsx`
- [Route registry](https://github.com/aibhavesh/verdantguard/blob/main/frontend/src/routes/AllRoutes.jsx): React routes · `frontend/src/routes/AllRoutes.jsx`
- [Sign-in & sign-up](https://github.com/aibhavesh/verdantguard/blob/main/frontend/src/pages/SignIn.jsx): React pages · `frontend/src/pages/SignIn.jsx`
- [Image upload](https://github.com/aibhavesh/verdantguard/blob/main/frontend/src/pages/Upload.jsx): React page · Starts authenticated multipart diagnosis requests. · `frontend/src/pages/Upload.jsx`
- [Results & history](https://github.com/aibhavesh/verdantguard/blob/main/frontend/src/pages/Data.jsx): React page · `frontend/src/pages/Data.jsx`
- [API endpoint config](https://github.com/aibhavesh/verdantguard/blob/main/frontend/src/constant/API_URL.jsx): frontend config · Environment-driven Express API boundary. · `frontend/src/constant/API_URL.jsx`

### Express API

Application gateway at /api/v1.

- [Express entry point](https://github.com/aibhavesh/verdantguard/blob/main/backend/app.js): Node.js service · Owns CORS, security, startup, health checks, and API mounting. · `backend/app.js`
- [Route aggregator](https://github.com/aibhavesh/verdantguard/blob/main/backend/routes/Allroutes.js): Express routes · `backend/routes/Allroutes.js`
- [Authentication API](https://github.com/aibhavesh/verdantguard/blob/main/backend/routes/Singninauth.js): Express routes · Public account creation and JWT login. · `backend/routes/Singninauth.js`
- [Upload API](https://github.com/aibhavesh/verdantguard/blob/main/backend/routes/UploadRoutes.js): Express routes · Authenticated diagnostic upload resource. · `backend/routes/UploadRoutes.js`
- [Contact API](https://github.com/aibhavesh/verdantguard/blob/main/backend/routes/ContactusRoutes.js): Express routes · `backend/routes/ContactusRoutes.js`
- [Identity controllers](https://github.com/aibhavesh/verdantguard/blob/main/backend/controllers/Signinauthcontroller.js): Express controllers · Hashes passwords and issues JWTs. · `backend/controllers/Signinauthcontroller.js`
- [Upload controller](https://github.com/aibhavesh/verdantguard/blob/main/backend/controllers/UploadController.js): Express controller · Persists uploads and calls the prediction service. · `backend/controllers/UploadController.js`
- [Auth & multipart middleware](https://github.com/aibhavesh/verdantguard/blob/main/backend/middlewares/authMiddleware.js): Express middleware · JWT protection plus local file validation and placement. · `backend/middlewares/authMiddleware.js`

### ML inference

Standalone potato disease classifier.

- [Flask prediction API](https://github.com/aibhavesh/verdantguard/blob/main/model/api4.py): Python service · Preprocesses images and returns potato disease class and confidence. · `model/api4.py`
- [Trained Keras model](https://github.com/aibhavesh/verdantguard/blob/main/model/Potato_Disease_Classification_Model.keras): TensorFlow artifact · `model/Potato_Disease_Classification_Model.keras`

### Persistence & storage

- [MongoDB connection](https://github.com/aibhavesh/verdantguard/blob/main/backend/config/conn.js): database connection · `backend/config/conn.js`
- **MongoDB**: database · Stores users, contact submissions, and upload histories.
- **Local image storage**: filesystem · Repository-backed uploads at uploads/ and model/uploads/.

## Connections

- Browser client → App shell: uses
- App shell → Route registry: renders
- Route registry → Sign-in & sign-up: maps auth views
- Route registry → Image upload: maps upload view
- Route registry → Results & history: maps history view
- Sign-in & sign-up → API endpoint config: reads endpoint
- Image upload → API endpoint config: reads endpoint
- Results & history → API endpoint config: reads endpoint
- API endpoint config → Express entry point: HTTPS API calls
- Express entry point → MongoDB connection: initializes
- MongoDB connection → MongoDB: connects
- Express entry point → Route aggregator: mounts /api/v1
- Route aggregator → Authentication API: registers
- Route aggregator → Upload API: registers
- Route aggregator → Contact API: registers
- Authentication API → Identity controllers: handles credentials
- Identity controllers → MongoDB: stores users
- Upload API → Auth & multipart middleware: protects and parses
- Auth & multipart middleware → Upload controller: passes image
- Auth & multipart middleware → Local image storage: writes file
- Upload controller → MongoDB: stores upload/result
- Upload controller → Flask prediction API: prediction request
- Flask prediction API → Trained Keras model: loads and infers
- Contact API → MongoDB: stores messages
