The backend for Bytes.AI, an intelligent recipe management application that blends creative AI with smart grocery list management. Built with Django, powered by OpenAI GPT-4o-mini, secured with JWT authentication, and deployed on Railway.
The Bytes.AI backend provides the core API and business logic for the app. It handles:
- AI-powered recipe generation using OpenAI's GPT-4o-mini with dietary tag enforcement and unit normalization
- Secure image storage via AWS S3 with presigned URLs and automatic cleanup
- Intelligent grocery list management with unit conversion, item merging, and recipe-to-list import
- Comprehensive user authentication including JWT tokens, password reset via SendGrid email, and profile management
- Full recipe CRUD operations with nested ingredients and steps
- RESTful API design with 22 functional endpoints serving the React frontend
This service powers all frontend interactions, exposing RESTful endpoints and managing authentication, data persistence, and external integrations.
| Technology | Purpose |
|---|---|
| Django 4.2.25 | Core backend framework |
| Django REST Framework 3.16.1 | REST API serialization and routing |
| Simple JWT 5.5.1 | JSON Web Token authentication |
| OpenAI API (GPT-4o-mini) | AI recipe generation with dietary constraints |
| AWS S3 (boto3) | Cloud image storage with presigned URLs |
| SendGrid | Email delivery for password resets |
| PostgreSQL | Production database (Railway) |
| WhiteNoise | Static file serving |
| Gunicorn | Production WSGI server |
| Railway | Cloud deployment and hosting |
- OpenAI GPT-4o-mini integration for intelligent recipe creation
- Prompt-based generation - Describe what you want to cook and let AI create the recipe
- Dietary tag enforcement - Automatically enforces restrictions (vegan, gluten-free, no nuts, etc.)
- Grocery list incorporation - Generate recipes using checked items from your grocery list
- Unit normalization - Ensures all ingredients use standardized measurements
- Automatic allergen detection - AI identifies and tags common allergens
- Detailed instructions - Includes cooking times, temperatures, and visual cues
- Nutrition information - AI-generated macro and nutrition details in notes
- Recipe-to-list import - Add all recipe ingredients to your grocery list with one click
- Smart item merging - Automatically combines quantities of duplicate items with compatible units
- Unit conversion - Converts between compatible measurements (tsp โ tbsp โ cup, g โ kg โ oz โ lb)
- Check/uncheck tracking - Mark items as purchased or needed
- Bulk operations - Clear all checked items at once
- Manual item entry - Add individual items with custom quantities and units
- Intelligent updates - Adding more of an item unchecks it for re-purchase
- Full CRUD operations - Create, read, update, and delete recipes
- Image upload - Store recipe photos in AWS S3 with automatic cleanup
- Nested data - Manage ingredients and cooking steps as structured data
- Favorite marking - Tag favorite recipes for quick access
- Dietary tags - JSON-based tag system for allergens and dietary preferences
- User-scoped access - Users only see their own recipes (data isolation)
- JWT-based authentication - Secure, stateless token authentication
- Token refresh - Automatic session extension without re-login
- Password reset via email - SendGrid-powered password recovery with 1-hour token expiry
- Profile updates - Change username, email, or password
- Account deletion - Complete data removal with cascade delete
- Custom password validation - Enforces uppercase, lowercase, number, and special character requirements
- AWS S3 storage - Scalable, production-grade cloud storage
- UUID-based filenames - Prevents collisions and overwrites
- User-specific folders - Organized by
recipes/user_{id}/ - Presigned URLs - Secure, temporary access to private images
- Automatic deletion - Removes old images when recipes are updated or deleted
- MultiPart form support - Handle image uploads with JSON data
- Fields: title, notes, favorite, image, tags (JSON)
- Relationships: One-to-Many with Ingredient and Step
- Features: Custom S3 upload paths, JSON dietary tags
- Fields: name, quantity, volume_unit, weight_unit
- Validation: Only one unit type (volume OR weight) per ingredient
- Supported Units:
- Volume: tsp, tbsp, fl_oz, cup, pt, qt, gal, ml, l
- Weight: g, kg, oz, lb
- Fields: step (number), description
- Purpose: Ordered cooking instructions for recipes
- Fields: name, quantity, volume_unit, weight_unit, checked, created_at
- Features: Unit conversion, duplicate merging, check/uncheck status
| Method | Endpoint | Description |
|---|---|---|
| POST | /users/sign-up/ |
Register new user with JWT tokens |
| POST | /users/sign-in/ |
Login and receive access/refresh tokens |
| GET | /users/verify/ |
Verify current JWT token |
| POST | /users/token/refresh/ |
Refresh access token |
| POST | /users/password-reset/ |
Request password reset email |
| POST | /users/password-reset-confirm/ |
Confirm password reset with token |
| Method | Endpoint | Description |
|---|---|---|
| PATCH | /users/update-username/ |
Update username (min 3 chars, unique) |
| PATCH | /users/update-email/ |
Update email with validation |
| PATCH | /users/update-password/ |
Change password (requires current password) |
| DELETE | /users/delete-account/ |
Delete account with cascade |
| Method | Endpoint | Description |
|---|---|---|
| GET/POST | /recipes/ |
List user's recipes / Create new recipe |
| GET/PUT/PATCH/DELETE | /recipes/<id>/ |
Retrieve, update, or delete recipe |
| GET/POST | /recipes/<recipe_id>/ingredients/ |
List/add ingredients |
| GET/PUT/PATCH/DELETE | /recipes/<recipe_id>/ingredients/<id>/ |
Ingredient CRUD |
| GET/POST | /recipes/<recipe_id>/steps/ |
List/add cooking steps |
| GET/PUT/PATCH/DELETE | /recipes/<recipe_id>/steps/<id>/ |
Step CRUD |
| POST | /recipes/generate/ |
AI recipe generation |
| Method | Endpoint | Description |
|---|---|---|
| GET | /grocery-list/ |
List all grocery items |
| POST | /grocery-list/add-item/ |
Add single item with smart merging |
| POST | /grocery-list/add-recipe/<recipe_id>/ |
Import recipe ingredients |
| PATCH | /grocery-list/item/<item_id>/ |
Update item (check/uncheck) |
| DELETE | /grocery-list/clear-checked/ |
Bulk delete checked items |
- Access Token: Short-lived token for API requests (sent in Authorization header)
- Refresh Token: Long-lived token to obtain new access tokens
- Token Verification:
/users/verify/endpoint for session persistence - Stateless: No server-side session storage required
- Custom Validators:
- Minimum 8 characters
- At least one uppercase letter
- At least one lowercase letter
- At least one number
- At least one special character (
!@#$%^&*(),.?":{}|<>)
- Django Built-in Validators:
- UserAttributeSimilarityValidator
- CommonPasswordValidator
- All queries filtered by
request.user - Users cannot access other users' recipes, ingredients, steps, or grocery lists
- Authorization enforced at view level with
permissions.IsAuthenticated
- Allowed Origins:
http://localhost:5173(development)https://bytesai.netlify.app(production)
- CSRF Trusted Origins:
- Railway backend
- Netlify frontend
Ensure you have the following installed:
- Python 3.10+
- pip and pipenv
- PostgreSQL (optional - SQLite used by default in development)
You'll also need API keys for:
- OpenAI - For AI recipe generation
- AWS S3 - For image storage (Access Key ID, Secret Access Key, Bucket Name)
- SendGrid - For password reset emails (optional in development)
# 1๏ธโฃ Clone the repository
git clone https://github.com/saramattina/bytes-backend
cd bytes-backend
# 2๏ธโฃ Activate the Pipenv shell
pipenv shell
# 3๏ธโฃ Install dependencies
pipenv install
# 4๏ธโฃ Create your .env file
touch .envEnvironment Variables (.env):
# Django Settings
DJANGO_ENV=development
SECRET_KEY=your-secret-key-here
DEBUG=True
# OpenAI (Required for AI recipe generation)
OPENAI_API_KEY=your-openai-api-key
# AWS S3 (Required for image uploads)
AWS_ACCESS_KEY_ID=your-aws-access-key-id
AWS_SECRET_ACCESS_KEY=your-aws-secret-access-key
AWS_STORAGE_BUCKET_NAME=your-bucket-name
AWS_S3_REGION_NAME=us-east-1
# SendGrid (Optional - email will print to console in development)
SENDGRID_API_KEY=your-sendgrid-api-key
# Frontend URL (for password reset links)
FRONTEND_URL=http://localhost:5173
# Email Settings (Development - optional)
EMAIL_BACKEND=django.core.mail.backends.console.EmailBackend
DEFAULT_FROM_EMAIL=noreply@bytesai.com
# Database (Optional - defaults to SQLite)
# DATABASE_URL=postgresql://user:password@localhost:5432/dbname# 5๏ธโฃ Apply database migrations
python manage.py migrate
# 6๏ธโฃ Create a superuser (optional - for Django admin)
python manage.py createsuperuser
# 7๏ธโฃ Run the development server
python manage.py runserverDevelopment server will run at: http://127.0.0.1:8000/
Django admin available at: http://127.0.0.1:8000/admin/
The app is deployed on Railway with the following production settings:
- Database: PostgreSQL (via DATABASE_URL)
- Static Files: Served by WhiteNoise
- WSGI Server: Gunicorn
- Email Backend: SendGrid API (SMTP ports blocked on Railway)
Production Environment Variables:
DJANGO_ENV=production
DEBUG=False
SECRET_KEY=<generated-secret-key>
DATABASE_URL=<railway-postgres-url>
ALLOWED_HOSTS=bytes-backend-production.up.railway.app- Push code to GitHub repository
- Connect Railway to GitHub repo
- Configure environment variables in Railway dashboard
- Railway auto-deploys on push to main branch
- Run migrations:
python manage.py migrate
bytes-backend/
โโโ main_app/ # Main Django application
โ โโโ migrations/ # Database migrations
โ โโโ models.py # Recipe, Ingredient, Step, GroceryListItem models
โ โโโ serializers.py # DRF serializers with custom validation
โ โโโ views.py # API views and OpenAI integration
โ โโโ urls.py # App-level URL routing
โ โโโ validators.py # Custom password validators
โ โโโ admin.py # Django admin configuration
โโโ recipecollector/ # Django project settings
โ โโโ settings.py # Main configuration file
โ โโโ urls.py # Root URL routing
โ โโโ wsgi.py # WSGI application entry point
โ โโโ sendgrid_backend.py # Custom SendGrid email backend
โโโ manage.py # Django management script
โโโ Pipfile # Python dependencies (pipenv)
โโโ Pipfile.lock # Locked dependency versions
โโโ requirements.txt # Pip requirements (for Railway)
โโโ start.sh # Production startup script
โโโ db.sqlite3 # SQLite database (development)
โโโ README.md # This file
- User sends prompt + optional dietary tags + optional grocery list flag
- Backend constructs OpenAI system prompt with dietary constraints
- If grocery list requested, includes checked items in prompt
- OpenAI GPT-4o-mini generates structured JSON response
- Backend normalizes units and validates structure
- Returns recipe preview to frontend for user approval
- User can save, edit, or regenerate
- User adds item (manually or from recipe)
- Backend checks for existing item with same name
- If found, determines measurement type (volume/weight/count)
- Converts units to common base (ml for volume, g for weight)
- Combines quantities and converts back to appropriate unit
- Updates existing item or creates new one
- Frontend sends multipart form data (image + JSON)
- Serializer extracts and validates image
- Custom upload path function generates unique S3 key:
recipes/user_{id}/{uuid}.{ext} - Boto3 uploads to S3 with cache headers
- On retrieval, serializer generates presigned URL (24hr expiry)
- On update/delete, old image automatically removed from S3
- User requests reset with email address
- Backend generates UID + token (1hr expiry)
- SendGrid sends email with reset link:
{FRONTEND_URL}/reset-password?uid={uid}&token={token} - User clicks link, enters new password
- Frontend sends UID, token, new password to confirm endpoint
- Backend validates token, updates password
- User can log in with new password
The Bytes.AI Backend is the engine that powers a smarter way to cook โ blending creativity, collaboration, and AI (At this day and age, what doesn't). This project reflects our shared goal of building technology that feels helpful, elegant, and human. From scalable Django architecture to AI-driven recipe generation, every component was crafted with care, curiosity, and hunger.
Potential next steps to expand Bytes.AI:
- External MCP Server - Implement a dedicated Model Context Protocol server for enhanced AI capabilities
- Recipe Scaling - Automatically adjust ingredient quantities for different serving sizes
- Meal Planning - Weekly meal planner with automatic grocery list generation
- Nutrition Tracking - Detailed macro and calorie tracking per recipe and meal
- Social Features - Share recipes with friends, public recipe discovery
- Recipe Import - Parse recipes from URLs or images using OCR
- Shopping List Categorization - Group items by store section (produce, dairy, etc.)
- Voice Commands - Hands-free cooking mode with step-by-step voice guidance
- Recipe Rating & Reviews - Community feedback system
- Multi-language Support - Internationalization for global users
| Name | Role |
|---|---|
| Daniel Amit | Project Manager ยท Full-Stack & AI Engineer |
| Sara Mattina | Back-End Engineer ยท Repository Owner |
| Dylan Tai | Front-End Engineer ยท Repository Owner |
๐ก Team Bytes.AI โ fueled by innovation, caffeine, and clean commits.
