Spaces:
Running
title: Agromind Backend
emoji: π
colorFrom: green
colorTo: blue
sdk: docker
app_port: 7860
AgroMind: Where Farmers Meet AI & Technology for a Greener Future! πΎ
AgroMind is an innovative platform designed to empower farmers by connecting them with agricultural experts, AI-powered tools, and modern technology. Our goal is to make farming smarter, more efficient, and more sustainable.
π Key Features
Core Features
- Expert Consultations - Real-time video calls and chat with agricultural experts
- AI-Powered Recommendations - Crop, fertilizer, and yield predictions
- Task Management - Goal-based scheduling and tracking
- Weather Alerts - Real-time weather updates and recommendations
- Revenue Tracking - Income and expense management
New Features (v2.0)
| Feature | Description |
|---|---|
| Value Chain Marketplace | Connect farmers, processors, and buyers for oilseed by-products |
| Hedging Platform | Virtual hedging, price risk management, forward contracts |
| Crop Economics | Comparative crop analysis, govt schemes, profitability simulation |
| Oil Palm Advisory | Farmer profiling, ROI projections, gestation support tracking |
| Yield Optimization | AI-driven yield predictions with intervention suggestions |
| Tariff Simulator | Model impact of customs duty changes on prices |
| Millets Marketplace | Specialized marketplace with traceability and offline support |
| CRM Machine Tracking | Real-time tracking of crop residue management machines |
| CROPIC | AI-based crop damage assessment for insurance |
ποΈ Architecture
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Frontend β
β (React.js + Vite) β
βββββββββββββββββββββββ¬ββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββΌββββββββββββββββ
βΌ βΌ βΌ
ββββββββββββ ββββββββββββ ββββββββββββββββ
β Backend β β AI Backendβ β Smart Contractsβ
β Node.js β β Python β β Solidity β
ββββββ¬ββββββ ββββββ¬ββββββ ββββββββββββββββ
β β
ββββββββ¬ββββββββ
βΌ
ββββββββββββ
β MongoDB β
β Redis β
ββββββββββββ
π¦ Quick Start
Prerequisites
- Node.js 20+
- Python 3.11+
- Docker & Docker Compose (recommended)
- MongoDB
Local Development with Docker
# Clone repository
git clone https://github.com/Anamitra-Sarkar/AgroMind.git
cd AgroMind
# Copy environment file
cp .env.sample .env
# Start all services
docker-compose up -d
# Access applications
# Frontend: http://localhost:5173
# Backend: http://localhost:8000
# AI Backend: http://localhost:5000
Manual Setup
# Backend
cd backend && npm install && npm run dev
# AI Backend
cd ai-backend && pip install -r requirements.txt && python app.py
# Frontend
cd frontend && npm install && npm run dev
π§ Environment Variables
See .env.sample for all required environment variables.
Key Variables
| Variable | Description |
|---|---|
MONGO_URL |
MongoDB connection string |
JWT_KEY |
JWT signing key |
FRONTEND_URL |
Frontend URL for CORS |
AI_BACKEND_URL |
AI backend URL |
OPENWEATHER_API_KEY |
OpenWeather API key |
GEMINI_API_KEY |
Google Gemini AI key |
π οΈ Technology Stack
Frontend
- React.js 18 + Vite
- TailwindCSS + Material-UI
- Chart.js + Recharts
- Socket.IO Client
- i18next (internationalization)
Backend
- Node.js + Express.js
- MongoDB + Mongoose
- Redis (caching)
- Socket.IO
- JWT Authentication
AI Backend
- Python + Flask
- PyTorch + scikit-learn
- LightGBM (price forecasting)
- ResNet (image classification)
Infrastructure
- Docker + Docker Compose
- GitHub Actions CI/CD
- Vercel (frontend hosting)
- Hugging Face Spaces (backend hosting)
- Prometheus + Grafana (monitoring)
π API Documentation
Backend API Endpoints
| Endpoint | Description |
|---|---|
/api/auth/* |
Authentication |
/api/valuechain/* |
Marketplace |
/api/hedging/* |
Hedging platform |
/api/crop-economics/* |
Crop comparison |
/api/oilpalm/* |
Oil palm advisory |
/api/crm/* |
Machine tracking |
/api/millets/* |
Millets marketplace |
AI Backend Endpoints
| Endpoint | Description |
|---|---|
/ai/price-forecast |
Price predictions |
/ai/yield-predict |
Yield predictions |
/ai/tariff-simulate |
Tariff impact simulation |
/ai/cropic/analyze |
Crop damage analysis |
/crop_recommendation |
Crop recommendations |
/fertilizer_prediction |
Fertilizer suggestions |
π Full API documentation: docs/postman_collection.json
π§ͺ Testing
# Backend tests
cd backend && npm test
# AI Backend tests
cd ai-backend && pytest tests/ -v
# Frontend tests
cd frontend && npm test
# E2E tests
cd frontend && npm run cypress:open
# Smart contract tests
cd backend/contracts && npm test
AI Backend Testing Details
The AI backend now includes comprehensive test coverage with:
Test Coverage:
- Unit tests for model predictions (
tests/test_models.py) - 15 passing, 5 skipped - Integration tests for all API endpoints (
tests/test_api_integration.py) - Existing validation tests (
tests/test_endpoints.py)
Test Features:
- Mocked models for fast, deterministic tests (no HF downloads)
- Retry logic testing with transient failures
- Error handling and exception logging validation
- Content-Type and JSON payload validation
- Model loading and caching tests
Run with Coverage:
cd ai-backend
pytest tests/ -v --cov=. --cov-report=html
For detailed testing documentation and sample payloads, see docs/TESTING.md.
π Deployment
Frontend β Vercel
cd frontend
vercel --prod
Hugging Face Spaces β Backend only
To push only the backend and ai-backend folders (avoid large frontend/binary files), use the helper script:
Example:
chmod +x scripts/push_to_hf.sh
./scripts/push_to_hf.sh https://huggingface.co/spaces/<username>/<repo>
This creates a temporary git repo containing only backend and ai-backend and force-pushes main to the provided remote.
GitHub Action (recommended)
You can automate the push using the provided GitHub Action. It creates a temporary repo with only backend and ai-backend and pushes it to your Hugging Face Space.
- Add a repository secret named
HF_TOKENcontaining a Hugging Face token with repo write access. - Run the workflow manually from the Actions tab and provide the
hf_repoinput (e.g.username/Agromind-backend).
Workflow options:
- hf_branch: target branch on the Hugging Face repo (default
main). - force: set to
trueto force-push the target branch (defaultfalse). Avoid force-push unless you intentionally want to overwrite history. - dry_run: set to
trueto prepare the temporary repo and list files without pushing (defaultfalse).
Recommended safe flow:
- Run with
dry_run=trueto verify what will be pushed. - Run with
force=falseto push to a branch without overwriting history. If you specifically need to replace the remote branch, setforce=true.
The workflow file is .github/workflows/push_to_hf.yml.
Backend β Hugging Face Spaces
See docs/deploy.md for detailed deployment instructions.
Required GitHub Secrets
VERCEL_TOKEN
VERCEL_ORG_ID
VERCEL_PROJECT_ID
HF_TOKEN
HF_BACKEND_SPACE_ID
HF_AI_BACKEND_SPACE_ID
π Project Structure
AgroMind/
βββ frontend/ # React frontend
βββ backend/ # Node.js backend
β βββ routes/ # API routes
β βββ controllers/ # Route handlers
β βββ models/ # MongoDB models
β βββ middleware/ # Express middleware
β βββ socket/ # Socket.IO handlers
β βββ contracts/ # Smart contracts
βββ ai-backend/ # Python AI backend
β βββ model/ # ML models
β βββ tests/ # Python tests
βββ docs/ # Documentation
βββ config/ # Configuration files
βββ scripts/ # Utility scripts
βββ docker-compose.yml # Local development
π Documentation
- Architecture - System design and diagrams
- Deployment - Deployment instructions
- Security - Security checklist
- ML Models - Model documentation
- Local Setup - Local development guide
π Security
- JWT-based authentication
- Rate limiting and CORS
- Input validation and sanitization
- Encrypted data storage
- Regular dependency scanning
See docs/security.md for the full security checklist.
π€ Contributing
We welcome contributions! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
π License
This project is licensed under the ISC License.
π Support
For support, email support@agromind.app or join our community.
AgroMind: Empowering farmers with technology for a greener, smarter future! π±
