# bilalhassankhan007/threat_monitoring_alert_platform_using_django architecture

> Architecture diagram of the GitHub repository bilalhassankhan007/threat_monitoring_alert_platform_using_django, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-25). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django
- Repository: https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django

## Overview

#### 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: [`monitoring/models.py`](https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/monitoring/models.py) (Events & alerts), [`monitoring/views.py`](https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/monitoring/views.py) (Event & alert API), [`monitoring/dashboard_api.py`](https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/monitoring/dashboard_api.py) (Dashboard endpoints), [`threat_platform/settings.py`](https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/threat_platform/settings.py) (Service configuration)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_project["Django Project"]
  node_manage["Django entry point<br/>Python CLI<br/>[manage.py]"]
  node_settings["Service configuration<br/>Django settings<br/>[settings.py]"]
  node_project_urls["Global routes &amp; JWT<br/>Django URL config<br/>[urls.py]"]
  node_accounts[("Users &amp; roles<br/>Django models<br/>[models.py]")]
  node_admin["Privileged admin<br/>Django admin<br/>[admin.py]"]
end

subgraph group_monitoring["Monitoring Domain"]
  node_monitoring_app["Monitoring app startup<br/>Django app config<br/>[apps.py]"]
  node_monitoring_urls["Monitoring API routes<br/>DRF URL config<br/>[urls.py]"]
  node_api_views["Event &amp; alert API<br/>DRF viewsets<br/>[views.py]"]
  node_serializers["Payload validation<br/>DRF serializers<br/>[serializers.py]"]
  node_permissions["Role authorization<br/>DRF permissions<br/>[permissions.py]"]
  node_query_support["Alert query support<br/>Filters &amp; pagination<br/>[filters.py]"]
  node_events_alerts[("Events &amp; alerts<br/>Django models<br/>[models.py]")]
  node_alert_signal["Severe-event alert rule<br/>Post-save signal<br/>[signals.py]"]
end

subgraph group_ui["Dashboard UI"]
  node_dashboard_api["Dashboard endpoints<br/>Django endpoints<br/>[dashboard_api.py]"]
  node_dashboard["Demo dashboard<br/>Server-rendered template<br/>[dashboard.html]"]
end

subgraph group_ops["Runtime &amp; Deployment"]
  node_wsgi["Production WSGI app<br/>[wsgi.py]"]
  node_database[("PostgreSQL / SQLite<br/>Relational database")]
  node_deployment{{"Render deployment<br/>Deployment config<br/>[render.yaml]"}}
end

node_manage -->|"boots with"| node_settings
node_wsgi -->|"loads"| node_settings
node_deployment -->|"Gunicorn serves"| node_wsgi
node_settings -->|"configures"| node_database
node_project_urls -->|"includes"| node_monitoring_urls
node_project_urls -->|"routes to"| node_dashboard_api
node_monitoring_urls -->|"dispatches to"| node_api_views
node_api_views -->|"validates via"| node_serializers
node_api_views -->|"authorizes via"| node_permissions
node_api_views -->|"filters and paginates with"| node_query_support
node_api_views -->|"reads and writes"| node_events_alerts
node_events_alerts -->|"persists in"| node_database
node_monitoring_app -->|"registers"| node_alert_signal
node_events_alerts -->|"post-save triggers"| node_alert_signal
node_alert_signal -->|"creates OPEN alert"| node_events_alerts
node_dashboard -->|"uses"| node_dashboard_api
node_dashboard_api -->|"uses"| node_permissions
node_dashboard_api -->|"operates on"| node_events_alerts
node_accounts -->|"persists in"| node_database
node_admin -->|"manages"| node_accounts
node_admin -->|"manages"| node_events_alerts

