How bilalhassankhan007/threat_monitoring_alert_platform_using_django works
Purpose and entry points
A Django 5 threat-monitoring backend ingests security events, generates alerts for severe events, and exposes JWT-protected REST APIs plus a dashboard/demo UI. Django starts through manage.py; production serves WSGI via threat_platform/wsgi.py. Global routing and service configuration are centralized in threat_platform/urls.py and threat_platform/settings.py.
Application composition
Two domain apps separate identity from monitoring:
• accounts/models.py defines the custom Django user and Admin/Analyst role model.
• monitoring/models.py owns Event and Alert persistence.
• monitoring/apps.py initializes the monitoring app, including signal registration.
Migrations under accounts/migrations/ and monitoring/migrations/ define the persisted schema evolution.
Authentication and authorization boundary
JWT token issuance, refresh, and verification are configured at the project layer and routed through threat_platform/urls.py. API requests authenticate with bearer tokens; role-based access is enforced by monitoring/permissions.py. Admin users can ingest events and update alert state, while Analysts have alert read access. Django admin remains a separate privileged management interface through accounts/admin.py and monitoring/admin.py.
Event-to-alert processing pipeline
The core write flow is: client request → DRF serialization/validation → Event database save → post-save rule → optional Alert creation.
• monitoring/serializers.py validates and formats Event/Alert API payloads.
• monitoring/views.py exposes the main Event and Alert viewsets.
• monitoring/signals.py reacts to newly saved HIGH or CRITICAL Events and creates an OPEN Alert.
This signal boundary keeps alert-generation policy decoupled from request handlers, but means any Event creation path that saves the model can trigger alert generation.
Alert query and lifecycle APIs
Alert reads flow through optimized queryset/viewset logic in monitoring/views.py, with filtering in monitoring/filters.py and page boundaries in monitoring/pagination.py. API consumers can filter alert severity/status and receive paginated results. Alert state mutation is restricted to Admin roles via the permission layer. URL registration for these APIs is in monitoring/urls.py.
Dashboard integration layer
The root dashboard is a server-rendered demo/control surface at monitoring/templates/monitoring/dashboard.html, backed by dashboard-specific endpoints in monitoring/dashboard_api.py. It consumes the same authentication and authorization model while adding operational shortcuts: creating analysts, injecting a critical test event, listing filtered alerts, and changing alert status. This is an integration/UI boundary rather than the core domain API.
Runtime, persistence, and deployment
The runtime is Python/Django with Django REST Framework, simplejwt, django-filter, and drf-spectacular/OpenAPI. PostgreSQL is the intended production database, selected from DATABASE_URL; SQLite is the local fallback. Environment loading, database setup, REST/JWT settings, schema documentation, and static-file behavior are in threat_platform/settings.py. Deployment targets Render using render.yaml and build.sh, with Gunicorn serving threat_platform.wsgi:application; WhiteNoise handles static assets.
Main entry points: models.py Events & alerts · views.py Event & alert API · dashboard_api.py Dashboard endpoints · settings.py Service configuration
Components 18
Django Project
- Django entry point
manage.py - Service configuration · Configures database, REST, JWT, OpenAPI, static files, and environment loading.
threat_platform/settings.py - Global routes & JWT · Registers API routes and JWT token endpoints.
threat_platform/urls.py - Users & roles · Custom users carry Admin and Analyst roles.
accounts/models.py - Privileged admin · Separate management interface for users, events, and alerts.
accounts/admin.py
Monitoring Domain
- Monitoring app startup · Registers monitoring signals during application initialization.
monitoring/apps.py - Monitoring API routes
monitoring/urls.py - Event & alert API · Exposes event ingestion, alert reads, and alert state updates.
monitoring/views.py - Payload validation · Validates and formats Event and Alert payloads.
monitoring/serializers.py - Role authorization · Admins write events and mutate alerts; Analysts can read alerts.
monitoring/permissions.py - Alert query support · Filters alerts by severity/status and applies page boundaries.
monitoring/filters.py - Events & alerts · Persistent security events and their generated alerts.
monitoring/models.py - Severe-event alert rule · Creates an OPEN Alert for newly saved HIGH or CRITICAL Events.
monitoring/signals.py
Dashboard UI
- Dashboard endpoints · Provides demo operations including analyst creation, test events, and alert updates.
monitoring/dashboard_api.py - Demo dashboard
monitoring/templates/monitoring/dashboard.html
Runtime & Deployment
- Production WSGI app
threat_platform/wsgi.py - PostgreSQL / SQLite · PostgreSQL is selected from DATABASE_URL; SQLite is the local fallback.
- Render deployment · Builds the service and runs Gunicorn with WhiteNoise static serving.
render.yaml
Connections 21
- Django entry point → Service configuration: boots with
- Production WSGI app → Service configuration: loads
- Render deployment → Production WSGI app: Gunicorn serves
- Service configuration → PostgreSQL / SQLite: configures
- Global routes & JWT → Monitoring API routes: includes
- Global routes & JWT → Dashboard endpoints: routes to
- Monitoring API routes → Event & alert API: dispatches to
- Event & alert API → Payload validation: validates via
- Event & alert API → Role authorization: authorizes via
- Event & alert API → Alert query support: filters and paginates with
- Event & alert API → Events & alerts: reads and writes
- Events & alerts → PostgreSQL / SQLite: persists in
- Monitoring app startup → Severe-event alert rule: registers
- Events & alerts → Severe-event alert rule: post-save triggers
- Severe-event alert rule → Events & alerts: creates OPEN alert
- Demo dashboard → Dashboard endpoints: uses
- Dashboard endpoints → Role authorization: uses
- Dashboard endpoints → Events & alerts: operates on
- Users & roles → PostgreSQL / SQLite: persists in
- Privileged admin → Users & roles: manages
- Privileged admin → Events & alerts: manages