Technical architecture overview for the FarmSmart platform.
- System Overview
- Technology Stack
- Architecture Diagram
- Component Architecture
- Data Flow
- Storage Design
- API Surface
- Deployment Architecture
FarmSmart is a web platform with a React frontend and an Express backend over MongoDB.
Core domains in the backend:
- Authentication (OTP + JWT)
- Crop marketplace
- Negotiation and order lifecycle
- Reviews and disputes
- Quality pricing
- Government schemes/advisory
- Market price insights with cache and provider fallback
- React 19 (
frontend/package.json) - Vite (
frontend/package.json) - React Router (
frontend/src/App.jsx) - Axios service layer (
frontend/src/services/api.js)
- Express 5 + TypeScript (
backend/package.json) - Mongoose models (
backend/src/models/*) - JWT auth middleware (
backend/src/middleware/authMiddleware.ts) - Optional Redis cache (
backend/src/cache/redisCache.ts)
- MongoDB primary database (
backend/src/config/db.ts) - Optional external mandi provider via
MANDI_API_BASE_URL
┌──────────────────────┐ ┌──────────────────────────┐ ┌──────────────────────┐
│ Frontend │ HTTP │ Backend │ CRUD │ MongoDB │
│ React + Vite │ ──────► │ Express + TypeScript │ ──────► │ farmsmart database │
│ (Browser Client) │ ◄────── │ REST Endpoints │ ◄────── │ (Mongoose models) │
└──────────────────────┘ └──────────────────────────┘ └──────────────────────┘
│
│ optional
▼
┌──────────────────────────┐
│ Redis / In-memory │
│ Price Cache │
└──────────────────────────┘
│
│ optional
▼
┌──────────────────────────┐
│ External Mandi API │
│ (/current /history etc.) │
└──────────────────────────┘
- Route shell:
frontend/src/App.jsx - Auth pages:
Login,Register,Otp - Dashboard modules: marketplace, pricing, negotiation, orders, reviews, disputes, schemes
- Service layer in
frontend/src/services/handles all backend API calls
- App bootstrap:
backend/src/index.ts - Express app and route mounting:
backend/src/app.ts - Domain routes:
backend/src/routes/* - Controllers: request handling and domain logic (
backend/src/controllers/*) - Models: MongoDB schemas (
backend/src/models/*) - Shared middleware: auth/role guards (
backend/src/middleware/authMiddleware.ts) - Utilities: response wrapper, seed scripts, HTTP fetch helper
- API endpoints:
backend/src/routes/prices.routes.ts - Service abstraction:
backend/src/services/priceService.ts - Provider implementation:
backend/src/services/mandiPriceIngestion.ts - Fallback mocks:
backend/src/services/priceMocks.ts - Cache keys + adapters:
backend/src/cache/*
- Client calls
POST /auth/registerorPOST /auth/login. - Backend validates user and generates OTP (
VerificationCodecollection). - Client calls
POST /auth/verifywith{ contact, code }. - Backend verifies OTP, marks user verified, and returns JWT token.
- Client stores token and sends it in
Authorization: Bearer <token>.
- Farmer creates crop listing (
POST /crops). - Buyer either starts negotiation (
POST /negotiations/start) or uses instant buy (POST /orders/instant-buy). - Negotiation can be countered/accepted/rejected (
POST /negotiations/:id/respond). - Order is created (
POST /orders) from accepted negotiation. - Farmer updates status (
PATCH /orders/:id/status). - Buyer/Farmer can raise disputes (
POST /disputes).
- User submits review (
POST /reviews) with order-linked or direct target context. - Backend stores review and recalculates target user rating aggregate.
- Reputation endpoints return received reviews (
GET /reviews/my,GET /reviews/user/:userId).
- Client requests
/prices/current,/prices/history, or/prices/compare. - Backend service checks cache first.
- If provider is configured and reachable, live data is returned.
- If provider is unavailable, deterministic mock data is returned.
- Response is cached with endpoint-specific TTL.
| Collection | Purpose |
|---|---|
User |
Auth identity, role, location, reputation summary |
VerificationCode |
OTP codes with expiry |
Crop |
Marketplace crop listings |
QualityRule |
Grade-to-price multiplier rules |
MarketPrice |
Market price history and comparison data |
Negotiation |
Buyer/farmer offer exchanges |
Order |
Order lifecycle, status timeline |
Review |
Ratings and comments |
Scheme |
Government scheme catalog |
Advisory |
Advisory feed entries |
Dispute |
Order dispute records |
backend/prisma/schema.prismaexists and defines Mongo datasource models for auth entities.- Runtime API logic currently uses Mongoose models from
backend/src/models.
Mounted base paths in backend/src/app.ts:
/auth/cropsand/api/crops(alias)/negotiations/orders/reviews/quality/schemes/advisory/disputes/pricesand/api/prices(alias)
Full endpoint contract is documented in API.md.
- Backend process:
npm run devinbackend/ - Frontend process:
npm run devinfrontend/ - MongoDB: local service or Docker (
backend/docker-compose.yml) - Optional Redis via
REDIS_URL
No production deployment manifest (for example Dockerfile, Kubernetes, or cloud IaC) was found in this repository.
TODO: add standardized production deployment documentation after the deployment target is finalized.
Backend startup calls seedSchemesAndAdvisory() on boot, which clears and reseeds those collections.