A comprehensive Django-based form builder and response management system similar to Google Forms, featuring real-time notifications, analytics, and a flexible API architecture.
- Dynamic Form Creation: Build forms with multiple field types (text, number, date, dropdown, checkbox, file upload)
- Real-Time Notifications: WebSocket-powered live updates for new submissions
- Flexible Response Collection: Multiple API endpoints for different use cases
- Advanced Analytics: Response rates, completion statistics, and field-level insights
- File Upload Support: Secure file handling with cloud storage integration
- Smart Field Matching: Tolerant field label matching for easy integration
- Status Workflow: Draft β Submitted β Under Review β Approved/Rejected
- RESTful API: Comprehensive API with multiple ViewSets for different workflows
- Backend: Django 4.2.25 + Django REST Framework
- Real-time: Django Channels with WebSockets
- Database: SQLite (development) / PostgreSQL (production)
- Task Queue: Celery with Redis
- File Storage: Local (development) / AWS S3 (production)
- Authentication: JWT Token-based authentication
- Python 3.8+
- Node.js 16+ (for frontend development)
- Redis Server (for real-time features and Celery)
- PostgreSQL (for production)
git clone <repository-url>
cd myprojoWindows (PowerShell):
python -m venv .venv
.venv\Scripts\Activate.ps1macOS/Linux:
python3 -m venv .venv
source .venv/bin/activatepip install -r requirements.txtCreate a .env file in the project root:
# Django Settings
SECRET_KEY=your-secret-key-here
DEBUG=True
ALLOWED_HOSTS=localhost,127.0.0.1
# Database Configuration (Development - SQLite)
DATABASE_URL=sqlite:///db.sqlite3
# Database Configuration (Production - PostgreSQL)
# DATABASE_URL=postgresql://username:password@localhost:5432/dbname
# Redis Configuration (for Channels and Celery)
REDIS_URL=redis://localhost:6379/0
# Celery Configuration
CELERY_BROKER_URL=redis://localhost:6379/0
CELERY_RESULT_BACKEND=redis://localhost:6379/0
# AWS S3 Configuration (Production)
# AWS_ACCESS_KEY_ID=your-access-key
# AWS_SECRET_ACCESS_KEY=your-secret-key
# AWS_STORAGE_BUCKET_NAME=your-bucket-name
# AWS_S3_REGION_NAME=us-west-2
# CORS Settings
CORS_ALLOW_ALL_ORIGINS=True
CORS_ALLOW_CREDENTIALS=True# Create and apply migrations
python manage.py makemigrations
python manage.py migrate
# Create superuser account
python manage.py createsuperuserWindows:
# Using Chocolatey
choco install redis-64
# Or download from: https://github.com/microsoftarchive/redis/releasesmacOS:
brew install redis
brew services start redisUbuntu/Linux:
sudo apt update
sudo apt install redis-server
sudo systemctl start redis-server
sudo systemctl enable redis-serverTerminal 1 - Django Development Server:
python manage.py runserverTerminal 2 - Celery Worker (Optional):
celery -A myprojo worker --loglevel=infoTerminal 3 - Redis Server (if not running as service):
redis-server- API Root: http://localhost:8000/api/
- Django Admin: http://localhost:8000/admin/
- WebSocket: ws://localhost:8000/ws/notifications/
Using Django Admin:
- Go to http://localhost:8000/admin/
- Login with your superuser account
- Add a new Form in the "Forms" section
- Add Fields to your form in the "Fields" section
Using API:
# Create a form
curl -X POST http://localhost:8000/api/forms/ \
-H "Content-Type: application/json" \
-d '{
"name": "Contact Form",
"description": "Get in touch with us",
"is_active": true,
"allow_multiple_submissions": false
}'
# Add fields to the form
curl -X POST http://localhost:8000/api/fields/ \
-H "Content-Type: application/json" \
-d '{
"form": 1,
"label": "Full Name",
"field_type": "text",
"required": true,
"order": 1
}'curl -X POST http://localhost:8000/api/field-responses/ \
-H "Content-Type: application/json" \
-d '{
"form_id": 1,
"submitted_by": "user@example.com",
"answers": {
"Full Name": "John Doe",
"Email": "john@example.com",
"Message": "Hello, this is a test message!"
}
}'| Endpoint | Description | Methods |
|---|---|---|
/api/forms/ |
Form management | GET, POST, PUT, DELETE |
/api/fields/ |
Field definitions | GET, POST, PUT, DELETE |
/api/submissions/ |
Submission management | GET, POST, PUT, DELETE |
/api/field-responses/ |
Client response API | GET, POST |
/api/form-responses/ |
Form analytics & responses | GET |
/api/notifications/ |
Real-time notifications | GET, POST |
| Endpoint | Description |
|---|---|
/api/submissions/recent/ |
Recent submissions |
/api/submissions/statistics/ |
Overall statistics |
/api/form-responses/{id}/analytics/ |
Form-specific analytics |
/api/form-responses/{id}/responses/ |
All responses for a form |
/api/form-responses/all_responses/ |
Cross-form response view |
For detailed API documentation, see FORM_RESPONSES_API.md
myprojo/
βββ myprojo/ # Django project settings
β βββ settings.py # Main settings
β βββ urls.py # URL routing
β βββ asgi.py # ASGI configuration
β βββ wsgi.py # WSGI configuration
βββ forms_app/ # Form definitions
β βββ models.py # Form model
β βββ views.py # Form API views
β βββ serializers.py # Form serializers
β βββ admin.py # Admin interface
βββ fields_app/ # Dynamic field definitions
β βββ models.py # Field model with types & validation
β βββ views.py # Field API views
β βββ serializers.py # Field serializers
βββ submissions_app/ # Response collection & analytics
β βββ models.py # Submission, FieldResponse, Notification
β βββ views.py # Multiple ViewSets for different use cases
β βββ serializers.py # Response serializers
β βββ consumers.py # WebSocket consumers
β βββ routing.py # WebSocket routing
β βββ tasks.py # Celery tasks
βββ templates/ # Django templates (if needed)
βββ requirements.txt # Python dependencies
βββ manage.py # Django management script
βββ db.sqlite3 # SQLite database (development)
βββ README.md # This file
βββ DESIGN_DECISIONS.md # Architecture documentation
βββ FORM_RESPONSES_API.md # API documentation
Development (SQLite):
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}Production (PostgreSQL):
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'your_db_name',
'USER': 'your_db_user',
'PASSWORD': 'your_db_password',
'HOST': 'localhost',
'PORT': '5432',
}
}For real-time features and Celery:
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [("127.0.0.1", 6379)],
},
},
}
CELERY_BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'redis://localhost:6379'Development (Local Storage):
MEDIA_URL = '/media/'
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')Production (AWS S3):
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
AWS_ACCESS_KEY_ID = 'your-access-key'
AWS_SECRET_ACCESS_KEY = 'your-secret-key'
AWS_STORAGE_BUCKET_NAME = 'your-bucket-name'# Run all tests
python manage.py test
# Run specific app tests
python manage.py test forms_app
python manage.py test fields_app
python manage.py test submissions_app
# Run with coverage
pip install coverage
coverage run --source='.' manage.py test
coverage report
coverage htmlUse the provided test file:
python test_api_endpoints.pyOr test manually with curl:
# Test form creation
curl -X POST http://localhost:8000/api/forms/ \
-H "Content-Type: application/json" \
-d '{"name": "Test Form", "description": "Test form description"}'- Environment Variables: Set production values in
.env - Database: Configure PostgreSQL connection
- Redis: Set up Redis server for production
- Static Files: Configure static file serving
- File Storage: Set up AWS S3 or similar
- Security: Update
ALLOWED_HOSTS, disableDEBUG - SSL: Configure HTTPS certificates
- Monitoring: Set up application monitoring
Create Dockerfile:
FROM python:3.11-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["gunicorn", "myprojo.wsgi:application", "--bind", "0.0.0.0:8000"]Create docker-compose.yml:
version: '3.8'
services:
web:
build: .
ports:
- "8000:8000"
depends_on:
- redis
- db
environment:
- DATABASE_URL=postgresql://postgres:password@db:5432/formdb
- REDIS_URL=redis://redis:6379/0
db:
image: postgres:13
environment:
POSTGRES_DB: formdb
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
volumes:
- postgres_data:/var/lib/postgresql/data
redis:
image: redis:6
ports:
- "6379:6379"
volumes:
postgres_data:- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Documentation: See DESIGN_DECISIONS.md for architecture details
- API Docs: See FORM_RESPONSES_API.md for API reference
- Issues: Create an issue on GitHub for bugs or feature requests