A full-stack web application for tracking agricultural produce prices and providing smart farming advice using AI.
- 🔐 JWT-based authentication with role-based access (Admin/Farmer)
- 📊 CRUD operations for produce items and price entries
- 🌤️ Weather API integration (OpenWeatherMap)
- 🤖 AI-powered farming advice using Groq LLM
- 💬 Community forum with posts and comments
- 📈 7-day price history tracking
- 🎨 Modern, responsive UI with Mantine components
- 📊 Interactive price trend charts with Recharts
- 🌦️ Real-time weather display
- 💡 Smart advice based on price trends and weather
- 👥 Community forum for farmer discussions
- 🔒 Protected routes with role-based access
- FastAPI - Modern Python web framework
- MongoDB - NoSQL database with Motor (async driver)
- Pydantic - Data validation
- JWT - Authentication
- Groq API - AI model for farming advice
- OpenWeatherMap API - Weather data
- React - UI library
- Vite - Build tool
- Mantine - Component library
- Recharts - Data visualization
- Axios - HTTP client
- React Router - Navigation
/backend
├── /app
│ ├── /routers # API endpoints
│ │ ├── auth.py # Authentication
│ │ ├── produce.py # Produce & prices CRUD
│ │ ├── external_apis.py # Weather & AI
│ │ └── forum.py # Community forum
│ ├── /models # Pydantic models
│ │ ├── user.py
│ │ ├── produce.py
│ │ └── forum.py
│ ├── /utils # Utilities
│ │ ├── hashing.py # Password hashing
│ │ └── jwt_handler.py # JWT operations
│ ├── database.py # MongoDB connection
│ └── main.py # FastAPI app
├── .env # Environment variables
└── requirements.txt
/frontend
├── /src
│ ├── /api # Axios configuration
│ ├── /components # Reusable components
│ ├── /context # React context (auth)
│ ├── /pages # Page components
│ ├── App.jsx
│ └── main.jsx
├── index.html
├── package.json
└── vite.config.js
- Python 3.9+
- Node.js 16+
- MongoDB (local or cloud instance)
- OpenWeatherMap API key
- Groq API key
-
Navigate to backend directory:
cd backend
-
Create a virtual environment:
python -m venv venv .\venv\Scripts\Activate.ps1 -
Install dependencies:
pip install -r requirements.txt -
Configure environment variables:
- Open
.envfile and update the following:MONGODB_URL=mongodb://localhost:27017 DATABASE_NAME=smart_agriculture_db SECRET_KEY=your-secure-secret-key-here OPENWEATHER_API_KEY=your-openweathermap-api-key GROQ_API_KEY=your-groq-api-key
- Open
-
Run MongoDB:
- Make sure MongoDB is running locally or use MongoDB Atlas
-
Start the backend server:
uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
- API will be available at: http://localhost:8000
- API documentation: http://localhost:8000/docs
-
Navigate to frontend directory:
cd frontend
-
Install dependencies:
npm install
-
Start the development server:
npm run dev
- App will be available at: http://localhost:5173
POST /auth/register- Register new userPOST /auth/login- Login and get JWT token
POST /produce/- Add new produce (Admin only)POST /produce/prices- Add price entry (Admin only)GET /produce/- Get all produce with latest pricesGET /produce/{item_id}/history- Get 7-day price history
GET /api/weather?city={city}- Get weather dataPOST /api/advice- Get AI farming advice
POST /forum/posts- Create new postGET /forum/posts- Get all postsGET /forum/posts/{post_id}- Get post details with commentsPOST /forum/posts/{post_id}/comments- Add comment to post
- View produce prices and trends
- Get weather information
- Request AI farming advice
- Participate in forum discussions
- All farmer permissions
- Add new produce items
- Add/update price entries
- Manage market data
- Register as a farmer
- Login to access the dashboard
- View current market prices
- Click "View Trend" to see 7-day price history
- Click "Get Advice" for AI-powered recommendations
- Visit the forum to discuss with other farmers
- Register as an admin
- Login to access admin dashboard
- Add new produce items
- Add daily price entries for each produce
- Monitor market trends
- Moderate forum discussions
MONGODB_URL=mongodb://localhost:27017
DATABASE_NAME=smart_agriculture_db
SECRET_KEY=your-secret-key
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=60
OPENWEATHER_API_KEY=your-api-key
GROQ_API_KEY=your-api-key
ALLOWED_ORIGINS=http://localhost:5173- Sign up at https://openweathermap.org/
- Generate an API key
- Add to
.envfile
- Sign up at https://groq.com/
- Generate an API key
- Add to
.envfile
# Run with auto-reload
uvicorn app.main:app --reload
# Run tests (if implemented)
pytest
# Format code
black app/# Development server
npm run dev
# Build for production
npm run build
# Preview production build
npm run preview- Ensure MongoDB is running
- Check connection string in
.env - For MongoDB Atlas, whitelist your IP address
- Ensure frontend URL is in
ALLOWED_ORIGINSin backend.env - Check that frontend is making requests to correct backend URL
- Verify API keys are correct in
.env - Check API quota/limits haven't been exceeded
- Real-time price alerts
- Mobile app (React Native)
- Export data to CSV/Excel
- Multi-language support
- SMS notifications for price changes
- Crop recommendation system
- Marketplace integration
- Advanced analytics dashboard
MIT License
Built for the Web Hackathon
For issues and questions, please open an issue on GitHub or contact the development team.