Advanced Dynamic Survey Platform - Enterprise-level REST API for creating, deploying, and analyzing surveys.
Interactive Documentation:
- Swagger UI: http://localhost:8000/api/docs/
- ReDoc: http://localhost:8000/api/redoc/
- OpenAPI Schema: http://localhost:8000/api/schema/
Code Examples:
python api_docs/examples.pySee api_docs/ for working Python examples.
- Dynamic Survey Builder - Multi-step surveys with sections, various field types, conditional logic, and field dependencies
- Survey Submission - Real-time validation, partial response saving, resumable sessions
- Data Security - AES-256-GCM encryption for sensitive fields, RBAC permissions
- Async Processing - Celery-powered exports, batch invitations
- Analytics - Survey-level statistics with caching
- Comprehensive Documentation - OpenAPI/Swagger with detailed guides and examples
- Framework: Django 6.0 + Django REST Framework
- Database: PostgreSQL 16
- Cache/Broker: Redis 7
- Task Queue: Celery 5.6
- Auth: JWT (SimpleJWT)
- Docker & Docker Compose
- Git
git clone <repository-url>
cd survey-api-app
# Create environment file
cp .env.example .env# Generate a secure encryption key and add to .env
docker compose run --rm web python manage.py generate_encryption_keyCopy the output to FIELD_ENCRYPTION_KEY in your .env file.
docker compose up -dThis starts:
- web - Django API server at http://localhost:8000
- db - PostgreSQL database
- redis - Redis for caching and Celery broker
- celery - Background task worker
- celery-beat - Scheduled tasks
docker compose exec web python manage.py createsuperuser- API Root: http://localhost:8000/api/v1/
- Swagger Docs: http://localhost:8000/api/docs/
- Admin Panel: http://localhost:8000/admin/
- Python 3.12+
- Poetry
- PostgreSQL (or use Docker for DB only)
- Redis (or use Docker for Redis only)
# Install Poetry if not installed
curl -sSL https://install.python-poetry.org | python3 -
# Install project dependencies
poetry installcp .env.example .env
# Edit .env with your local settingsOption A - Use Docker for PostgreSQL and Redis only:
docker compose up -d db redisOption B - Use local PostgreSQL:
# Update .env with your local PostgreSQL credentialspoetry run python manage.py migratepoetry run python manage.py generate_encryption_key
# Add the output to FIELD_ENCRYPTION_KEY in .env# Django server
poetry run python manage.py runserver
# In separate terminal - Celery worker
poetry run celery -A config worker -l info
# Optional - Celery beat for scheduled tasks
poetry run celery -A config beat -l info# Register
POST /api/v1/auth/register/
# Login (returns JWT tokens)
POST /api/v1/auth/login/
# Refresh token
POST /api/v1/auth/token/refresh/
# Use token in requests
Authorization: Bearer <access_token># List/Create surveys
GET/POST /api/v1/surveys/
# Survey details
GET/PATCH/DELETE /api/v1/surveys/{id}/
# Publish survey
POST /api/v1/surveys/{id}/publish/# Start survey session
POST /api/v1/surveys/{id}/submissions/start/
# Get current section
GET /api/v1/submissions/current-section/
# Header: X-Session-Token: <token>
# Submit section answers
POST /api/v1/submissions/submit-section/
# Finish survey
POST /api/v1/submissions/finish/# List responses
GET /api/v1/surveys/{id}/responses/
# Export responses (async, emailed)
GET /api/v1/surveys/{id}/responses/export/?format=csv
# Analytics
GET /api/v1/surveys/{id}/responses/analytics/For complete documentation: Visit http://localhost:8000/api/docs/
# Run all tests
poetry run pytest
# Run specific test file
poetry run pytest submissions/tests.py -v
# Run with coverage
poetry run pytest --cov=. --cov-report=html# Start Locust
poetry run locust -f load_tests/locustfile.py
# Open http://localhost:8089survey-api-app/
βββ config/ # Django project settings
β βββ settings.py
β βββ urls.py
β βββ celery.py
βββ users/ # User auth, RBAC, sessions
βββ surveys/ # Survey builder models & API
βββ submissions/ # Response handling, exports, analytics
βββ audit/ # Audit logging
βββ load_tests/ # Locust load testing
βββ architectural_docs/ # System documentation
βββ docker-compose.yml
βββ Dockerfile
βββ pyproject.toml # Poetry dependencies
βββ .env.example
| Variable | Description | Default |
|---|---|---|
SECRET_KEY |
Django secret key | (required) |
DEBUG |
Debug mode | True |
DB_ENGINE |
Database engine | postgresql |
DB_NAME |
Database name | survey_db |
DB_USER |
Database user | survey_user |
DB_PASSWORD |
Database password | survey_password |
DB_HOST |
Database host | localhost |
REDIS_URL |
Redis URL for caching | redis://localhost:6379/1 |
CELERY_BROKER_URL |
Celery broker URL | redis://localhost:6379/0 |
FIELD_ENCRYPTION_KEY |
AES-256 key for sensitive fields | (required) |
See .env.example for all options.
MIT