Skip to content

DataFlow is a Django Channels demo showcasing real-time student data. A threaded generator creates records and saves to SQLite while WebSockets broadcast progress to a sleek Material-inspired UI. Built with Redis, Daphne, Bootstrap, and Faker for smooth, scalable, live updates. Extensible and ready

Notifications You must be signed in to change notification settings

RajeebLochan/DataFlow

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

DataFlow - Real-time Student Data Generator

A sophisticated Django Channels application that demonstrates real-time data processing and WebSocket communication through an elegant Material Design interface.

Overview

DataFlow is a modern web application built with Django Channels that showcases real-time data generation and streaming capabilities. The system generates student records in the background using Python threading while simultaneously broadcasting updates to connected clients via WebSockets, creating a seamless real-time experience.

Key Features

Real-time Data Processing

  • Background Threading: Utilizes Python threading for non-blocking data generation
  • WebSocket Integration: Live data streaming to frontend without page refreshes
  • Progress Tracking: Real-time progress indicators with smooth animations
  • Database Persistence: Automatic saving of generated records to SQLite database

Modern User Interface

  • Material Design: Clean, professional interface following Google's Material Design principles
  • Responsive Layout: Optimized for desktop and mobile devices
  • Glass Morphism: Modern frosted glass visual effects with backdrop blur
  • Animated Components: Smooth transitions and engaging micro-interactions

Technical Architecture

  • Django Channels: Asynchronous WebSocket handling for real-time communication
  • Redis Channel Layer: Scalable message broadcasting system
  • Faker Integration: Realistic fake data generation for testing and demonstration
  • Consumer Patterns: Well-structured WebSocket consumers for different data types

Technology Stack

Backend Framework

  • Django 5.2.5
  • Django Channels 4.2.1
  • Daphne ASGI Server

Real-time Communication

  • WebSockets
  • Redis Channel Layer
  • Asynchronous Programming

Data Generation

  • Python Threading
  • Faker Library
  • SQLite Database

Frontend Technologies

  • HTML5 & CSS3
  • JavaScript ES6+
  • Bootstrap 5.3
  • Material Design Icons

Project Structure

core/
├── core/
│   ├── asgi.py              # ASGI configuration with WebSocket routing
│   ├── settings.py          # Django settings with Channels configuration
│   └── urls.py              # URL routing
├── home/
│   ├── models.py            # Database models (Students, Notifications)
│   ├── views.py             # Django views
│   ├── consumers.py         # WebSocket consumers
│   ├── thread.py            # Background threading logic
│   └── templates/
│       └── index.html       # Material Design frontend
├── templates/
└── manage.py

Installation & Setup

Prerequisites

  • Python 3.8 or higher
  • Redis server
  • Virtual environment (recommended)

Step 1: Clone and Setup Environment

git clone https://github.com/RajeebLochan/DataFlow/
cd core
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

Step 2: Install Dependencies

pip install django channels channels-redis faker daphne

Step 3: Configure Redis

# Install Redis (Ubuntu/Debian)
sudo apt update
sudo apt install redis-server

# Start Redis service
sudo systemctl start redis-server
sudo systemctl enable redis-server

Step 4: Database Setup

cd core
python manage.py makemigrations
python manage.py migrate

Step 5: Run the Application

python manage.py runserver

The application will be available at http://127.0.0.1:8000/

Usage Guide

Basic Operation

  1. Access the Application: Navigate to the home page
  2. Set Parameters: Enter the number of students to generate (1-100)
  3. Start Generation: Click "Start Generation" to begin the process
  4. Monitor Progress: Watch real-time progress bar and student cards appearing
  5. WebSocket Status: Monitor connection status in the status indicator

Real-time Features

  • Live Updates: Student records appear instantly as they're generated
  • Progress Tracking: Visual progress bar with percentage completion
  • Connection Monitoring: Real-time WebSocket connection status
  • Animated Interface: Smooth card animations and loading states

API Endpoints

HTTP Endpoints

  • GET / - Main application interface
  • GET /generate-students/?total=<number> - Start student generation process

WebSocket Endpoints

  • ws://localhost:8000/ws/test/ - Real-time data streaming

