# pratikdeoke/plant-disease-detection-platform architecture

> Architecture diagram of the GitHub repository pratikdeoke/plant-disease-detection-platform, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-05-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/pratikdeoke/plant-disease-detection-platform
- Repository: https://github.com/pratikdeoke/plant-disease-detection-platform

## Overview

1. **Overall shape**
   - This is a three-tier system with a clear service boundary:
     - **Frontend**: React/Vite UI
     - **Backend**: Node.js/Express API
     - **ML inference service**: separate Python/TensorFlow container
   - The frontend only talks to the backend REST API; the backend is the hub that talks to both PostgreSQL and the ML service.

2. **Frontend subsystem**
   - The `frontend/` app is a single-page React application built with Vite and styled with Tailwind.
   - It is organized around **pages** (`Upload`, `Community`, `Post`, `CreatePost`, `History`, `Login`, `Register`, `VerifyEmail`) and shared **components** (`Navbar`, `Layout`, `ProtectedRoute`, `PostCard`, `Comment`, etc.).
   - `AuthContext` holds client-side auth state, and `ProtectedRoute` enforces UI-level access control for authenticated pages.

3. **Frontend data access boundary**
   - All server communication is funneled through `frontend/src/api/*` modules, which isolate HTTP calls into three domains:
     - auth
     - discussion/community
     - prediction/disease detection
   - The frontend is configured by `VITE_API_BASE_URL`, so deployment can switch backend targets without changing UI code.

4. **Backend API layer**
   - The backend is an Express application split into:
     - `routes/` for URL-level wiring
     - `controllers/` for request handling
     - `middleware/` for auth and role checks
     - `utils/` for cross-cutting helpers
   - `app.js` likely assembles middleware and routes, while `server.js` starts the HTTP listener.

5. **Authentication and authorization**
   - Auth is JWT-based, with `auth.middleware.js` protecting private endpoints and `rbac.middleware.js` handling role-based authorization where needed.
   - The auth controller supports registration/login and email verification, with `sendVerificationEmail.js` indicating an account-confirmation flow.
   - This creates a hard boundary between public routes and privileged actions such as posting, commenting, liking, and prediction history access.

6. **Community/discussion subsystem**
   - The community feature is implemented in the backend via `discussion.routes.js` and `discussion.controller.js`, backed by `db/discussion.queries.js`.
   - The readme’s schema description implies relational entities for users, posts, comments, and likes, with UUID identifiers generated by `utils/id.js`.
   - The frontend community pages map directly to this subsystem: browse posts, open a post, add comments, and create content.

7. **Disease prediction subsystem**
   - Image-based diagnosis is handled by `prediction.routes.js` and `prediction.controller.js`.
   - The frontend `Upload` page is the entry point: a user submits a leaf image, the backend receives it, and the backend forwards it to the ML service.
   - The backend likely stores uploaded files in `backend/uploads/` and uses `utils/upload.js` for multipart handling before calling inference.

8. **ML inference service boundary**
   - `ml-service/` is fully isolated from the Node stack and runs as a Dockerized Python service.
   - It packages a trained TensorFlow model (`my_model4.h5`) with model/prediction code and exposes a prediction endpoint, described in the readme as `/predict`.
   - This separation makes the model independently deployable and keeps heavyweight ML dependencies out of the API server.

9. **Database layer**
   - PostgreSQL is the persistent store for auth and community data.
   - `backend/src/db.js` is the connection layer, `schema.sql` defines the relational schema, and `discussion.queries.js` contains SQL for post/comment/like operations.
   - The architecture is intentionally relational and UUID-based, which suits many-to-many interactions like likes and threaded discussion content.

10. **Request/data flow for prediction**
   - User uploads an image in the frontend.
   - Frontend sends the file to the backend prediction endpoint.
   - Backend validates/authenticates the request, stores or streams the image, and calls the ML service.
   - ML service returns disease label plus confidence score.
   - Backend returns the result to the UI and may also persist history for the user-facing `History` page.

