A production-ready Django application with PostgreSQL, JWT authentication (SimpleJWT), Celery for background tasks, and RAG (Retrieval Augmented Generation) capabilities using Google Cloud Storage and Qdrant vector database.
- ✅ JWT Authentication - Secure authentication using djangorestframework-simplejwt
- ✅ PostgreSQL Database - Robust data persistence with Django ORM
- ✅ GCS Presigned URLs - Direct client-to-GCS uploads (no server bandwidth)
- ✅ Celery Background Tasks - Async document processing and RAG response generation
- ✅ Django REST Framework - RESTful API with ModelViewSets
- ✅ Multi-tenant Architecture - Organization-based data isolation
- ✅ Docker Compose - Complete orchestration of all services
- ✅ RAG System Integration - Vector embeddings and semantic search with Qdrant
┌──────────────┐ ┌──────────────┐ ┌──────────────┐
│ Django App │ ═══> │ GCP Storage │ ═══> │ Celery │
│ (REST API) │ │ (Documents) │ │ Worker │
└──────────────┘ └──────────────┘ └──────────────┘
│ │ │
│ │ │
└────────────────────────┴─────────────────────────┘
│
┌──────────▼──────────┐
│ PostgreSQL DB │
│ (Shared State) │
└─────────────────────┘
│
┌──────────▼──────────┐
│ Qdrant Vector │
│ Database │
└─────────────────────┘
advanced-rag/
├── config/ # Django project configuration
├── users/ # User authentication app
├── documents/ # Document management app
├── chats/ # Chat and RAG app
├── common/ # Shared utilities (Qdrant client)
├── manage.py # Django management script
├── requirements.txt # Python dependencies
├── docker-compose.yml # Docker orchestration
├── Makefile # Convenience commands
└── .env.example # Environment template
- Python 3.12+
- PostgreSQL
- Redis
- Docker & Docker Compose (recommended)
- GCP account with Cloud Storage enabled
- Qdrant (optional, included in docker-compose)
# Copy environment template
cp .env.example .env
# Edit .env with your configuration
nano .envRequired environment variables:
SECRET_KEY=your-secret-key
DB_NAME=advanced_rag
DB_USER=postgres
DB_PASSWORD=password
DB_HOST=localhost
DB_PORT=5432
GCS_BUCKET_NAME=your-bucket-name
GCS_PROJECT_ID=your-project-id
GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials.json
CELERY_BROKER_URL=redis://localhost:6379/0# Start all services
docker-compose up -d
# Run migrations
docker-compose exec web python3 manage.py migrate
# Create superuser
docker-compose exec web python3 manage.py createsuperuser
# View logs
docker-compose logs -fServices will start on:
- Django API: http://localhost:8000
- Admin: http://localhost:8000/admin/
- PostgreSQL: localhost:5432
- Redis: localhost:6379
- Qdrant: http://localhost:6333
# Install dependencies
make install
# Run migrations
make makemigrations
make migrate
# Create superuser
make superuser
# Start services in separate terminals:
# Terminal 1: Django server
make run
# Terminal 2: Celery worker
make celery
# Terminal 3: Celery beat (optional)
make celery-beatPOST /api/auth/users/- Register new userPOST /api/auth/login/- Login and get JWT tokenPOST /api/auth/token/refresh/- Refresh JWT tokenGET /api/auth/users/me/- Get current user infoPUT /api/auth/users/me/profile/- Update user profile
GET /api/documents/- List user documentsPOST /api/documents/presign-upload/- Get presigned upload URLPOST /api/documents/{id}/process/- Trigger document processingGET /api/documents/{id}/download/- Get presigned download URLDELETE /api/documents/{id}/- Delete document
GET /api/chats/chats/- List user chatsPOST /api/chats/chats/- Create new chatPOST /api/chats/chats/{id}/messages/send/- Send message and get RAG responseDELETE /api/chats/chats/{id}/- Delete chat
curl -X POST http://localhost:8000/api/auth/users/ \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"password": "securepassword123",
"password_confirm": "securepassword123"
}'curl -X POST http://localhost:8000/api/auth/login/ \
-H "Content-Type: application/json" \
-d '{
"email": "[email protected]",
"password": "securepassword123"
}'TOKEN="your-jwt-token"
curl -X POST http://localhost:8000/api/documents/presign-upload/ \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"filename": "document.pdf",
"file_type": "application/pdf",
"file_size": 1024000
}'# Use the presigned URL from the previous response
curl -X PUT "$PRESIGNED_URL" \
-H "Content-Type: application/pdf" \
--data-binary @document.pdfcurl -X POST http://localhost:8000/api/documents/{id}/process/ \
-H "Authorization: Bearer $TOKEN"curl -X POST http://localhost:8000/api/chats/chats/{id}/messages/send/ \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"content": "What is the main topic of the document?"
}'# Database
make migrate # Run migrations
make makemigrations # Create migrations
make db-reset # Reset database
# Server
make run # Start Django server
make celery # Start Celery worker
make celery-beat # Start Celery beat
# Docker
make docker-up # Start all services
make docker-down # Stop all services
make docker-logs # View logs
make docker-rebuild # Rebuild and start
# Cleanup
make clean # Remove Python cache files
# Testing
make test # Run tests- JWT token-based authentication with SimpleJWT
- Django's built-in password hashing
- Environment-based secrets management
- Multi-tenant data isolation (organization-based)
- CORS configuration
- SQL injection protection via Django ORM
- Presigned URLs for secure file uploads/downloads
# 1. Register user
TOKEN=$(curl -X POST http://localhost:8000/api/auth/users/ \
-H "Content-Type: application/json" \
-d '{"email":"[email protected]","password":"test123","password_confirm":"test123"}' \
| jq -r '.access')
# 2. Request presigned URL
RESPONSE=$(curl -X POST http://localhost:8000/api/documents/presign-upload/ \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"filename":"test.pdf","file_type":"application/pdf"}')
UPLOAD_URL=$(echo $RESPONSE | jq -r '.upload_url')
DOC_ID=$(echo $RESPONSE | jq -r '.document_id')
# 3. Upload file to GCS
curl -X PUT "$UPLOAD_URL" \
-H "Content-Type: application/pdf" \
--data-binary @test.pdf
# 4. Trigger processing
curl -X POST http://localhost:8000/api/documents/$DOC_ID/process/ \
-H "Authorization: Bearer $TOKEN"
# 5. Check status
curl -X GET http://localhost:8000/api/documents/$DOC_ID/ \
-H "Authorization: Bearer $TOKEN"- Document processing time
- Celery task queue depth
- RAG response generation time
- GCS storage usage
- Database query performance
- Django application logs
- Celery worker logs
- GCS client logs
- Qdrant client logs
- Set
DEBUG=False - Configure proper
SECRET_KEY - Set up production database (PostgreSQL)
- Configure GCS with proper IAM roles
- Set up Redis for Celery
- Configure HTTPS/SSL
- Set up static file serving (Whitenoise/CDN)
- Configure monitoring and logging
- Set up database backups
- Configure rate limiting
- Set up Celery with proper concurrency
- Check Celery worker logs:
docker-compose logs celery - Verify GCS credentials
- Check document status in admin panel
- Verify Qdrant is running
- Check JWT token expiration
- Verify user is active
- Check CORS configuration in settings
- Run migrations:
make migrate - Check PostgreSQL connection
- Verify database credentials in .env
This project was converted from FastAPI to Django:
- FastAPI routes → Django REST Framework ViewSets
- Pydantic models → DRF Serializers
- SQLAlchemy models → Django ORM models
- AWS S3 → Google Cloud Storage
- Background processor service → Celery tasks
- FastAPI JWT → djangorestframework-simplejwt
- Fork the repository
- Create a feature branch
- Make your changes
- Run tests
- Submit a pull request
MIT License
For detailed documentation, see:
- PROJECT_OVERVIEW.md - Comprehensive project documentation
- Admin Interface: http://localhost:8000/admin/
- API Root: http://localhost:8000/api/
Built with Django, PostgreSQL, Celery, GCS, and Qdrant