A sophisticated Django Channels application that demonstrates real-time data processing and WebSocket communication through an elegant Material Design interface.
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.
- 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
- 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
- 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
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
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
- Python 3.8 or higher
- Redis server
- Virtual environment (recommended)
git clone https://github.com/RajeebLochan/DataFlow/
cd core
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activatepip install django channels channels-redis faker daphne# Install Redis (Ubuntu/Debian)
sudo apt update
sudo apt install redis-server
# Start Redis service
sudo systemctl start redis-server
sudo systemctl enable redis-servercd core
python manage.py makemigrations
python manage.py migratepython manage.py runserverThe application will be available at http://127.0.0.1:8000/
- Access the Application: Navigate to the home page
- Set Parameters: Enter the number of students to generate (1-100)
- Start Generation: Click "Start Generation" to begin the process
- Monitor Progress: Watch real-time progress bar and student cards appearing
- WebSocket Status: Monitor connection status in the status indicator
- 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
GET /- Main application interfaceGET /generate-students/?total=<number>- Start student generation process
ws://localhost:8000/ws/test/- Real-time data streaming
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)
}))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)}
)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)],
},
},
}- 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
- Use Redis clustering for high-traffic scenarios
- Implement connection pooling for database operations
- Consider using Celery for heavy background tasks
- Monitor WebSocket connection limits
- Start Redis server
- Activate virtual environment
- Run migrations if needed
- Start Django development server
- Access application and test 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));- 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
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"]- 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
Enable Django debug mode for development:
DEBUG = True
ALLOWED_HOSTS = ['localhost', '127.0.0.1']- Fork the repository
- Create a feature branch
- Make changes and test thoroughly
- Submit a pull request with detailed description
- Follow PEP 8 style guidelines
- Write comprehensive docstrings
- Include unit tests for new features
- Update documentation as needed
This project is open source and available under the MIT License.
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.