How rahul-suthar/flockguard works
Purpose and Deliverables
FlockGuard is a livestock-health platform for pig and poultry farms. It combines a React Native farmer-facing app, an Express/MongoDB API, a Flask disease-classification service, and a lightweight React/Vite public site. Core outcomes are farm records, disease-image prediction, health reports, role-based access, and veterinary/pharmacy workflows.
Client Entry Points
The public web client is a Vite React application rooted at client/src/main.jsx and client/src/App.jsx. It primarily serves informational, onboarding, contact, legal, and download-facing pages, structured with shared navigation/layout components in client/src/components/NavBar.jsx and client/src/components/DocLayout.jsx. Deployment configuration targets Vercel via client/vercel.json.
Mobile Application and Navigation
The primary operational UI is the React Native app, bootstrapped through mobile/index.js and mobile/App.jsx. Navigation composes stack and tab flows in mobile/src/navigations/StackNavigator.jsx, mobile/src/navigations/TabNavigator.jsx, and mobile/src/navigations/HomeStackNav.jsx. Major workflows are represented by login/registration, farm/home, diagnosis details, vet, and profile screens under mobile/src/screens/.
Mobile State and API Boundary
Cross-screen concerns use React contexts: authentication, camera capture, health/report state, loader, popup, and theme state in mobile/src/context/Auth.context.js, mobile/src/context/Camera.context.js, and mobile/src/context/Health.context.js. The app reaches the backend through API-domain modules—mobile/src/apis/api.js, mobile/src/apis/auth.js, mobile/src/apis/farm.js, and mobile/src/apis/report.js—which form the client/server boundary. Camera-driven image collection is encapsulated in mobile/src/components/CameraView.jsx.
Backend API and Authorization
The Node.js/Express service starts from server/src/index.js, with application assembly in server/src/app.js. Route groups separate authentication/admin, farms, and reports in server/src/routes/auth.routes.js, server/src/routes/farm.routes.js, and server/src/routes/report.routes.js. Controllers implement corresponding business operations in server/src/controllers/user.controller.js, server/src/controllers/farm.controller.js, and server/src/controllers/report.controller.js. JWT/role enforcement and multipart image intake are boundary middleware in server/src/middlewares/auth.middleware.js, server/src/middlewares/role.middleware.js, and server/src/middlewares/multer.middleware.js.
Persistent Domain and External Services
MongoDB persistence is initialized in server/src/db/index.js; Mongoose models capture users, farms, reports, alerts, vets, pharmacies, and related roles, including server/src/models/user.models.js, server/src/models/farm.models.js, and server/src/models/report.models.js. Uploaded diagnostic images pass through temporary server storage (server/public/temp/.gitkeep) and Cloudinary integration (server/src/utils/cloudinary.js). The backend converts ML output into application-facing report data through server/src/utils/mlRespose.js.
ML Prediction Service and Report Flow
The Flask service entry point is ml/app.py; health and prediction endpoints are split into ml/routes/health.py and ml/routes/predict.py. It loads the serialized disease model at ml/models/disease_model.pkl. The principal flow is: authenticated mobile user creates/selects a farm, captures/uploads an animal image, Express stores/forwards image data and invokes ML prediction, then persists prediction-linked health report data for later vet notes, prescriptions, and alert-related follow-up.
Main entry points: report.controller.js Domain controllers · app.py Flask prediction API · api.js API domain modules · StackNavigator.jsx App navigation
Components 18
Public Web
- Vite React site · Informational, onboarding, legal, and download pages.
client/src/main.jsx - Shared web layout
client/src/components/NavBar.jsx
Farmer Mobile App
- React Native app
mobile/index.js - App navigation
mobile/src/navigations/StackNavigator.jsx - Farm, diagnosis, vet and profile
- Cross-screen state · Authentication, camera, health reports, loader, popup, and theme state.
mobile/src/context/Auth.context.js - Camera capture
mobile/src/components/CameraView.jsx - API domain modules
mobile/src/apis/api.js
Platform API
- Express service
server/src/index.js - Auth, farm and report routes
server/src/routes/auth.routes.js - JWT, roles and uploads · Enforces access and accepts multipart diagnostic images.
server/src/middlewares/auth.middleware.js - Domain controllers
server/src/controllers/report.controller.js - MongoDB domain data · Users, farms, reports, alerts, vets, pharmacies, and roles.
server/src/db/index.js - Diagnostic image storage
server/src/utils/cloudinary.js - ML result adapter · Converts prediction output into application report data.
server/src/utils/mlRespose.js
Disease ML Service
- Flask prediction API
ml/app.py - Prediction endpoint
ml/routes/predict.py - Disease classifier
ml/models/disease_model.pkl
Connections 18
- Vite React site → Shared web layout: renders
- React Native app → App navigation: boots
- App navigation → Farm, diagnosis, vet and profile: routes to
- Cross-screen state → Farm, diagnosis, vet and profile: supplies state
- Farm, diagnosis, vet and profile → Camera capture: captures images
- Camera capture → API domain modules: uploads image
- Farm, diagnosis, vet and profile → API domain modules: farm and report requests
- API domain modules → Express service: HTTPS API
- Express service → Auth, farm and report routes: mounts
- Auth, farm and report routes → JWT, roles and uploads: guards requests
- JWT, roles and uploads → Domain controllers: authorizes and passes uploads
- Domain controllers → MongoDB domain data: reads and writes
- Domain controllers → Diagnostic image storage: stores diagnostic images
- Domain controllers → Flask prediction API: requests prediction
- Flask prediction API → Prediction endpoint: serves
- Prediction endpoint → Disease classifier: loads and infers
- Flask prediction API → ML result adapter: returns ML output
- ML result adapter → MongoDB domain data: persists prediction-linked report