Yuga is a modern, production-ready REST API for restaurant and food delivery platforms. Built with Django and Django REST Framework, it provides comprehensive backend services for menu management, user authentication, order processing, and delivery crew management.
The API is designed with enterprise-level security, role-based access control (RBAC), and scalable architecture suitable for multi-restaurant platforms.
- Browse menu items organized by categories
- Search, filter, and sort menu items by price and popularity
- Featured items highlighting
- RESTful CRUD operations for administrators
- Token-based authentication (Django REST Framework Token Auth)
- Role-based access control with user groups:
- Customers - Browse menu, place orders, manage cart
- Managers - Manage menu, approve orders, assign delivery crew
- Delivery Crew - Accept and complete deliveries
- Admin - Full system access
- Add/remove items to cart
- Automatic price calculation
- Per-user cart isolation
- Bulk cart operations (clear all)
- Create orders from cart items
- Order status tracking
- Delivery crew assignment
- Order history and retrieval
- Order-level and item-level tracking
- Django Filter Backend integration
- Search by title and category
- Price range filtering
- Paginated responses for performance
- Custom ordering capabilities
- Role-based permission enforcement
- Request validation and error handling
- Consistent HTTP status codes
- Detailed error messages
| Component | Technology |
|---|---|
| Framework | Django 4.x |
| API Framework | Django REST Framework 3.x |
| Database | PostgreSQL 13+ |
| Authentication | Token Authentication (DRF) |
| Filtering | Django Filter |
| Pagination | PageNumberPagination |
| Python Version | 3.9+ |
yuga/
βββ manage.py # Django management script
βββ requirements.txt # Project dependencies
βββ README.md # This file
β
βββ yuga/ # Main project settings
β βββ settings.py # Django configuration
β βββ urls.py # Root URL routing
β βββ wsgi.py # WSGI application
β βββ asgi.py # ASGI application
β
βββ restaurant/ # Django app (main backend logic)
βββ models.py # Database models (Category, MenuItem, Cart, Order, OrderItem)
βββ views.py # API views and viewsets
βββ serializers.py # Data serialization/deserialization
βββ urls.py # App-specific URL routing
βββ admin.py # Django admin configuration
βββ apps.py # App configuration
βββ tests.py # Unit tests
βββ migrations/ # Database migrations
βββ __pycache__/ # Python cache files
- id (Primary Key)
- slug (String, unique)
- title (String, indexed)- id (Primary Key)
- title (String, indexed)
- price (Decimal, indexed)
- featured (Boolean, indexed)
- category (Foreign Key β Category)- id (Primary Key)
- user (Foreign Key β User)
- menuitem (Foreign Key β MenuItem)
- quantity (SmallInteger)
- unit_price (Decimal)
- price (Decimal)
- Constraint: Unique(menuitem, user)- id (Primary Key)
- user (Foreign Key β User)
- delivery_crew (Foreign Key β User, nullable)
- status (Boolean, indexed)
- total (Decimal)
- date (Date, indexed)- id (Primary Key)
- order (Foreign Key β Order)
- menuitem (Foreign Key β MenuItem)
- quantity (SmallInteger)
- unit_price (Decimal)
- price (Decimal)
- Constraint: Unique(order, menuitem)| Method | Endpoint | Description | Permission |
|---|---|---|---|
| GET | /api/menu-items/ |
List all menu items | Public (read-only) |
| POST | /api/menu-items/ |
Create menu item | Manager/Admin |
| GET | /api/menu-items/{id}/ |
Retrieve menu item | Public |
| PUT | /api/menu-items/{id}/ |
Update menu item | Manager/Admin |
| DELETE | /api/menu-items/{id}/ |
Delete menu item | Manager/Admin |
Filters: ?category=<slug>&fromPrice=<min>&toPrice=<max>&search=<query>&orderBy=<field>
| Method | Endpoint | Description | Permission |
|---|---|---|---|
| GET | /api/category/ |
List all categories | Public |
| POST | /api/category/ |
Create category | Manager/Admin |
| GET | /api/category/{id}/ |
Retrieve category | Public |
| PUT | /api/category/{id}/ |
Update category | Manager/Admin |
| DELETE | /api/category/{id}/ |
Delete category | Manager/Admin |
| Method | Endpoint | Description | Permission |
|---|---|---|---|
| GET | /api/cart/menu-items/ |
View cart | Customer (authenticated) |
| POST | /api/cart/menu-items/ |
Add item to cart | Customer |
| DELETE | /api/cart/menu-items/ |
Clear cart | Customer |
POST Body:
{
"menuitem_id": 5,
"quantity": 2
}Response:
{
"items": [...],
"total_items": 5,
"total_price": 1250.50
}| Method | Endpoint | Description | Permission |
|---|---|---|---|
| GET | /api/orders/ |
List orders | Customer (own), Manager/Admin (all) |
| POST | /api/orders/ |
Create order from cart | Customer |
| GET | /api/orders/{id}/ |
Retrieve order | Customer (own), Manager/Admin (all) |
| DELETE | /api/orders/{id}/ |
Delete order | Manager/Admin |
| Method | Endpoint | Description | Permission |
|---|---|---|---|
| GET | /api/groups/manager/users/ |
List managers | Admin |
| POST | /api/groups/manager/users/ |
Add manager | Admin |
| DELETE | /api/groups/manager/users/{id}/ |
Remove manager | Admin |
| GET | /api/groups/delivery-crew/users/ |
List delivery crew | Admin |
| POST | /api/groups/delivery-crew/users/ |
Add delivery crew | Admin |
| DELETE | /api/groups/delivery-crew/users/{id}/ |
Remove delivery crew | Admin |
Every authenticated request requires the token header:
Authorization: Token <your-token-here>- Browse menu items and categories
- Manage personal cart
- Create and view personal orders
- Cannot manage menu, users, or other orders
- All Customer permissions
- Create, update, delete menu items
- Manage categories
- View all orders
- Assign delivery crew to orders
- Manage customer accounts
- View assigned orders
- Update order status
- Cannot modify menu or orders
- Full system access
- User group management
- Database administration
- All CRUD operations
- Python 3.10+
- PostgreSQL 13+
- Git
- pip or pipenv
git clone https://github.com/your-org/yuga.git
cd yugapython -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install -r requirements.txtCreate a .env file in the project root:
DEBUG=False
SECRET_KEY=your-secret-key-here
DATABASE_URL=postgresql://user:password@localhost:5432/yuga_db
ALLOWED_HOSTS=localhost,127.0.0.1Update settings.py with your PostgreSQL credentials:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'yuga_db',
'USER': 'postgres',
'PASSWORD': 'your-password',
'HOST': 'localhost',
'PORT': '5432',
}
}python manage.py migratepython manage.py createsuperuserpython manage.py shellfrom django.contrib.auth.models import Group
Group.objects.create(name='Customer')
Group.objects.create(name='Manager')
Group.objects.create(name='Delivery')
Group.objects.create(name='Admin')python manage.py loaddata initial_data.jsonpython manage.py runserverAPI will be available at http://localhost:8000/api/
curl -X POST http://localhost:8000/api-token-auth/ \
-H "Content-Type: application/json" \
-d '{"username": "user123", "password": "pass123"}'Response:
{
"token": "abcdef123456789"
}curl -X GET "http://localhost:8000/api/menu-items/?category=pizzas&toPrice=500" \
-H "Authorization: Token abcdef123456789"curl -X POST http://localhost:8000/api/cart/menu-items/ \
-H "Authorization: Token abcdef123456789" \
-H "Content-Type: application/json" \
-d '{
"menuitem_id": 5,
"quantity": 2
}'curl -X POST http://localhost:8000/api/orders/ \
-H "Authorization: Token abcdef123456789" \
-H "Content-Type: application/json" \
-d '{}'curl -X PATCH http://localhost:8000/api/orders/10/ \
-H "Authorization: Token abcdef123456789" \
-H "Content-Type: application/json" \
-d '{"delivery_crew": 15}'python manage.py testpython manage.py test restaurantpip install coverage
coverage run --source='.' manage.py test
coverage report
coverage html # Generate HTML reportβ
DRF Generics & ViewSets - Reusable, maintainable views
β
Django Filters - Advanced filtering without custom code
β
Pagination - Efficient data handling
β
Permission Classes - DjangoModelPermissions, DjangoModelPermissionsOrAnonReadOnly
β
Serializer Validation - Field-level and object-level validation
β
Database Constraints - Unique constraints at model level
β
Query Optimization - select_related() for foreign keys
β
Comprehensive Error Handling - Meaningful HTTP status codes
β
API Documentation - Browsable API interface (with DRF)
- Database indexing on frequently queried fields
- Query optimization with
select_related() - Pagination for large datasets
- Efficient serializer design
Core dependencies (see requirements.txt):
Django==4.2.x
djangorestframework==3.14.x
django-filter==23.x
psycopg2-binary==2.9.x
python-decouple==3.x
gunicorn==20.x
pip install gunicorn
gunicorn yuga.wsgi --bind 0.0.0.0:8000FROM python:3.9
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
CMD ["gunicorn", "yuga.wsgi:application", "--bind", "0.0.0.0:8000"]DEBUG=False
SECRET_KEY=<generate-strong-key>
ALLOWED_HOSTS=yourdomain.com,www.yourdomain.com
DATABASE_URL=postgresql://user:password@prod-db:5432/yuga_prodTo enable interactive API docs, install:
pip install drf-spectacularAdd to INSTALLED_APPS:
'drf_spectacular',Access at: http://localhost:8000/api/schema/swagger/
This project is licensed under the MIT License - see the LICENSE file for details.
- Django Documentation
- Django REST Framework Guide
- PostgreSQL Docs
- Best Practices for RESTful APIs
- Django Security
β
HTTPS Only - Always use HTTPS in production
β
CSRF Protection - Enabled by default
β
SQL Injection Prevention - Using Django ORM
β
XSS Protection - DRF serializers escape output
β
Rate Limiting - Implement via Throttle classes (TODO)
β
API Key Rotation - Token-based auth with expiry (TODO)
- Advanced order tracking with real-time updates
- Payment gateway integration (Stripe/PayPal)
- Push notifications for customers
- Rating & review system
- Analytics dashboard
- Multi-language support
- GraphQL API endpoint
- Mobile app API optimization
Last Updated: December 2025
Version: 1.0.0
Status: Dev Ready