Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

8 Commits
Β 
Β 
Β 
Β 

Repository files navigation

Dynamic Form Management System

A comprehensive Django-based form builder and response management system similar to Google Forms, featuring real-time notifications, analytics, and a flexible API architecture.

Features

  • 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

Technology Stack

  • 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

Prerequisites

  • Python 3.8+
  • Node.js 16+ (for frontend development)
  • Redis Server (for real-time features and Celery)
  • PostgreSQL (for production)

Installation

1. Clone the Repository

git clone <repository-url>
cd myprojo

2. Create Virtual Environment

Windows (PowerShell):

python -m venv .venv
.venv\Scripts\Activate.ps1

macOS/Linux:

python3 -m venv .venv
source .venv/bin/activate

3. Install Dependencies

pip install -r requirements.txt

4. Environment Configuration

Create 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

5. Database Setup

# Create and apply migrations
python manage.py makemigrations
python manage.py migrate

# Create superuser account
python manage.py createsuperuser

6. Install Redis (Required for Real-time Features)

Windows:

# Using Chocolatey
choco install redis-64

# Or download from: https://github.com/microsoftarchive/redis/releases

macOS:

brew install redis
brew services start redis

Ubuntu/Linux:

sudo apt update
sudo apt install redis-server
sudo systemctl start redis-server
sudo systemctl enable redis-server

7. Start Development Servers

Terminal 1 - Django Development Server:

python manage.py runserver

Terminal 2 - Celery Worker (Optional):

celery -A myprojo worker --loglevel=info

Terminal 3 - Redis Server (if not running as service):

redis-server

πŸš€ Quick Start

1. Access the Application

2. Create Your First Form

Using Django Admin:

  1. Go to http://localhost:8000/admin/
  2. Login with your superuser account
  3. Add a new Form in the "Forms" section
  4. 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
  }'

3. Submit Response to Form

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!"
    }
  }'

πŸ“– API Documentation

Core Endpoints

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

Advanced Endpoints

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

Project Structure

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

πŸ”§ Configuration

Database Configuration

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',
    }
}

Redis Configuration

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'

File Storage Configuration

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'

Testing

Run Tests

# 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 html

API Testing

Use the provided test file:

python test_api_endpoints.py

Or 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"}'

Deployment

Production Checklist

  1. Environment Variables: Set production values in .env
  2. Database: Configure PostgreSQL connection
  3. Redis: Set up Redis server for production
  4. Static Files: Configure static file serving
  5. File Storage: Set up AWS S3 or similar
  6. Security: Update ALLOWED_HOSTS, disable DEBUG
  7. SSL: Configure HTTPS certificates
  8. Monitoring: Set up application monitoring

Docker Deployment (Optional)

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:

Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

Support

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages