A comprehensive full-stack web application connecting farmers directly with buyers, eliminating middlemen and enabling fair pricing for agricultural products.
- Features
- Tech Stack
- Project Structure
- Installation
- Configuration
- Running the Application
- API Endpoints
- Database Schema
- Features Breakdown
- Demo Accounts
- 🏠 Home Page: Modern landing page with hero section and CTA buttons
- 👨🌾 Farmer Module: Registration, profile creation, product management, order tracking
- 🛒 Buyer Module: Signup, product browsing, cart management, order placement
- 📦 Product Listing: Farmers can add products with images, quantity, price, location
- 🛍️ Marketplace: Grid-based product display with filters (category, price, location) and search
- 💬 Price Negotiation: Direct communication system between farmers and buyers
- 📦 Order Management: Full order lifecycle from cart to delivery
- 💳 Payment Integration: UI for UPI, Card, and Cash on Delivery
- 🧑💼 Admin Dashboard: Analytics, user management, order tracking
- 📊 Analytics Dashboard: Charts and statistics for admins
- 🌦️ Weather Widget: (Ready for integration)
- 🌱 Farmer Tips: Blog section with agricultural articles
- 🌐 Multi-language Support: English, Hindi, Marathi (Ready for integration)
- 📱 Fully Responsive: Mobile-first design
- Framework: Next.js 14 with React 18
- Styling: Tailwind CSS
- State Management: Zustand
- Animations: Framer Motion
- Charts: Recharts
- Icons: React Icons
- HTTP Client: Axios
- Runtime: Node.js (Next.js API Routes)
- Database: MongoDB with Mongoose ORM
- Authentication: JWT (JSON Web Tokens)
- Password Hashing: bcryptjs
- Package Manager: npm/yarn
- Version Control: Git
- Environment: .env.local
farmdirect/
├── app/
│ ├── api/
│ │ ├── auth/
│ │ │ ├── register/
│ │ │ └── login/
│ │ ├── products/
│ │ │ ├── route.ts (GET all products)
│ │ │ ├── create/
│ │ │ └── [id]/
│ │ ├── orders/
│ │ │ ├── route.ts (GET orders)
│ │ │ ├── create/
│ │ │ └── [id]/
│ │ ├── cart/
│ │ │ └── route.ts (GET, POST, DELETE)
│ │ ├── users/
│ │ │ └── profile/
│ │ └── admin/
│ │ └── analytics/
│ ├── (pages)
│ │ ├── page.tsx (Home)
│ │ ├── register/
│ │ ├── login/
│ │ ├── marketplace/
│ │ ├── cart/
│ │ ├── dashboard/
│ │ ├── contact/
│ │ └── admin/
│ ├── layout.tsx (Root layout)
│ └── globals.css
├── components/
│ ├── Navbar.tsx
│ ├── Footer.tsx
│ ├── HeroSection.tsx
│ └── ProductCard.tsx
├── lib/
│ ├── db.ts (MongoDB connection)
│ ├── auth.ts (JWT utilities)
│ ├── response.ts (API response utilities)
│ ├── authStore.ts (Auth Zustand store)
│ └── cartStore.ts (Cart Zustand store)
├── models/
│ ├── User.ts
│ ├── Product.ts
│ ├── Order.ts
│ └── Cart.ts
├── types/
│ └── index.ts
├── public/
├── .env.local.example
├── tailwind.config.js
├── postcss.config.js
├── next.config.js
├── package.json
└── README.md
- Node.js 18+ and npm/yarn
- MongoDB (local or MongoDB Atlas)
- Git
git clone https://github.com/yourusername/farmdirect.git
cd farmdirectnpm install
# or
yarn installcp .env.local.example .env.localEdit .env.local with your configuration:
MONGODB_URI=mongodb://localhost:27017/farmers-market
JWT_SECRET=your-secret-key-here
NEXT_PUBLIC_API_URL=http://localhost:3000# If using local MongoDB
mongod
# Or use MongoDB Atlas (cloud)
# Update MONGODB_URI in .env.localnpm run dev
# or
yarn devVisit http://localhost:3000 in your browser.
Local MongoDB:
# Install MongoDB Community Edition
# macOS (with Homebrew):
brew tap mongodb/brew
brew install mongodb-community
# Start MongoDB:
brew services start mongodb-community
# Connect:
mongo mongodb://localhost:27017MongoDB Atlas (Cloud):
- Create account at mongodb.com/atlas
- Create a cluster
- Get connection string
- Update
MONGODB_URIin.env.local
Generate a strong secret:
node -e "console.log(require('crypto').randomBytes(32).toString('hex'))"npm run dev- Access: http://localhost:3000
- Hot reload enabled
- Debug friendly
npm run build
npm startnpm run lintPOST /api/auth/register- User registrationPOST /api/auth/login- User login
GET /api/products- Get all products with filtersPOST /api/products/create- Create product (Farmers only)GET /api/products/[id]- Get product detailsPUT /api/products/[id]- Update productDELETE /api/products/[id]- Delete product
GET /api/orders- Get user ordersPOST /api/orders/create- Create orderGET /api/orders/[id]- Get order detailsPUT /api/orders/[id]- Update order status
GET /api/cart- Get cart itemsPOST /api/cart- Add to cartDELETE /api/cart?productId=xxx- Remove from cart
GET /api/users/profile- Get user profilePUT /api/users/profile- Update profile
GET /api/admin/analytics- Get system analytics
{
firstName: string
lastName: string
email: string (unique)
password: string (hashed)
phone: string
role: 'farmer' | 'buyer' | 'admin'
avatar: string
address: {
street: string
city: string
state: string
zipCode: string
country: string
}
// Farmer specific
farmName?: string
farmSize?: number
cropsGrown?: string[]
registrationNumber?: string
bankDetails?: { accountHolder, accountNumber, ifscCode }
// Buyer specific
companyName?: string
businessType?: 'individual' | 'retailer' | 'wholesaler'
isVerified: boolean
isActive: boolean
createdAt: Date
updatedAt: Date
}{
name: string
description: string
category: string (enum)
subcategory?: string
price: number
quantity: number
unit: string (kg, liter, dozen, etc.)
images: string[]
farmer: ObjectId (ref: User)
location: { city, state, zipCode }
harvestDate?: Date
expiryDate?: Date
certifications?: string[]
minOrderQuantity: number
rating: number
reviews: Array<{ buyer, rating, comment, createdAt }>
isAvailable: boolean
tags?: string[]
createdAt: Date
updatedAt: Date
}{
orderNumber: string (unique)
buyer: ObjectId (ref: User)
farmer: ObjectId (ref: User)
items: Array<{ product, productName, quantity, price, subtotal }>
totalAmount: number
status: 'pending' | 'confirmed' | 'shipped' | 'delivered' | 'cancelled'
paymentMethod: 'upi' | 'card' | 'cod' | 'bank_transfer'
paymentStatus: 'pending' | 'completed' | 'failed'
deliveryAddress: { street, city, state, zipCode }
deliveryDate?: Date
notes?: string
trackingNumber?: string
createdAt: Date
updatedAt: Date
}{
buyer: ObjectId (ref: User, unique)
items: Array<{ product, quantity, price, farmer }>
totalItems: number
totalPrice: number
createdAt: Date
updatedAt: Date
}- JWT-based authentication
- Role-based access (farmer, buyer, admin)
- Password hashing with bcryptjs
- Session management with Zustand
- Add products with images
- Edit and delete listings
- Track inventory
- View product performance
- Browse all products
- Filter by category, price, location
- Search functionality
- Wishlist (ready to implement)
- Create orders from cart
- Track order status
- View order history
- Order cancellation
- UPI integration ready
- Card payment interface
- Cash on Delivery option
- Payment status tracking
- User analytics
- Order statistics
- Revenue tracking
- System health monitoring
Email: farmer@demo.com
Password: password123
Role: Farmer
Email: buyer@demo.com
Password: password123
Role: Buyer
Email: admin@demo.com
Password: password123
Role: Admin
To create demo accounts, seed the database:
node scripts/seed.js- ✅ Password hashing with bcryptjs
- ✅ JWT token-based authentication
- ✅ CORS protection ready
- ✅ Environment variable protection
- ✅ SQL injection prevention (MongoDB)
- ✅ XSS protection with React
- Real-time chat system
- Video call between farmers and buyers
- Weather API integration
- Blog system with farming tips
- Multi-language support (Hindi, Marathi)
- Notification system
- Advanced analytics
- Mobile app (React Native)
- Payment gateway integration (Stripe, Razorpay)
- Ratings and reviews system
- Wishlist feature
- Subscription plans for farmers
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For support, email support@farmdirect.in or open an issue on GitHub.
Developed as a comprehensive FarmTech solution for direct farmer-to-buyer marketplace platform.
Made with ❤️ for Indian Agriculture 🌾