click node_manage "https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/manage.py"
click node_settings "https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/threat_platform/settings.py"
click node_project_urls "https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/threat_platform/urls.py"
click node_wsgi "https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/threat_platform/wsgi.py"
click node_accounts "https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/accounts/models.py"
click node_admin "https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/accounts/admin.py"
click node_monitoring_app "https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/monitoring/apps.py"
click node_monitoring_urls "https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/monitoring/urls.py"
click node_api_views "https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/monitoring/views.py"
click node_serializers "https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/monitoring/serializers.py"
click node_permissions "https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/monitoring/permissions.py"
click node_query_support "https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/monitoring/filters.py"
click node_events_alerts "https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/monitoring/models.py"
click node_alert_signal "https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/monitoring/signals.py"
click node_dashboard_api "https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/monitoring/dashboard_api.py"
click node_dashboard "https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/monitoring/templates/monitoring/dashboard.html"
click node_deployment "https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/render.yaml"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_manage,node_settings,node_project_urls,node_accounts,node_admin toneBlue
class node_monitoring_app,node_monitoring_urls,node_api_views,node_serializers,node_permissions,node_query_support,node_events_alerts,node_alert_signal toneAmber
class node_dashboard_api,node_dashboard toneMint
class node_wsgi,node_database,node_deployment toneRose
```

## Components

### Django Project

- [Django entry point](https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/manage.py): Python CLI · `manage.py`
- [Service configuration](https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/threat_platform/settings.py): Django settings · Configures database, REST, JWT, OpenAPI, static files, and environment loading. · `threat_platform/settings.py`
- [Global routes & JWT](https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/threat_platform/urls.py): Django URL config · Registers API routes and JWT token endpoints. · `threat_platform/urls.py`
- [Users & roles](https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/accounts/models.py): Django models · Custom users carry Admin and Analyst roles. · `accounts/models.py`
- [Privileged admin](https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/accounts/admin.py): Django admin · Separate management interface for users, events, and alerts. · `accounts/admin.py`

### Monitoring Domain

- [Monitoring app startup](https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/monitoring/apps.py): Django app config · Registers monitoring signals during application initialization. · `monitoring/apps.py`
- [Monitoring API routes](https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/monitoring/urls.py): DRF URL config · `monitoring/urls.py`
- [Event & alert API](https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/monitoring/views.py): DRF viewsets · Exposes event ingestion, alert reads, and alert state updates. · `monitoring/views.py`
- [Payload validation](https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/monitoring/serializers.py): DRF serializers · Validates and formats Event and Alert payloads. · `monitoring/serializers.py`
- [Role authorization](https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/monitoring/permissions.py): DRF permissions · Admins write events and mutate alerts; Analysts can read alerts. · `monitoring/permissions.py`
- [Alert query support](https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/monitoring/filters.py): Filters & pagination · Filters alerts by severity/status and applies page boundaries. · `monitoring/filters.py`
- [Events & alerts](https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/monitoring/models.py): Django models · Persistent security events and their generated alerts. · `monitoring/models.py`
- [Severe-event alert rule](https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/monitoring/signals.py): Post-save signal · Creates an OPEN Alert for newly saved HIGH or CRITICAL Events. · `monitoring/signals.py`

### Dashboard UI

- [Dashboard endpoints](https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/monitoring/dashboard_api.py): Django endpoints · Provides demo operations including analyst creation, test events, and alert updates. · `monitoring/dashboard_api.py`
- [Demo dashboard](https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/monitoring/templates/monitoring/dashboard.html): Server-rendered template · `monitoring/templates/monitoring/dashboard.html`

### Runtime & Deployment

- [Production WSGI app](https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/threat_platform/wsgi.py): WSGI · `threat_platform/wsgi.py`
- **PostgreSQL / SQLite**: Relational database · PostgreSQL is selected from DATABASE_URL; SQLite is the local fallback.
- [Render deployment](https://github.com/bilalhassankhan007/threat_monitoring_alert_platform_using_django/blob/main/render.yaml): Deployment config · Builds the service and runs Gunicorn with WhiteNoise static serving. · `render.yaml`

## Connections

- 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
