A complete backend system for food ordering with database management and Stripe payment integration.
- User Authentication - JWT-based authentication with role-based access control (admin/customer)
- Menu Management - Full CRUD operations for menu items with categories and filters
- Order Management - Complete order lifecycle from creation to delivery
- Stripe Payment Integration - Secure payment processing with webhooks
- Database - MongoDB for data persistence
- RESTful API - Clean and well-documented API endpoints
- Validation - Input validation and error handling
- Security - Password hashing, JWT tokens, and secure payment handling
- Node.js - Runtime environment
- Express.js - Web framework
- MongoDB - NoSQL database
- Mongoose - MongoDB ODM
- Stripe - Payment processing
- JWT - Authentication
- bcryptjs - Password hashing
- express-validator - Input validation
Before you begin, ensure you have the following installed:
- Node.js (v14 or higher)
- MongoDB (v4.4 or higher)
- npm or yarn
- Stripe account (for payment integration)
- Clone the repository:
git clone <repository-url>
cd A386-Restro- Install dependencies:
npm install- Set up environment variables:
Create a .env file in the root directory:
cp .env.example .envEdit the .env file with your configuration:
# Server Configuration
PORT=5000
NODE_ENV=development
# MongoDB Configuration
MONGODB_URI=mongodb://localhost:27017/a386-restro
# JWT Secret (generate a strong random string)
JWT_SECRET=your_jwt_secret_key_here_make_it_very_long_and_random
# Stripe Configuration
STRIPE_SECRET_KEY=sk_test_your_stripe_secret_key
STRIPE_PUBLISHABLE_KEY=pk_test_your_stripe_publishable_key
STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret
# Frontend URL (for CORS)
FRONTEND_URL=http://localhost:3000- Start MongoDB:
Make sure MongoDB is running on your system:
# On macOS with Homebrew
brew services start mongodb-community
# On Linux
sudo systemctl start mongod
# On Windows
# Start MongoDB from Services or run mongod.exe- Seed the database (optional but recommended):
npm run seedThis will create:
- Admin user:
admin@a386restro.com/admin123 - Test customer:
john@example.com/password123 - 15 sample menu items across all categories
- Start the server:
Development mode with auto-reload:
npm run devProduction mode:
npm startThe server will start on http://localhost:5000
-
Create a Stripe account at https://stripe.com
-
Get your API keys:
- Go to Stripe Dashboard → Developers → API keys
- Copy your Publishable key and Secret key
- Add them to your
.envfile
-
Set up webhooks (for production):
- Go to Stripe Dashboard → Developers → Webhooks
- Add endpoint:
https://your-domain.com/api/payments/webhook - Select events:
payment_intent.succeeded,payment_intent.payment_failed,charge.refunded - Copy the webhook signing secret to your
.envfile
-
Test webhook locally (optional):
# Install Stripe CLI
brew install stripe/stripe-cli/stripe
# Login to Stripe
stripe login
# Forward webhooks to local server
stripe listen --forward-to localhost:5000/api/payments/webhookComplete API documentation is available in API_DOCUMENTATION.md
Test if the server is running:
curl http://localhost:5000/api/healthExpected response:
{
"status": "ok",
"message": "A386 Restro Backend is running",
"timestamp": "2025-01-15T18:30:00.000Z"
}POST /api/auth/register- Register new userPOST /api/auth/login- Login userGET /api/auth/me- Get current userPUT /api/auth/profile- Update profile
GET /api/menu- Get all menu itemsGET /api/menu/:id- Get single menu itemPOST /api/menu- Create menu item (admin)PUT /api/menu/:id- Update menu item (admin)DELETE /api/menu/:id- Delete menu item (admin)
GET /api/orders- Get ordersGET /api/orders/:id- Get single orderPOST /api/orders- Create new orderPUT /api/orders/:id/status- Update order status (admin)DELETE /api/orders/:id- Cancel order
POST /api/payments/create-payment-intent- Create Stripe paymentPOST /api/payments/webhook- Stripe webhook handlerPOST /api/payments/refund- Process refund (admin)GET /api/payments/config- Get Stripe public key
A386-Restro/
├── models/ # Database models
│ ├── User.js # User model with authentication
│ ├── MenuItem.js # Menu item model
│ └── Order.js # Order model
├── routes/ # API routes
│ ├── auth.js # Authentication routes
│ ├── menu.js # Menu routes
│ ├── orders.js # Order routes
│ └── payments.js # Payment routes
├── middleware/ # Custom middleware
│ └── auth.js # Authentication middleware
├── seeders/ # Database seeders
│ └── seed.js # Seed script for sample data
├── server.js # Main application file
├── package.json # Dependencies and scripts
├── .env.example # Environment variables template
├── .gitignore # Git ignore file
├── README.md # This file
└── API_DOCUMENTATION.md # Complete API docs
- name, email, password (hashed)
- phone, address
- role (customer/admin)
- timestamps
- name, description, price
- category (appetizer, main-course, dessert, beverage, special)
- image, ingredients, allergens
- dietary flags (vegetarian, vegan, gluten-free)
- availability status
- rating system
- order number (auto-generated)
- user reference
- items with quantities and prices
- pricing breakdown (subtotal, tax, delivery fee, total)
- status tracking (pending → confirmed → preparing → ready → out-for-delivery → delivered)
- payment status (pending → processing → completed)
- delivery address and customer info
- Stripe payment intent ID
- timestamps
- Customer creates order - POST /api/orders
- Order created with "pending" status
- Customer creates payment intent - POST /api/payments/create-payment-intent
- Customer completes payment (frontend with Stripe.js)
- Stripe webhook confirms payment
- Order status automatically updated to "confirmed"
- Admin updates status through the order lifecycle
- Order delivered - Status: "delivered"
- Create order through API
- Get payment intent with client secret
- Use Stripe.js on frontend to collect payment
- Webhook automatically updates order status
- Customer receives confirmation
- Password hashing with bcryptjs
- JWT token authentication
- Role-based access control
- Input validation and sanitization
- Stripe webhook signature verification
- CORS configuration
- Environment variable protection
- Mongoose schema validation
Admin Account:
- Email:
admin@a386restro.com - Password:
admin123 - Can manage menu items and view all orders
Customer Account:
- Email:
john@example.com - Password:
password123 - Can place orders and view own orders
- Import the API endpoints into Postman
- Set up environment variables for base URL and token
- Test the authentication flow
- Create orders and process payments
Use these test cards for payment testing:
- Success:
4242 4242 4242 4242 - Declined:
4000 0000 0000 0002 - Requires authentication:
4000 0025 0000 3155
Use any future expiry date, any 3-digit CVC, and any postal code.
Ensure all production environment variables are set:
- Use strong, random JWT_SECRET
- Use production Stripe keys
- Set NODE_ENV=production
- Configure production MongoDB URI
- Set proper FRONTEND_URL for CORS
- Backend: Heroku, Railway, Render, DigitalOcean
- Database: MongoDB Atlas (free tier available)
- Domain: Configure custom domain with SSL
- Set all environment variables
- Configure MongoDB Atlas
- Set up Stripe webhook endpoint
- Enable HTTPS
- Configure CORS for production frontend
- Set up error logging (e.g., Sentry)
- Implement rate limiting
- Set up database backups
- Monitor server health
- Configure auto-scaling if needed
- Ensure MongoDB is running
- Check MongoDB URI in .env
- Verify network connectivity
- Verify Stripe keys are correct
- Check webhook is configured
- Ensure using test mode for development
- Check JWT_SECRET is set
- Verify token is being sent in headers
- Check token hasn't expired (30 days)
- Check FRONTEND_URL in .env
- Verify CORS middleware configuration
- Ensure proper headers on frontend
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
For issues and questions:
- Check API_DOCUMENTATION.md
- Review common issues above
- Create an issue on GitHub
ISC
A386 Restro Development Team
After setup, you can:
- ✅ Test API endpoints with Postman or cURL
- ✅ Build a frontend application (React, Vue, etc.)
- ✅ Integrate Stripe.js for payment collection
- ✅ Add more features (reviews, favorites, recommendations)
- ✅ Implement real-time order tracking with WebSockets
- ✅ Add email notifications
- ✅ Create admin dashboard
- ✅ Deploy to production
Happy coding! 🚀