A full-stack mobile application for rice trading with real-time bidding and logistics features.
- Project Overview
- Features
- Tech Stack
- Prerequisites
- Installation
- Environment Variables
- API Endpoints
- Authentication
- Error Handling
- Examples
The Rice Trade Platform is a comprehensive mobile application backend designed to facilitate rice trading between sellers, buyers, and logistics providers. The platform enables real-time bidding, order management, and logistics tracking.
- User registration and authentication
- Product listing and management
- Real-time bidding system
- Order management and tracking
- Logistics assignment
- Payment processing
- Analytics and reporting
- Push notifications for bids and orders
- User registration and authentication
- Browse and search products
- Place bids on products
- View bid history
- Order management
- Track order status
- Payment processing
- Push notifications for bid status and orders
- User registration and authentication
- Order pickup and delivery management
- Real-time location tracking
- OTP-based verification system
- Order status updates
- Route optimization
- Push notifications for new orders
- Real-time chat between users
- Location-based services
- Secure payment processing
- Push notifications
- User profile management
- Rating and review system
- Search and filter functionality
- Multi-language support
- Node.js
- Express.js
- MongoDB
- Socket.io (for real-time features)
- JWT Authentication
- Bcrypt for password hashing
- Mongoose ODM
- Postman for API testing
- Git for version control
- VS Code for development
- Android Studio for mobile development
- Node.js (v14 or higher)
- MongoDB (running locally or remote)
- npm or yarn package manager
- Clone the repository
git clone https://github.com/srajan-kush/Integrated-Rice-Trade-Platform-backend.git
cd Integrated-Rice-Trade-Platform-backend- Install dependencies
npm install- Create a
.envfile in the root directory with the following variables:
PORT=8001
MONGO_URI=mongodb://127.0.0.1:27017/kuteeram
JWT_SECRET=your-secret-key-here
CLIENT_URL=http://localhost:3000- Start the development server
npm run devThe server will start at http://localhost:8001
POST /api/auth/seller/registerRequest body:
{
"name": "Seller Name",
"email": "seller@example.com",
"password": "password123",
"phone": "1234567890",
"city": "City Name",
"location": {
"coordinates": [longitude, latitude]
}
}POST /api/auth/buyer/registerRequest body:
{
"name": "Buyer Name",
"phone": "1234567890",
"password": "password123",
"location": {
"coordinates": [longitude, latitude]
}
}POST /api/auth/logistics/registerRequest body:
{
"name": "Logistics Company",
"email": "logistics@example.com",
"password": "password123",
"phone": "1234567890",
"address": {
"coordinates": [longitude, latitude]
}
}POST /api/auth/{userType}/loginRequest body:
{
"email": "user@example.com",
"password": "password123"
}GET /api/auth/meHeaders:
Authorization: Bearer YOUR_JWT_TOKEN
POST /api/auth/logoutHeaders:
Authorization: Bearer YOUR_JWT_TOKEN
GET /api/productsQuery Parameters:
- category: Filter by category
- minPrice: Minimum price
- maxPrice: Maximum price
- search: Search in name and description
- sort: Sort by price, date, etc.
GET /api/products/nearbyQuery Parameters:
- latitude: User's latitude
- longitude: User's longitude
- radius: Search radius in kilometers
GET /api/products/:idPOST /api/productsHeaders:
Authorization: Bearer YOUR_JWT_TOKEN
Request body:
{
"name": "Product Name",
"description": "Product Description",
"price": 99.99,
"category": "Electronics",
"stock": 100,
"images": ["image_url1", "image_url2"]
}PUT /api/products/:idHeaders:
Authorization: Bearer YOUR_JWT_TOKEN
DELETE /api/products/:idHeaders:
Authorization: Bearer YOUR_JWT_TOKEN
GET /api/products/seller/productsHeaders:
Authorization: Bearer YOUR_JWT_TOKEN
POST /api/bidsHeaders:
Authorization: Bearer YOUR_JWT_TOKEN
Request body:
{
"productId": "product_id",
"amount": 120.50
}GET /api/bids/buyerHeaders:
Authorization: Bearer YOUR_JWT_TOKEN
GET /api/bids/sellerHeaders:
Authorization: Bearer YOUR_JWT_TOKEN
PUT /api/bids/:id/acceptHeaders:
Authorization: Bearer YOUR_JWT_TOKEN
PUT /api/bids/:id/rejectHeaders:
Authorization: Bearer YOUR_JWT_TOKEN
PUT /api/bids/:id/cancelHeaders:
Authorization: Bearer YOUR_JWT_TOKEN
GET /api/orders/sellerHeaders:
Authorization: Bearer YOUR_JWT_TOKEN
GET /api/orders/buyerHeaders:
Authorization: Bearer YOUR_JWT_TOKEN
GET /api/orders/logisticsHeaders:
Authorization: Bearer YOUR_JWT_TOKEN
GET /api/orders/:idHeaders:
Authorization: Bearer YOUR_JWT_TOKEN
PUT /api/orders/:id/statusHeaders:
Authorization: Bearer YOUR_JWT_TOKEN
PUT /api/orders/:id/assign-logisticsHeaders:
Authorization: Bearer YOUR_JWT_TOKEN
PUT /api/orders/:id/verify-pickupHeaders:
Authorization: Bearer YOUR_JWT_TOKEN
PUT /api/orders/:id/verify-deliveryHeaders:
Authorization: Bearer YOUR_JWT_TOKEN
PUT /api/orders/:id/update-locationHeaders:
Authorization: Bearer YOUR_JWT_TOKEN
The API uses JWT (JSON Web Tokens) for authentication. The token is stored in an HTTP-only cookie named jwt.
- Token is generated upon successful login/register
- Token expires in 30 days
- Token is automatically sent with each request in cookies
- Protected routes require a valid token
The API returns appropriate HTTP status codes and error messages:
- 400: Bad Request
- 401: Unauthorized
- 403: Forbidden
- 404: Not Found
- 500: Internal Server Error
Error response format:
{
"success": false,
"statusCode": 400,
"message": "Error message"
}- Register Seller:
curl -X POST http://localhost:8001/api/auth/seller/register \
-H "Content-Type: application/json" \
-d '{"name":"Test Seller","email":"seller@example.com","password":"password123","phone":"1234567890","city":"Test City","location":{"coordinates":[0,0]}}'- Login:
curl -X POST http://localhost:8001/api/auth/seller/login \
-H "Content-Type: application/json" \
-d '{"email":"seller@example.com","password":"password123"}'- Create Product:
curl -X POST http://localhost:8001/api/products \
-H "Content-Type: application/json" \
-H "Cookie: jwt=your-jwt-token" \
-d '{"name":"Product Name","description":"Product Description","price":99.99,"category":"Electronics","stock":100}'- Place Bid:
curl -X POST http://localhost:8001/api/bids \
-H "Content-Type: application/json" \
-H "Cookie: jwt=your-jwt-token" \
-d '{"productId":"product_id","amount":120.50}'- Passwords are hashed using bcrypt
- JWT tokens are stored in HTTP-only cookies
- SameSite cookie policy is set to 'strict'
- Secure cookie flag is enabled in production
- Input validation is performed on all endpoints
- Error messages are generic to prevent information leakage
- Authorization checks for product and bid operations
- Rate limiting can be implemented for production