A comprehensive microservices-based food delivery platform built with Node.js, TypeScript, Express, and Prisma.
The system consists of three main microservices:
- User Service (Port 3001) - Authentication, user management, ordering, and ratings
- Restaurant Service (Port 3002) - Restaurant management, menu items, and order processing
- Delivery Service (Port 3003) - Delivery agent management and order tracking
- Backend: Node.js, TypeScript, Express.js
- Database: PostgreSQL with Prisma ORM
- Authentication: JWT tokens
- Password Hashing: bcrypt
The system uses a shared database schema across all services with the following main entities:
- User - Supports multiple roles (user, restaurant_owner, delivery_agent, admin)
- Restaurant - Restaurant information and ownership
- MenuItem - Menu items for each restaurant
- Order - Order management with status tracking
- OrderItem - Individual items in an order
- DeliveryStatusUpdate - Tracking delivery progress
- DeliveryAgentAvailability - Agent availability status
- Rating - Reviews for restaurants and delivery agents
- Node.js (v16+)
- PostgreSQL
- npm or yarn
- Clone the repository
- Install dependencies for each service:
# User Service
cd user-service
npm install
# Restaurant Service
cd restaurant-service
npm install
# Delivery Service
cd delivery-service
npm install- Set up environment variables in each service:
DATABASE_URL="postgresql://username:password@localhost:5432/food_delivery"
JWT_SECRET="your-secret-key"
PORT=3001 # 3002 for restaurant, 3003 for delivery
NODE_ENV=development- Run database migrations:
npx prisma migrate dev- Start all services:
# Terminal 1 - User Service
cd user-service
npm run dev
# Terminal 2 - Restaurant Service
cd restaurant-service
npm run dev
# Terminal 3 - Delivery Service
cd delivery-service
npm run devAll protected endpoints require a Bearer token in the Authorization header:
Authorization: Bearer <jwt_token>
POST /api/auth/signup
{
"name": "John Doe",
"email": "john@example.com",
"password": "password123",
"role": "user" // user, restaurant_owner, delivery_agent, admin
}POST /api/auth/login
{
"email": "john@example.com",
"password": "password123"
}POST /api/orders (Protected - User role)
{
"restaurantId": "uuid",
"items": [
{
"menuItemId": "uuid",
"quantity": 2
}
]
}GET /api/orders (Protected - User role)
- Returns user's order history with restaurant and delivery agent details
GET /api/restaurants (Protected)
- Returns all online restaurants with their menu items
POST /api/ratings (Protected - User role)
{
"orderId": "uuid",
"ratingType": "restaurant", // restaurant or delivery_agent
"rating": 5,
"comment": "Great food!"
}POST /api/restaurants (Protected - Restaurant Owner)
{
"name": "Pizza Palace",
"address": "123 Main St, City"
}GET /api/restaurants/my-restaurants (Protected - Restaurant Owner)
- Returns owner's restaurants with menu items and order counts
PUT /api/restaurants/:id/status (Protected - Restaurant Owner/Admin)
{
"isOnline": true
}POST /api/menu (Protected - Restaurant Owner)
{
"restaurantId": "uuid",
"name": "Margherita Pizza",
"description": "Classic pizza with tomato and mozzarella",
"price": 12.99,
"isAvailable": true
}PUT /api/menu/:id (Protected - Restaurant Owner)
{
"name": "Updated Pizza Name",
"price": 13.99,
"isAvailable": false
}DELETE /api/menu/:id (Protected - Restaurant Owner/Admin)
GET /api/menu/restaurant/:restaurantId
- Returns all menu items for a restaurant
GET /api/orders (Protected - Restaurant Owner)
- Returns all orders for owner's restaurants
PUT /api/orders/:orderId/status (Protected - Restaurant Owner)
{
"status": "accepted" // placed, accepted, rejected, preparing, out_for_delivery, delivered, cancelled
}GET /api/delivery/orders (Protected - Delivery Agent)
- Returns assigned orders for the delivery agent
PUT /api/delivery/orders/:orderId/status (Protected - Delivery Agent)
{
"status": "picked_up" // assigned, picked_up, delivered
}PUT /api/delivery/availability (Protected - Delivery Agent)
{
"isAvailable": true
}GET /api/delivery/history (Protected - Delivery Agent)
- Returns completed deliveries with ratings
GET /api/health (Available on all services)
- Returns service health status
- User places order → Creates order with "placed" status
- Restaurant accepts/rejects → Updates status to "accepted" or "rejected"
- Auto-assignment → When accepted, system assigns available delivery agent
- Restaurant prepares → Updates status to "preparing"
- Delivery pickup → Agent updates to "picked_up", order status becomes "out_for_delivery"
- Delivery complete → Agent updates to "delivered", order status becomes "delivered"
- Agent availability → Agent becomes available again automatically
All endpoints return standardized error responses:
{
"error": "Error message description"
}Common HTTP status codes:
200- Success201- Created400- Bad Request401- Unauthorized403- Forbidden404- Not Found500- Internal Server Error
- User: Can place orders, view restaurants, add ratings
- Restaurant Owner: Can manage restaurants, menu items, and process orders
- Delivery Agent: Can update delivery status and availability
- Admin: Has elevated permissions for system management
placed → accepted → preparing → out_for_delivery → delivered
↘ rejected
assigned → picked_up → delivered
- User registration and authentication
- Multi-role support (customers, restaurant owners, delivery agents)
- Restaurant and menu management
- Order placement and tracking
- Automatic delivery agent assignment
- Real-time order status updates
- Rating and review system
- Delivery history tracking
{
"email": "user1@fooodiii.com",
"password": "StrongP@ssw0rd!"
}
- "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6ImNmYmFhOTY4LTQ5ZTYtNDBiYi05ZDI2LTMxNmEwYzZiZmQwZiIsInJvbGUiOiJ1c2VyIiwiaWF0IjoxNzQ4NTE0NzM5LCJleHAiOjE3NDkxMTk1Mzl9.pLvRJi40dN_WNN4qRrZVXaSZ5L_xERE1fGjPtz2WCAM"
{
"email": "restaurant.owner1@fooodiii.com",
"password": "StrongP@ssw0rd!"
}
- "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6Ijg4MGQ3MDc0LTBkY2QtNDc5Ny1hNjY4LWI5MjlkZGJkMWMzYSIsInJvbGUiOiJyZXN0YXVyYW50X293bmVyIiwiaWF0IjoxNzQ4NTE0NzkyLCJleHAiOjE3NDkxMTk1OTJ9.IqsVNfvZq0keQwPhL12B0CnbR6X08EMmUYBgE2x8Ecs"
{
"email": "delivery_agent1@fooodiii.com",
"password": "StrongP@ssw0rd!"
}
"token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6Ijg1MmYyZWI0LWQyODItNGI3My05YjFiLTY2ZTVmYzQ5ZjkwZCIsInJvbGUiOiJkZWxpdmVyeV9hZ2VudCIsImlhdCI6MTc0ODUxNDY4OCwiZXhwIjoxNzQ5MTE5NDg4fQ.0oQyS1Znw-cjT58IVf2tfaW4YdBK5Af-ocDWWxKJhLY"