Technical Implementation

WebSocket Consumer

class TestConsumer(WebsocketConsumer):
    def connect(self):
        # Join user-specific group for notifications
        self.room_group_name = "student_data_group"
        async_to_sync(self.channel_layer.group_add)(
            self.room_group_name, self.channel_name
        )
        self.accept()

    def send_student_data(self, event):
        # Handle student data from thread and send to frontend
        message = event["message"]
        self.send(text_data=json.dumps({
            'type': 'student_data',
            'data': json.loads(message)
        }))

Background Threading

class CreateStudentThread(threading.Thread):
    def run(self):
        for i in range(self.total):
            # Generate fake student data
            student_data = {
                'name': fake.name(),
                'email': fake.email(),
                'address': fake.address(),
                'age': fake.random_int(min=18, max=25)
            }
            
            # Save to database and broadcast via WebSocket
            Students.objects.create(**student_data)
            async_to_sync(channel_layer.group_send)(
                "student_data_group",
                {"type": "send_student_data", "message": json.dumps(student_data)}
            )

Configuration

Django Settings

INSTALLED_APPS = [
    'channels',
    'daphne',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'home',
]

ASGI_APPLICATION = 'core.asgi.application'

CHANNEL_LAYERS = {
    "default": {
        "BACKEND": "channels_redis.core.RedisChannelLayer",
        "CONFIG": {
            "hosts": [("localhost", 6379)],
        },
    },
}

Performance Considerations

Scalability Features

  • Asynchronous Processing: Non-blocking operations for better performance
  • Redis Channel Layer: Distributed message handling for horizontal scaling
  • Efficient Database Operations: Optimized queries and bulk operations
  • Memory Management: Proper cleanup of WebSocket connections

Optimization Tips

  • Use Redis clustering for high-traffic scenarios
  • Implement connection pooling for database operations
  • Consider using Celery for heavy background tasks
  • Monitor WebSocket connection limits

Development Workflow

Local Development

  1. Start Redis server
  2. Activate virtual environment
  3. Run migrations if needed
  4. Start Django development server
  5. Access application and test WebSocket connections

Testing WebSocket Connections

# Using wscat (install with: npm install -g wscat)
wscat -c ws://localhost:8000/ws/test/

# Or use browser console
const ws = new WebSocket('ws://localhost:8000/ws/test/');
ws.onmessage = (event) => console.log(JSON.parse(event.data));

Deployment

Production Considerations

  • Use environment variables for sensitive settings
  • Configure Redis with proper security settings
  • Set up proper logging and monitoring
  • Use reverse proxy (Nginx) for static files
  • Configure SSL/TLS for WebSocket connections

Docker Deployment

FROM python:3.9
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 8000
CMD ["daphne", "-b", "0.0.0.0", "-p", "8000", "core.asgi:application"]

Troubleshooting

Common Issues

  • Redis Connection: Ensure Redis server is running on port 6379
  • WebSocket 404: Check ASGI routing configuration
  • Import Errors: Verify all dependencies are installed
  • Thread Issues: Monitor background thread execution

Debug Mode

Enable Django debug mode for development:

DEBUG = True
ALLOWED_HOSTS = ['localhost', '127.0.0.1']

Contributing

Development Setup

  1. Fork the repository
  2. Create a feature branch
  3. Make changes and test thoroughly
  4. Submit a pull request with detailed description

Code Standards

  • Follow PEP 8 style guidelines
  • Write comprehensive docstrings
  • Include unit tests for new features
  • Update documentation as needed

License

This project is open source and available under the MIT License.

Author

Developed as a demonstration of modern web development practices using Django Channels, WebSockets, and real-time data processing techniques.


Note: This application is designed for educational and demonstration purposes, showcasing the integration of Django Channels with real-time data processing and modern frontend technologies.

About

DataFlow is a Django Channels demo showcasing real-time student data. A threaded generator creates records and saves to SQLite while WebSockets broadcast progress to a sleek Material-inspired UI. Built with Redis, Daphne, Bootstrap, and Faker for smooth, scalable, live updates. Extensible and ready

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published