A Django-based meal planning system that uses LangChain, OpenAI, and Instacart APIs to generate personalized weekly meal plans and shopping carts based on user preferences. Features secure user authentication with email verification for premium features.
The easiest way to get started is using Docker, which ensures a consistent environment across all machines:
# Clone the repository
git clone <your-repo-url>
cd django-project
# Run the setup script
./scripts/docker-setup.sh
# Start the development environment
make dev-up
# or: ./scripts/docker-commands.sh dev-upAccess the application:
- Django App: http://localhost:8000
- Django Admin: http://localhost:8000/admin/
- pgAdmin (PostgreSQL): http://localhost:8080 ([email protected] / admin)
- Redis Commander: http://localhost:8081
If you prefer to run locally without Docker:
# Create virtual environment
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install -r requirements.txt
# Create .env file with your API keys
cp .env.example .env
# Edit .env with your actual API keys
# Start Redis
brew services start redis
# Run migrations
python manage.py migrate
# Create superuser
python manage.py createsuperuser
# Start Celery worker (in new terminal)
celery -A core worker --loglevel=info
# Start Django server
python manage.py runserverThe system implements a secure authentication flow:
- Open Registration: Anyone can create an account
- Email Verification Required: Users must verify their email to access premium features
- Protected Meal Planning: Only verified users can create meal plans
graph TD
A[User Registration] --> B[Account Created + Email Sent]
B --> C[User Clicks Verification Link]
C --> D[Email Verified]
D --> E[Can Create Meal Plans]
F[Unverified User] --> G[Login Successful]
G --> H[Try to Create Meal Plan]
H --> I[β Email Verification Required]
POST /auth/register/- Register new user (sends verification email)POST /auth/login/- Login userPOST /auth/logout/- Logout userPOST /auth/refresh/- Refresh access token
POST /auth/verify-email/- Verify email with tokenPOST /auth/resend-verification/- Resend verification email
GET /auth/profile/- Get user profilePUT /auth/profile/update/- Update profilePUT /auth/profile/location/- Update location
POST /api/profiles/<profile_id>/trigger-meal-plan/- Create meal planGET /api/email-verification-status/- Check verification status
curl -X POST http://localhost:8000/auth/register/ \
-H "Content-Type: application/json" \
-d '{
"username": "johndoe",
"email": "[email protected]",
"password": "SecurePassword123!"
}'Response:
{
"access_token": "your-access-token",
"refresh_token": "your-refresh-token",
"user": {...},
"email_verification_sent": true,
"message": "Registration successful! Please check your email to verify your account."
}curl -X POST http://localhost:8000/auth/verify-email/ \
-H "Content-Type: application/json" \
-d '{
"token": "verification-token-from-email"
}'curl -X GET http://localhost:8000/api/email-verification-status/ \
-H "Authorization: Token your-access-token"curl -X POST http://localhost:8000/api/profiles/1/trigger-meal-plan/ \
-H "Authorization: Token your-access-token"This project integrates multiple technologies:
- Django: Web framework and API
- Django Rest Framework: API endpoints with authentication
- Email Verification: Custom email verification system
- LangChain: AI/LLM orchestration
- OpenAI: GPT models for meal planning
- Instacart: Shopping cart creation
- Celery: Background task processing
- Redis: Message broker and caching
- PostgreSQL: Database (Docker) / SQLite (local)
# Run all tests (includes authentication flow)
make test
# Run specific test suites
make test-components
make test-integration
make test-instacart
# Test authentication system
make test-auth# Run test scripts
python test_services.py
python test_components.py
python test_integration.py
python test_instacart_api.py
python test_authentication.py # New authentication tests# Test the complete authentication workflow
python test_authentication.py
# Check email verification in development
# (Emails will be printed to console)
docker-compose -f docker-compose.dev.yml logs web | grep "verification"django-project/
βββ api/ # API endpoints (meal planning)
β βββ views.py # Protected meal plan endpoints
β βββ urls.py # API routing
βββ core/ # Django settings and Celery config
β βββ tasks.py # Celery tasks for meal planning
β βββ instacart_client.py # Instacart API client
β βββ settings.py # Django settings + email config
βββ users/ # User authentication and profiles
β βββ models.py # User, Profile, EmailVerification models
β βββ views.py # Auth endpoints with email verification
β βββ serializers.py # API serializers
β βββ urls.py # Auth routing
βββ scripts/ # Docker and utility scripts
βββ logs/ # Application logs
βββ test_*.py # Test scripts (updated for auth flow)
βββ Dockerfile # Docker configuration
βββ docker-compose*.yml # Docker services
βββ Makefile # Easy commands
βββ TESTING_GUIDE.md # Updated testing documentation
# Development
make dev-up # Start development environment
make dev-down # Stop development environment
make dev-logs # View logs
make rebuild # Rebuild containers
# Authentication
make superuser # Create Django superuser
make test-auth # Test authentication flow
# Testing
make test # Run all tests
make test-components # Run component tests
make test-integration # Run integration tests
# Database
make migrate # Run migrations
make shell # Open Django shell
# Meal Plans
make check-meals # Check meal plans
make view-meals # View meal plans
make cleanup # Cleanup failed plans# Django
python manage.py runserver
python manage.py migrate
python manage.py createsuperuser
# Celery
celery -A core worker --loglevel=info
celery -A core beat --loglevel=info
# Testing
python test_components.py
python test_integration.py
python test_authentication.py # New
python check_meal_plans.pyCreate a .env file with the following variables:
# Django Settings
DJANGO_SECRET_KEY=your-secret-key-here
DJANGO_DEBUG=True
DJANGO_ALLOWED_HOSTS=localhost,127.0.0.1,0.0.0.0
# Database (Docker)
DATABASE_URL=postgresql://postgres:postgres@db:5432/meal_planning
# Redis (Docker)
REDIS_URL=redis://redis:6379/0
# API Keys
OPENAI_API_KEY=your-openai-api-key-here
INSTACART_API_KEY=your-instacart-api-key-here
# Email Configuration (Production)
EMAIL_BACKEND=django.core.mail.backends.smtp.EmailBackend
EMAIL_HOST=smtp.gmail.com
EMAIL_PORT=587
EMAIL_USE_TLS=True
EMAIL_HOST_USER=[email protected]
EMAIL_HOST_PASSWORD=your-app-password
DEFAULT_FROM_EMAIL=[email protected]
# Frontend URL (for email verification links)
FRONTEND_URL=http://localhost:3000For development, emails are printed to the console by default. For production, configure SMTP:
-
Gmail Setup:
- Enable 2-factor authentication
- Create an "App Password" in Google Account settings
- Use the app password as
EMAIL_HOST_PASSWORD
-
Other Providers: Update
EMAIL_HOST,EMAIL_PORT, etc. accordingly
- Password Validation: Django's built-in password validators
- Rate Limiting: API throttling on registration, login, and verification
- Token Authentication: Secure access and refresh tokens
- Email Verification: Required for premium features
- User Isolation: Users can only access their own data
- CORS Protection: Configured for frontend integration
- HTTPS Ready: SSL settings for production deployment
The project includes comprehensive test scripts updated for the authentication flow:
test_services.py: Redis and Celery connectivitytest_components.py: Individual component testingtest_integration.py: End-to-end workflow with authtest_instacart_api.py: Instacart API integrationtest_authentication.py: New - Authentication flow testingcheck_meal_plans.py: Database inspectionview_meal_plan.py: Meal plan viewercleanup_failed_plans.py: Cleanup utility
- Testing Guide - Updated with authentication testing
- Docker Setup Guide - Comprehensive Docker documentation
- API Documentation - API endpoints and authentication
-
Email verification not working
- Check console output for development emails
- Verify
FRONTEND_URLis set correctly - Test SMTP settings in production
-
Meal plan creation fails
- Ensure user email is verified:
GET /api/email-verification-status/ - Check authentication token is valid
- Verify user is accessing their own profile
- Ensure user email is verified:
-
Celery not processing tasks
- Check if Redis is running
- Verify Celery worker is started
- Check logs:
make logs-celery
-
API key errors
- Verify
.envfile has correct API keys - Check environment variables are loaded
- Test API keys with curl commands
- Verify
-
Database connection issues
- For Docker: Check if PostgreSQL container is running
- For local: Ensure SQLite file is writable
-
Port conflicts
- Check if ports 8000, 6379, 5432 are available
- Use different ports in docker-compose files
# Check user verification status
docker-compose -f docker-compose.dev.yml exec web python manage.py shell -c "
from django.contrib.auth.models import User
user = User.objects.get(username='your-username')
print(f'Email verified: {user.profile.is_email_verified}')
"
# Manually verify a user (for testing)
docker-compose -f docker-compose.dev.yml exec web python manage.py shell -c "
from users.models import EmailVerification
verification = EmailVerification.objects.get(user__username='your-username')
verification.is_verified = True
verification.save()
print('User manually verified')
"- Check the logs:
make dev-logs - Review the troubleshooting sections in documentation
- Run test scripts to identify issues:
python test_authentication.py - Check service status:
make status - Test authentication endpoints with curl
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests:
make test - Ensure authentication tests pass:
python test_authentication.py - Submit a pull request
This project is licensed under the MIT License.
For detailed testing instructions including authentication flow, see TESTING_GUIDE.md.