REST API backend for the NutriAI mobile application, providing restaurant data, dish information, and AI-powered nutrition estimation for 926,000+ dishes across 9,249 restaurants in the UAE.
- 🍽️ Restaurant Management - Browse and search 9,249+ restaurants
- 🥗 Dish Database - Access 926,396 dishes with detailed information
- 🤖 AI Nutrition Estimation - Groq AI-powered nutrition data estimation
- 📍 Geolocation - Find nearby restaurants using Haversine formula
- 🔍 Advanced Search - Filter by cuisine, category, rating, and more
- 📊 Pagination - Efficient data loading with configurable limits
- 🌍 CORS Enabled - Ready for mobile app integration
- Node.js - Runtime environment
- Express.js - Web framework
- MySQL - Database (nutriai_scraped)
- Axios - HTTP client for Groq AI
- dotenv - Environment configuration
- CORS - Cross-origin resource sharing
See API_DOCUMENTATION.md for complete API reference.
Quick overview:
GET /api/v1/restaurants- List restaurants with paginationGET /api/v1/restaurants/nearby- Find restaurants by locationGET /api/v1/restaurants/:id- Get restaurant detailsGET /api/v1/restaurants/:id/menu- Get restaurant menuGET /api/v1/dishes/search- Search dishesGET /api/v1/dishes/:id- Get dish detailsGET /api/v1/dishes/:id/nutrition- Get nutrition data (with AI estimation)
See DATABASE.md for complete database schema documentation.
The API uses the nutriai_scraped database with 5 main tables:
restaurants- Restaurant information (9,249 records)dishes- Dish information (926,396 records)locations- Geographic datarestaurant_stats- Performance metricsimport_log- Data import tracking
- Node.js 18.x or higher
- MySQL 8.x or higher
- npm or yarn
git clone https://github.com/warl0ck769/nutriai-api.git
cd nutriai-apinpm installCreate a .env file:
# Database Configuration
DB_HOST=your_mysql_host
DB_PORT=3306
DB_USER=your_mysql_user
DB_PASSWORD=your_mysql_password
DB_NAME=nutriai_scraped
# Server Configuration
PORT=3001
NODE_ENV=development
# Groq AI Configuration
GROQ_API_KEY=your_groq_api_key
# CORS Configuration
ALLOWED_ORIGINS=http://localhost:*,https://localhost:*# Development
npm start
# Production
npm run start:prodServer will start on http://localhost:3001
curl http://localhost:3001/api/v1/restaurants?limit=10{
"success": true,
"data": [...],
"pagination": {
"total": 9249,
"limit": 10,
"offset": 0,
"has_more": true
}
}nutriai-api/
├── src/
│ ├── config/
│ │ └── database.js # MySQL connection config
│ ├── controllers/
│ │ ├── restaurantController.js # Restaurant endpoints
│ │ └── dishController.js # Dish endpoints
│ ├── routes/
│ │ ├── restaurantRoutes.js # Restaurant routes
│ │ └── dishRoutes.js # Dish routes
│ ├── services/
│ │ └── nutritionService.js # Groq AI integration
│ ├── middleware/
│ │ └── cors.js # CORS configuration
│ └── server.js # Main server file
├── .env # Environment variables
├── package.json # Dependencies
└── README.md # This file
npm run dev# Test health check
curl http://localhost:3001/health
# Test restaurant endpoint
curl http://localhost:3001/api/v1/restaurants?limit=5
# Test nearby restaurants
curl "http://localhost:3001/api/v1/restaurants/nearby?lat=25.2048&lng=55.2708&radius=5"
# Test dish search
curl "http://localhost:3001/api/v1/dishes/search?q=chicken&limit=10"API returns standardized error responses:
{
"success": false,
"error": "Error message description"
}Common HTTP status codes:
200- Success400- Bad Request404- Not Found500- Internal Server Error
- Connection Pooling - Efficient MySQL connections
- Pagination - Default 20 items per request
- Index Optimization - Database indexes on key columns
- Lazy Loading - Load data on demand
- Caching - Future implementation planned
- Environment variables for sensitive data
- CORS configuration for allowed origins
- Input validation and sanitization
- SQL injection prevention with parameterized queries
- Rate limiting (future implementation)
npm install --production
NODE_ENV=production npm startFROM node:18-alpine
WORKDIR /app
COPY package*.json ./
RUN npm install --production
COPY . .
EXPOSE 3001
CMD ["npm", "start"]- AWS EC2 - Traditional deployment
- Heroku - Easy deployment with MySQL addon
- DigitalOcean - App Platform or Droplet
- Railway - Automatic deployments
| Variable | Description | Required |
|---|---|---|
DB_HOST |
MySQL host address | Yes |
DB_PORT |
MySQL port (default: 3306) | Yes |
DB_USER |
MySQL username | Yes |
DB_PASSWORD |
MySQL password | Yes |
DB_NAME |
Database name (nutriai_scraped) | Yes |
PORT |
API server port (default: 3001) | No |
NODE_ENV |
Environment (development/production) | No |
GROQ_API_KEY |
Groq AI API key | Yes for nutrition estimation |
ALLOWED_ORIGINS |
CORS allowed origins | No |
Currently no rate limiting implemented. Recommended for production:
- 100 requests per minute per IP
- 1000 requests per hour per IP
- Fork the repository
- Create feature branch (
git checkout -b feature/AmazingFeature) - Commit changes (
git commit -m 'Add AmazingFeature') - Push to branch (
git push origin feature/AmazingFeature) - Open Pull Request
# Test MySQL connection
mysql -h your_host -u your_user -p nutriai_scraped
# Check if database exists
SHOW DATABASES;
USE nutriai_scraped;
SHOW TABLES;# Find process using port 3001
lsof -i :3001
# Kill process
kill -9 <PID># Reinstall dependencies
rm -rf node_modules package-lock.json
npm installRecommended tools:
- PM2 - Process management
- Morgan - HTTP request logging
- Winston - Application logging
- New Relic - Performance monitoring
- Add authentication and authorization
- Implement API rate limiting
- Add caching layer (Redis)
- WebSocket support for real-time updates
- GraphQL API option
- API versioning strategy
- Comprehensive test suite
- API analytics and monitoring
- Swagger/OpenAPI documentation
- Docker compose setup
- Mobile App: https://github.com/warl0ck769/nutriai-app
- API Documentation: API_DOCUMENTATION.md
- Database Schema: DATABASE.md
- Report Issues: GitHub Issues
This project is licensed under the MIT License.
For support, email rahulvashista98@gmail.com or open an issue on GitHub.
Made with ❤️ using Node.js and Express
🤖 Generated with Claude Code