How pratikdeoke/plant-disease-detection-platform works
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: App.jsx UI Shell · auth.routes.js Routes · prediction.controller.js Prediction Controller · db.js DB Layer
Components 19
Frontend
React/Vite single-page app and client-side API boundary
- UI Shell · Main SPA entry and composition for the client UI
frontend/src/App.jsx - Auth State · Client-side auth session state and exposure to the UI
frontend/src/context/AuthContext.jsx - API Layer · Centralized frontend calls for auth, discussion, and prediction
frontend/src/api/api.js - Protected Route · UI-level access control for authenticated pages
frontend/src/components/ProtectedRoute.jsx - Pages · Core user-facing screens for upload, community, auth, and history
frontend/src/pages/Upload.jsx - Shared Components · Reusable layout and post/comment rendering pieces
frontend/src/components/Layout.jsx
Backend
Express API, business logic, auth, and persistence
- Express App · Application assembly for middleware and route wiring
backend/src/app.js - HTTP Server · Starts the backend listener and process lifecycle
backend/src/server.js - Routes · URL-level wiring for auth, discussion, and prediction
backend/src/routes/auth.routes.js - Auth Controller · Registration, login, and email verification flow
backend/src/controllers/auth.controller.js - Discussion Controller · Post, comment, and like operations for community content
backend/src/controllers/discussion.controller.js - Prediction Controller · Image upload handling and disease prediction orchestration
backend/src/controllers/prediction.controller.js - Auth Middleware · JWT protection and role-based access control
backend/src/middleware/auth.middleware.js - Upload Helper · File upload parsing and storage support
backend/src/utils/upload.js
ML Service
Python/TensorFlow inference runtime
- Inference API · Standalone prediction service exposed over HTTP
ml-service/app.py - TensorFlow Model · Packaged image classification model used for inference
ml-service/my_model4.h5
Data Store
Relational schema and database access
- DB Layer · Connection and query boundary for relational persistence
backend/src/db.js - Discussion SQL · SQL for posts, comments, likes, and feed retrieval
backend/src/db/discussion.queries.js - Schema · Relational definitions for users, posts, comments, and likes
backend/src/db/schema.sql
Connections 21
- 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