11. **Request/data flow for community actions**
   - The frontend sends authenticated requests for creating posts, commenting, and liking.
   - Backend middleware verifies identity and permissions.
   - Controllers execute SQL through the discussion query layer.
   - Results are returned to the frontend for rendering in the community feed and post detail views.

12. **Deployment and operational boundaries**
   - The app is designed for separate deployment of all three runtime units:
     - frontend on Vercel
     - backend on Vercel
     - ML service on Render as a Docker container
     - PostgreSQL as hosted cloud infrastructure
   - Each service has its own `vercel.json`/`Dockerfile`/environment variables, reinforcing the microservices-style separation.

13. **Key architecture takeaway**
   - The main design principle is **API-mediated separation**: UI, business logic, persistence, and inference are independent subsystems connected only through HTTP and SQL.
   - For an architecture diagram, the most important arrows are:
     - Frontend → Backend API
     - Backend → PostgreSQL
     - Backend → ML Service
     - ML Service → TensorFlow model file
     - Backend ↔ authenticated user session/JWT flow

Main entry points: [`frontend/src/App.jsx`](https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/frontend/src/App.jsx) (UI Shell), [`backend/src/routes/auth.routes.js`](https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/backend/src/routes/auth.routes.js) (Routes), [`backend/src/controllers/prediction.controller.js`](https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/backend/src/controllers/prediction.controller.js) (Prediction Controller), [`backend/src/db.js`](https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/backend/src/db.js) (DB Layer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_app["UI Shell<br/>React/Vite app<br/>[App.jsx]"]
  node_frontend_context(("Auth State<br/>React context<br/>[AuthContext.jsx]"))
  node_frontend_api["API Layer<br/>HTTP client modules<br/>[api.js]"]
  node_frontend_protected(("Protected Route<br/>route guard<br/>[ProtectedRoute.jsx]"))
  node_frontend_pages["Pages<br/>screen routes<br/>[Upload.jsx]"]
  node_frontend_components["Shared Components<br/>UI components<br/>[Layout.jsx]"]
end

subgraph group_backend["Backend"]
  node_backend_app["Express App<br/>[app.js]"]
  node_backend_server(("HTTP Server<br/>entrypoint<br/>[server.js]"))
  node_backend_routes["Routes<br/>HTTP routing<br/>[auth.routes.js]"]
  node_backend_auth_ctrl["Auth Controller<br/>request handler<br/>[auth.controller.js]"]
  node_backend_discussion_ctrl["Discussion Controller<br/>request handler"]
  node_backend_prediction_ctrl["Prediction Controller<br/>request handler"]
  node_backend_middleware(("Auth Middleware<br/>security middleware<br/>[auth.middleware.js]"))
  node_backend_upload["Upload Helper<br/>multipart helper<br/>[upload.js]"]
end

subgraph group_ml["ML Service"]
  node_ml_app["Inference API<br/>Python service<br/>[app.py]"]
  node_ml_model{{"TensorFlow Model<br/>trained model<br/>[my_model4.h5]"}}
end

subgraph group_data["Data Store"]
  node_backend_db[("DB Layer<br/>PostgreSQL access<br/>[db.js]")]
  node_discussion_sql["Discussion SQL<br/>query module"]
  node_schema["Schema<br/>[schema.sql]"]
end

node_frontend_app -->|"reads session"| node_frontend_context
node_frontend_app -->|"calls APIs"| node_frontend_api
node_frontend_app -->|"guards routes"| node_frontend_protected
node_frontend_app -->|"renders pages"| node_frontend_pages
node_frontend_app -->|"composes UI"| node_frontend_components
node_frontend_api -->|"REST requests"| node_backend_routes
node_backend_server -->|"boots"| node_backend_app
node_backend_app -->|"mounts"| node_backend_routes
node_backend_routes -->|"auth endpoints"| node_backend_auth_ctrl
node_backend_routes -->|"community endpoints"| node_backend_discussion_ctrl
node_backend_routes -->|"prediction endpoints"| node_backend_prediction_ctrl
node_backend_auth_ctrl -->|"protects"| node_backend_middleware
node_backend_discussion_ctrl -->|"authorizes"| node_backend_middleware
node_backend_prediction_ctrl -->|"auth checks"| node_backend_middleware
node_backend_prediction_ctrl -->|"parses files"| node_backend_upload
node_backend_discussion_ctrl -->|"queries"| node_backend_db
node_backend_auth_ctrl -->|"persists users"| node_backend_db
node_backend_db -->|"implements"| node_schema
node_backend_db -->|"executes"| node_discussion_sql
node_backend_prediction_ctrl -->|"invokes inference"| node_ml_app
node_ml_app -->|"loads model"| node_ml_model

click node_frontend_app "https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/frontend/src/App.jsx"
click node_frontend_context "https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/frontend/src/context/AuthContext.jsx"
click node_frontend_api "https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/frontend/src/api/api.js"
click node_frontend_protected "https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/frontend/src/components/ProtectedRoute.jsx"
click node_frontend_pages "https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/frontend/src/pages/Upload.jsx"
click node_frontend_components "https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/frontend/src/components/Layout.jsx"
click node_backend_app "https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/backend/src/app.js"
click node_backend_server "https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/backend/src/server.js"
click node_backend_routes "https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/backend/src/routes/auth.routes.js"
click node_backend_auth_ctrl "https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/backend/src/controllers/auth.controller.js"
click node_backend_discussion_ctrl "https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/backend/src/controllers/discussion.controller.js"
click node_backend_prediction_ctrl "https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/backend/src/controllers/prediction.controller.js"
click node_backend_middleware "https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/backend/src/middleware/auth.middleware.js"
click node_backend_upload "https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/backend/src/utils/upload.js"
click node_backend_db "https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/backend/src/db.js"
click node_discussion_sql "https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/backend/src/db/discussion.queries.js"
click node_schema "https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/backend/src/db/schema.sql"
click node_ml_app "https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/ml-service/app.py"
click node_ml_model "https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/ml-service/my_model4.h5"

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_frontend_app,node_frontend_context,node_frontend_api,node_frontend_protected,node_frontend_pages,node_frontend_components toneBlue
class node_backend_app,node_backend_server,node_backend_routes,node_backend_auth_ctrl,node_backend_discussion_ctrl,node_backend_prediction_ctrl,node_backend_middleware,node_backend_upload toneAmber
class node_ml_app,node_ml_model toneMint
class node_backend_db,node_discussion_sql,node_schema toneRose
```

## Components

### Frontend

React/Vite single-page app and client-side API boundary

- [UI Shell](https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/frontend/src/App.jsx): React/Vite app · Main SPA entry and composition for the client UI · `frontend/src/App.jsx`
- [Auth State](https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/frontend/src/context/AuthContext.jsx): React context · Client-side auth session state and exposure to the UI · `frontend/src/context/AuthContext.jsx`
- [API Layer](https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/frontend/src/api/api.js): HTTP client modules · Centralized frontend calls for auth, discussion, and prediction · `frontend/src/api/api.js`
- [Protected Route](https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/frontend/src/components/ProtectedRoute.jsx): route guard · UI-level access control for authenticated pages · `frontend/src/components/ProtectedRoute.jsx`
- [Pages](https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/frontend/src/pages/Upload.jsx): screen routes · Core user-facing screens for upload, community, auth, and history · `frontend/src/pages/Upload.jsx`
- [Shared Components](https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/frontend/src/components/Layout.jsx): UI components · Reusable layout and post/comment rendering pieces · `frontend/src/components/Layout.jsx`

### Backend

Express API, business logic, auth, and persistence

- [Express App](https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/backend/src/app.js): Node/Express app · Application assembly for middleware and route wiring · `backend/src/app.js`
- [HTTP Server](https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/backend/src/server.js): entrypoint · Starts the backend listener and process lifecycle · `backend/src/server.js`
- [Routes](https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/backend/src/routes/auth.routes.js): HTTP routing · URL-level wiring for auth, discussion, and prediction · `backend/src/routes/auth.routes.js`
- [Auth Controller](https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/backend/src/controllers/auth.controller.js): request handler · Registration, login, and email verification flow · `backend/src/controllers/auth.controller.js`
- [Discussion Controller](https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/backend/src/controllers/discussion.controller.js): request handler · Post, comment, and like operations for community content · `backend/src/controllers/discussion.controller.js`
- [Prediction Controller](https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/backend/src/controllers/prediction.controller.js): request handler · Image upload handling and disease prediction orchestration · `backend/src/controllers/prediction.controller.js`
- [Auth Middleware](https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/backend/src/middleware/auth.middleware.js): security middleware · JWT protection and role-based access control · `backend/src/middleware/auth.middleware.js`
- [Upload Helper](https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/backend/src/utils/upload.js): multipart helper · File upload parsing and storage support · `backend/src/utils/upload.js`

### ML Service

Python/TensorFlow inference runtime

- [Inference API](https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/ml-service/app.py): Python service · Standalone prediction service exposed over HTTP · `ml-service/app.py`
- [TensorFlow Model](https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/ml-service/my_model4.h5): trained model · Packaged image classification model used for inference · `ml-service/my_model4.h5`

### Data Store

Relational schema and database access

- [DB Layer](https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/backend/src/db.js): PostgreSQL access · Connection and query boundary for relational persistence · `backend/src/db.js`
- [Discussion SQL](https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/backend/src/db/discussion.queries.js): query module · SQL for posts, comments, likes, and feed retrieval · `backend/src/db/discussion.queries.js`
- [Schema](https://github.com/pratikdeoke/plant-disease-detection-platform/blob/main/backend/src/db/schema.sql): SQL schema · Relational definitions for users, posts, comments, and likes · `backend/src/db/schema.sql`

## Connections

- UI Shell → Auth State: reads session · The app consumes auth state to drive protected and logged-in UI
- UI Shell → API Layer: calls APIs · Screens use centralized HTTP modules for all server communication
- UI Shell → Protected Route: guards routes · Authenticated screens are wrapped with UI-level protection
- UI Shell → Pages: renders pages · The SPA routes into major user workflows and screens
- UI Shell → Shared Components: composes UI · Pages are built from shared layout and content components
- API Layer → Routes: REST requests · All frontend traffic is funneled to the backend API boundary
- HTTP Server → Express App: boots · Server entrypoint starts the Express application
- Express App → Routes: mounts · The app assembles and mounts the route modules
- Routes → Auth Controller: auth endpoints · Auth routes delegate to registration, login, and verification handlers
- Routes → Discussion Controller: community endpoints · Discussion routes delegate post/comment/like actions
- Routes → Prediction Controller: prediction endpoints · Prediction routes handle upload and inference requests
- Auth Controller → Auth Middleware: protects · Private auth flows are enforced by JWT and role checks
- Discussion Controller → Auth Middleware: authorizes · Community write actions require authenticated access
- Prediction Controller → Auth Middleware: auth checks · Prediction requests are validated before processing
- Prediction Controller → Upload Helper: parses files · Uploaded images are handled through multipart upload support
- Discussion Controller → DB Layer: queries · Discussion operations use the database access layer
- Auth Controller → DB Layer: persists users · Authentication and verification state are stored in PostgreSQL
- DB Layer → Schema: implements · The connection layer serves the relational schema
- DB Layer → Discussion SQL: executes · Discussion query module provides SQL statements to the DB layer
- Prediction Controller → Inference API: invokes inference · The backend forwards leaf images to the standalone ML service
- Inference API → TensorFlow Model: loads model · The inference service uses the packaged TensorFlow model
