A Django-based alerting and notification system that allows administrators to create and manage alerts with configurable visibility and automatic reminders, while providing users with the ability to interact with their alerts.
- Admin Alert Management: Create, update, and manage alerts with flexible visibility settings
- User Alert Interface: View, read, and snooze personal alerts
- Automated Reminders: Background tasks send reminders every 2 hours until snoozed or expired
- Flexible Visibility: Target entire organization, specific teams, or individual users
- Analytics Dashboard: Track alert engagement and delivery statistics
- Extensible Architecture: Clean OOP design with strategy patterns for future enhancements
- Backend: Django 4.2+ with Django REST Framework
- Database: SQLite (easily configurable for PostgreSQL/MySQL)
- Background Tasks: Celery with Redis broker
- Authentication: Token-based authentication
- API: RESTful APIs with proper serialization
- Python 3.8+
- Redis server (for Celery background tasks)
- Clone and setup project:
git clone <repository-url>
cd alerting_platform
# Create virtual environment
python -m venv alerting_env
source alerting_env/bin/activate # Linux/Mac
# alerting_env\Scripts\activate # Windows
# Install dependencies
pip install django djangorestframework celery redis django-cors-headers python-decouple- Database setup:
python manage.py makemigrations users
python manage.py makemigrations alerts
python manage.py makemigrations notifications
python manage.py migrate- Create superuser:
python manage.py createsuperuser- Load test data:
python manage.py setup_test_data- Start Redis (required for background tasks):
# Using Docker
docker run -p 6379:6379 redis
# Or install Redis locally and start it
redis-server- Start Django server:
python manage.py runserver- Start Celery worker (in separate terminal):
celery -A alerting_platform worker --loglevel=info- Start Celery beat scheduler (in another terminal):
celery -A alerting_platform beat --loglevel=infoAll API endpoints require authentication. Get a token:
curl -X POST http://localhost:8000/api/auth/token/ \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"admin123"}'Use the token in subsequent requests:
curl -H "Authorization: Token YOUR_TOKEN_HERE" http://localhost:8000/api/admin/alerts/Base URL: /api/admin/alerts/
POST /api/admin/alerts/
Content-Type: application/json
Authorization: Token YOUR_TOKEN
{
"title": "System Maintenance",
"message": "Scheduled maintenance tonight from 2 AM to 4 AM",
"severity": "warning",
"visibility_type": "organization",
"start_time": "2024-01-01T00:00:00Z",
"expiry_time": "2024-01-02T00:00:00Z",
"reminders_enabled": true
}GET /api/admin/alerts/
Authorization: Token YOUR_TOKEN
# Optional filters:
GET /api/admin/alerts/?severity=critical&is_active=true&visibility_type=teamPUT /api/admin/alerts/{id}/
Content-Type: application/json
Authorization: Token YOUR_TOKEN
{
"title": "Updated Title",
"is_active": false
}GET /api/admin/alerts/analytics/
Authorization: Token YOUR_TOKENGET /api/user/alerts/
Authorization: Token YOUR_TOKEN
# Optional filters:
GET /api/user/alerts/?state=unreadPOST /api/user/alerts/{alert_id}/read/
Authorization: Token YOUR_TOKENPOST /api/user/alerts/{alert_id}/unread/
Authorization: Token YOUR_TOKENPOST /api/user/alerts/{alert_id}/snooze/
Authorization: Token YOUR_TOKENGET /api/user/dashboard/
Authorization: Token YOUR_TOKENThe setup_test_data command creates:
- Engineering
- Marketing
- Operations
- admin (admin123) - Administrator
- john_eng (password123) - Engineering team member
- sarah_eng (password123) - Engineering team member
- mike_marketing (password123) - Marketing team member
- lisa_ops (password123) - Operations team member
- Organization-wide maintenance notice
- Team-specific security update
- User-specific database migration notice
- User: Extended Django user with team association and admin flag
- Team: Organizational units for targeting alerts
- Alert: Core alert entity with timing and targeting
- UserAlertPreference: User-specific alert state and snooze management
- NotificationDelivery: Audit log of sent notifications
- AlertService: Business logic for alert management and targeting
- NotificationService: Handles delivery and reminder logic
- send_reminders: Runs every 2 hours, sends reminders to users with unread alerts
- reset_daily_snoozes: Runs daily at midnight, resets day-long snoozes
- Strategy Pattern: Notification channels (in-app, email, SMS)
- Service Layer: Business logic separation from views
- Factory Pattern: Channel creation and management
- Create new channel class:
# notifications/channels.py
class SlackChannel(NotificationChannel):
def send(self, alert, user):
# Implement Slack integration
pass
def get_channel_name(self):
return 'slack'- Register in factory:
# notifications/channels.py
class NotificationChannelFactory:
_channels = {
'in_app': InAppChannel,
'email': EmailChannel,
'sms': SMSChannel,
'slack': SlackChannel, # Add new channel
}Modify the Alert model and update the reminder logic in the Celery task.
- Visit Django Admin:
http://localhost:8000/admin/ - API Status:
http://localhost:8000/api/status/ - DRF Browsable API:
http://localhost:8000/api/admin/alerts/
# Get token
TOKEN=$(curl -s -X POST http://localhost:8000/api/auth/token/ \
-H "Content-Type: application/json" \
-d '{"username":"admin","password":"admin123"}' | \
python -c "import sys, json; print(json.load(sys.stdin)['token'])")
# Test admin APIs
curl -H "Authorization: Token $TOKEN" http://localhost:8000/api/admin/alerts/
curl -H "Authorization: Token $TOKEN" http://localhost:8000/api/admin/alerts/analytics/
# Test user APIs
curl -H "Authorization: Token $TOKEN" http://localhost:8000/api/user/alerts/
curl -H "Authorization: Token $TOKEN" http://localhost:8000/api/user/dashboard/403 Forbidden on admin endpoints: Ensure user has is_admin=True
# In Django shell
from django.contrib.auth import get_user_model
User = get_user_model()
user = User.objects.get(username='your_username')
user.is_admin = True
user.save()Celery tasks not running: Ensure Redis is running and Celery worker/beat are started
No reminders being sent: Check Celery logs and verify alerts have reminders_enabled=True
- Django: Check console output when running
python manage.py runserver - Celery: Check worker and beat terminal outputs
- Redis: Use
redis-cli monitorto see Redis operations
# .env file
DEBUG=False
SECRET_KEY=your-production-secret-key
DATABASE_URL=postgresql://user:pass@localhost/dbname
REDIS_URL=redis://localhost:6379/0
ALLOWED_HOSTS=yourdomain.comConfigure PostgreSQL or MySQL in settings for production use.
python manage.py collectstaticUse supervisord or similar to manage Django, Celery worker, and Celery beat processes.
This project is created as a technical assessment and demonstration of Django development skills.