npm install# Create .env file with:
DATABASE_URL="postgresql://user:password@localhost:5432/urban_farming"
JWT_SECRET="your-secret-key"
JWT_EXPIRE="7d"
PORT=3000# Run migrations
npx prisma migrate dev --name init
# Seed database
npm run seed# Development
npm run dev
# Production
npm startServer will be available at: http://localhost:3000
API Docs: http://localhost:3000/api-docs
All protected routes require a Bearer token in the Authorization header:
Authorization: Bearer <your_jwt_token>
POST /api/auth/login
Content-Type: application/json
{
"email": "user@example.com",
"password": "password123"
}Response:
{
"success": true,
"data": {
"user": {
"id": "uuid",
"name": "User Name",
"email": "user@example.com",
"role": "customer"
},
"token": "eyJhbGciOiJIUzI1NiIs..."
},
"message": "Login successful"
}POST /api/auth/register
Content-Type: application/json
{
"name": "New User",
"email": "newuser@example.com",
"password": "securepassword",
"role": "customer"
}GET /api/produce?page=1&limit=20&category=vegetables&minPrice=50&maxPrice=200Query Parameters:
page(optional): Page number, default: 1limit(optional): Items per page, default: 20category(optional): Filter by categoryminPrice(optional): Minimum price filtermaxPrice(optional): Maximum price filter
Response:
{
"success": true,
"data": [...],
"pagination": {
"total": 150,
"page": 1,
"limit": 20,
"totalPages": 8,
"hasMore": true
}
}GET /api/produce/:idPOST /api/vendor/produce
Authorization: Bearer <token>
Content-Type: application/json
{
"name": "Organic Tomatoes",
"description": "Fresh organic tomatoes",
"price": 150.00,
"category": "vegetables",
"availableQuantity": 50
}PUT /api/vendor/produce/:id
Authorization: Bearer <token>
Content-Type: application/json
{
"price": 160.00,
"availableQuantity": 45
}POST /api/vendor/profile
Authorization: Bearer <token>
Content-Type: application/json
{
"farmName": "Green Valley Farm",
"farmDescription": "Sustainable urban farm",
"farmLocation": {
"type": "Point",
"coordinates": [40.7128, -74.0060]
}
}GET /api/vendor/profile
Authorization: Bearer <token>PUT /api/vendor/profile
Authorization: Bearer <token>
Content-Type: application/json
{
"farmName": "Updated Farm Name",
"farmDescription": "Updated description"
}GET /api/rentals?page=1&limit=20GET /api/rentals/:idPOST /api/vendor/rentals
Authorization: Bearer <token>
Content-Type: application/json
{
"name": "Garden Plot A",
"size": 50,
"price": 250,
"location": {
"type": "Point",
"coordinates": [40.7128, -74.0060]
}
}GET /api/plants
Authorization: Bearer <token>POST /api/plants
Authorization: Bearer <token>
Content-Type: application/json
{
"plantName": "Tomato Plant",
"plantType": "vegetable",
"plantingDate": "2026-04-01",
"expectedHarvestDate": "2026-06-01"
}PUT /api/plants/:id/health
Authorization: Bearer <token>
Content-Type: application/json
{
"healthStatus": "excellent",
"growthStage": "fruiting"
}GET /api/plants/:id
Authorization: Bearer <token>DELETE /api/plants/:id
Authorization: Bearer <token>GET /api/community/posts?page=1&limit=20&category=gardening_tipsGET /api/community/posts/:idPOST /api/community/posts
Authorization: Bearer <token>
Content-Type: application/json
{
"title": "Tips for Urban Gardening",
"content": "Here are my tips for successful urban gardening...",
"category": "gardening_tips"
}POST /api/community/posts/:id/like
Authorization: Bearer <token>POST /api/vendor/certification
Authorization: Bearer <token>
Content-Type: application/json
{
"certifyingAgency": "USDA_Organic",
"certificateNumber": "CERT-12345",
"issueDate": "2026-01-01",
"expiryDate": "2027-01-01"
}GET /api/vendor/certifications
Authorization: Bearer <token>PUT /api/admin/certification/:id
Authorization: Bearer <token>
Content-Type: application/json
{
"status": "verified",
"rejectionReason": null
}GET /api/admin/certifications?page=1&limit=20&status=pending
Authorization: Bearer <token>All errors return a consistent format:
{
"success": false,
"error": "Error Type",
"message": "Human readable message",
"timestamp": "2026-04-16T10:30:00.000Z"
}| Code | Error | Meaning |
|---|---|---|
| 400 | Bad Request | Invalid input parameters |
| 401 | Unauthorized | Missing or invalid token |
| 403 | Forbidden | Not authorized for this resource |
| 404 | Not Found | Resource doesn't exist |
| 500 | Server Error | Unexpected server error |
The API implements rate limiting to prevent abuse:
| Endpoint Type | Limit | Window |
|---|---|---|
| Auth (login/register) | 5 requests | 15 minutes |
| General API | 100 requests | 1 minute |
| Strict (admin) | 10 requests | 15 minutes |
Response headers include:
X-RateLimit-Limit: 100
X-RateLimit-Remaining: 98
X-RateLimit-Reset: 1650195000
const socket = io('http://localhost:3000');
// Join plant room for updates
socket.emit('join-plant-room', 'plant-uuid');
// Listen for health updates
socket.on('health-updated', (data) => {
console.log('Plant health updated:', data);
});
// Emit plant health update
socket.emit('plant-health-update', {
plantId: 'uuid',
healthStatus: 'excellent',
growthStage: 'fruiting'
});- id (UUID)
- name (String)
- email (String, unique)
- password (String, hashed)
- role (enum: admin, vendor, customer)
- status (enum: active, inactive)
- createdAt, updatedAt
- id (UUID)
- userId (Foreign Key β User)
- farmName, farmDescription
- certificationStatus, rating
- farmLocation (GeoJSON)
- id (UUID)
- vendorId (Foreign Key β VendorProfile)
- name, description, price
- category, certificationStatus
- availableQuantity, isAvailable
- id (UUID)
- userId (Foreign Key β User)
- plantName, plantType
- plantingDate, expectedHarvestDate
- healthStatus, growthStage
Admin:
Email: admin@example.com
Password: admin123
Vendor:
Email: vendor1@example.com
Password: vendor123
Customer:
Email: customer1@example.com
Password: customer123
Error: ECONNREFUSED 127.0.0.1:5432
Solution: Ensure PostgreSQL is running and DATABASE_URL is correct in .env
Error: Invalid token
Solution: Generate new token by logging in again
Error: Too many requests, please try again later
Solution: Wait for the rate limit window to reset (check X-RateLimit-Reset header)
- API Docs: http://localhost:3000/api-docs
- Performance Report: See BENCHMARK_REPORT.md
- Strategy Guide: See API_STRATEGY.md
Last Updated: April 16, 2026