CropConnect is a full-stack web application designed to eliminate intermediaries in agriculture by connecting farmers directly with buyers. Featuring location-based matching powered by Mapbox GL JS, real-time crop inventory management, and intuitive order request workflows, CropConnect makes produce trade transparent, efficient, and direct.
🌐 Live Application: https://crop-connect-t0qz.onrender.com/
- Inventory Management: Create, update, adjust prices, or remove crop listings in real-time.
- Request Dashboard: View incoming purchase requests from buyers with full quantity and pricing breakdowns.
- Order Fulfilment: Accept inventory orders and track transaction statuses.
- Geospatial Discovery: Interactive Mapbox map rendering nearby farmers with custom markers and crop availability.
- Direct Requests: Send purchase requests directly to farmers based on quantity and location requirements.
- Order History: Track past orders, pending offers, and accepted transactions.
- Geocoding API: Automatic conversion of location strings to geographical coordinates using
@mapbox/mapbox-sdk. - Custom Interactive Map: Visually locate registered farmers on dynamic vector maps.
- Dual Authentication Strategies: Dedicated authentication workflows for Farmers (
farmer-local) and Buyers (buyer-local) via Passport.js. - Session Store: Secure MongoDB-backed sessions via
connect-mongowith session expiration and flash messaging.
┌─────────────────────────────────────────────────────────────┐
│ CropConnect │
└──────────────────────────────┬──────────────────────────────┘
│
┌───────────────────────┼───────────────────────┐
▼ ▼ ▼
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Frontend │ │ Backend │ │ Database │
├──────────────┤ ├──────────────┤ ├──────────────┤
│ EJS / Boiler │ │ Express 5.x │ │ MongoDB │
│ Mapbox GL JS │ │ Node.js 20 │ │ Mongoose ORM │
│ Vanilla CSS │ │ Passport.js │ │ Connect-Mongo│
└──────────────┘ └──────────────┘ └──────────────┘
| Component | Technology | Description |
|---|---|---|
| Runtime Environment | Node.js (v20.12.2) | Server-side JavaScript execution environment |
| Web Framework | Express.js (v5.1.0) | Web application framework handling routing & middleware |
| Database | MongoDB & Mongoose | NoSQL database with object data modeling (ODM) |
| Templating Engine | EJS & EJS-Mate | Server-side template rendering with modular layouts |
| Authentication | Passport.js & Passport-Local | Dual-strategy authentication for Farmers and Buyers |
| Session Store | Express-Session & Connect-Mongo | Session handling persisted in MongoDB Atlas |
| Maps & Geocoding | Mapbox GL JS & @mapbox/mapbox-sdk |
Interactive maps and forward geocoding |
| Data Validation | Joi | Schema validation for user inputs and inventory items |
Crop_Connect/
├── config/ # Configuration files
│ ├── database.js # MongoDB database connection setup
│ ├── passport.js # Passport auth strategies (farmer-local, buyer-local)
│ └── index.js # Configuration export barrel
├── controllers/ # Request handlers (MVC Architecture)
│ ├── auth.controller.js # Authentication logic
│ ├── farmer.controller.js # Farmer dashboard & inventory operations
│ ├── buyer.controller.js # Buyer discovery & request submission
│ └── index.js # Controller export barrel
├── middleware/ # Custom Express middleware
│ ├── index.js # Role validation & route guard middleware
│ └── middleware.legacy.js # Legacy route handler fallbacks
├── models/ # Mongoose Schemas & Models
│ ├── User.js # Base User schema
│ ├── Farmer.js # Farmer profile schema
│ ├── Buyer.js # Buyer profile schema
│ ├── Inventory.js # Crop inventory schema
│ └── Request.js # Trade request schema
├── routes/ # Application Routes
│ ├── api.js # RESTful JSON endpoints (stats, geocoding)
│ ├── auth.js # Login/Register/Logout routes
│ ├── buyer.js # Buyer workspace routes
│ ├── farmer.js # Farmer workspace routes
│ └── index.js # Main router registry
├── services/ # Business & API Integration Logic
│ ├── request.service.js # Order transaction processing
│ └── map.service.js # Mapbox geocoding interface
├── views/ # EJS View Templates
│ ├── layouts/ # Base layout wrappers (boilerplate)
│ ├── pages/ # Main view pages (home, dashboard, auth)
│ └── partials/ # Reusable UI partials (header, footer, flash alerts)
├── public/ # Static Assets
│ ├── css/ # Custom stylesheets
│ └── js/ # Client-side JavaScript
├── .env # Environment variables (Git-ignored)
├── app.js # Application entry point
└── package.json # NPM dependencies & scripts
CropConnect exposes internal JSON API endpoints for data fetching and geocoding:
| Method | Endpoint | Auth Required | Description |
|---|---|---|---|
GET |
/api/request/:id |
Yes | Retrieves order request details by ID |
GET |
/api/stats |
No | Retrieves global platform transaction statistics |
GET |
/api/coordinates |
No | Converts location query string to Mapbox geo-coordinates |
Follow these steps to run CropConnect locally on your machine.
- Node.js (v20.12.2 or higher recommended)
- MongoDB (Local instance or MongoDB Atlas URI)
- Mapbox Access Token (Free tier key for geocoding & interactive maps)
-
Clone the repository:
git clone https://github.com/Sampath-12-alt/Crop_Connect.git cd Crop_Connect -
Install dependencies:
npm install
-
Configure Environment Variables: Create a
.envfile in the root directory:touch .env
Add the following configuration parameters:
# Database Connection String ATLASDB_URL=mongodb+srv://<username>:<password>@cluster0.example.mongodb.net/cropconnect # Mapbox API Token MAP_TOKEN=pk.eyJ1IjoiZXhhbXBsZSIsImEiOiJjbGV4YW1wbGUifQ.example_token # Session Secret SECRET=your_super_secret_session_key # Application Port (Optional, defaults to 8080) PORT=8080
-
Run the Development Server:
# Using nodemon for hot-reloading npm run dev # Or using standard node execution npm start
-
Access the Application: Open your browser and navigate to:
http://localhost:8080
| Variable | Required | Description |
|---|---|---|
ATLASDB_URL |
Yes | MongoDB connection string (Atlas or Local MongoDB URI) |
MAP_TOKEN |
Yes | Mapbox GL public access token for maps & geocoding |
SECRET |
Yes | Secret string used to sign express-session cookie |
PORT |
No | Port on which server runs (Default: 8080) |
NODE_ENV |
No | Application environment (development / production) |
Contributions are welcome! If you'd like to improve CropConnect:
- Fork the Repository
- Create your Feature Branch (
git checkout -b feature/AwesomeFeature) - Commit your Changes (
git commit -m 'Add some AwesomeFeature') - Push to the Branch (
git checkout -b feature/AwesomeFeature) - Open a Pull Request
Sampath Chiluka
- GitHub: @Sampath-12-alt
This project is licensed under the ISC License.