# informed-governance-project/nisinp architecture

> Architecture diagram of the GitHub repository informed-governance-project/nisinp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-10-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/informed-governance-project/nisinp
- Repository: https://github.com/informed-governance-project/nisinp

## Overview

##### Project type and purpose
- NISINP is a full-stack, multi-tenant Django application serving as an Incident Notification Platform for national regulators and Operators of Essential Services (energy, transport, etc.) under NIS 2 regulations.
- It provides web UIs (HTML templates + static JS/CSS), an administrative interface, REST/OpenAPI endpoints, scheduled/background tasks, email notifications, PDF generation, and multi-language support.

##### File structure
- Top-level orchestration:
- docker/ & .github/workflows/ → Docker‐based CI, container builds, docker-compose examples
- celery_worker.py, celery_beat.py → entry points for Celery workers & scheduler
- manage.py, governanceplatform/, incidents/ → core Django project and two main Django apps
- governanceplatform/:
- Core models, middleware, settings, URLs, forms, custom auth backend, signals, management commands, tasks
- Migrations for database schema
- incidents/:
- Models, views, templates, PDF generation, email helpers, tasks, scripts, migrations
- docs/:
- Architecture and OpenAPI spec (openapi.yml), global‐architecture.odg
- static/ & templates/:
- Frontend assets (JS, CSS) and HTML templates (home, admin, widgets)
- Configuration:
- pyproject.toml, package.json / package-lock.json (front-end deps), pytest.ini, .pre-commit-config.yaml
- docker-compose.example.yml, Dockerfile, Apache2 sample config

##### README for additional insights
- Confirms it is part of a larger platform (NC3-LU), uses Django, Celery, OpenAPI, multi-regulations support.
- Points to online documentation (readthedocs) and architecture doc in docs/_static/global‐architecture.odg.

##### Main components
a. Presentation Layer
- Web Browser (users & regulators)
- Static Assets (served by NGINX or Apache)
- HTML Templates (Django)
b. Application Layer
- Web Server / Reverse Proxy (NGINX or Apache2)
- WSGI Server (Gunicorn or uWSGI) hosting Django
- ASGI Server (for async endpoints if any)
- Django Core (governanceplatform app + incidents app)
c. Data Layer
- Relational Database (PostgreSQL or MariaDB)
- Redis/RabbitMQ (Celery broker + result backend)
- File Store (for generated PDFs, user uploads)
d. Background & Scheduling
- Celery Worker (+ concurrency pool)
- Celery Beat Scheduler (periodic tasks)
e. External Services
- Email SMTP Server (for incident notifications & reminders)
- Optional third-party APIs (e.g., regulatory reference data)
f. Development/CI
- GitHub Actions (CI pipelines)
- Docker (local dev & prod containers)
- Management CLI (manage.py, custom commands)

##### Relationships and data flows
- User → NGINX/Apache → Gunicorn → Django views → Database
- Django → Celery Broker → Celery Worker → tasks → Database / Email / PDF store
- Celery Beat → Broker → Worker (periodic jobs)
- Django → SMTP (send emails)
- Browser ← Static assets served by NGINX or Django static files app
- GitHub Actions → build/test Docker images → push to GHCR

##### Architectural patterns and design principles
- Layered architecture: Presentation, Application, Data
- Modular Django apps (governanceplatform vs incidents)
- Separation of concerns: web vs background tasks via Celery
- 12-factor app principles: config via environment, containerized deployment
- Internationalization (i18n) and template-based UI
- API-first mindset: OpenAPI spec in docs/_static

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Client Zone
    subgraph "Client Zone"
        Browser["Web Browser"]:::ui
    end

    %% Edge Zone
    subgraph "Edge Zone"
        Proxy["NGINX/Apache Reverse Proxy"]:::backend
        Static["Static Assets"]:::ui
        Templates["HTML Templates"]:::ui
    end

    %% App Zone
    subgraph "App Zone"
        WSGI["Django WSGI Entry Point"]:::backend
        ASGI["Django ASGI Entry Point"]:::backend
        CoreSettings["Settings & URLs"]:::backend
        GovernanceApp["Core Django Project & Governanceplatform App"]:::backend
        IncidentsApp["Incidents App"]:::backend
    end

    %% Background Zone
    subgraph "Background Zone"
        CeleryWorker["Celery Worker"]:::worker
        CeleryBeat["Celery Beat Scheduler"]:::worker
        GPTasks["Governanceplatform Celery Tasks"]:::worker
        IncTasks["Incidents Celery Tasks"]:::worker
    end

    %% Data Zone
    subgraph "Data Zone"
        Database["Relational Database"]:::infra
        Broker["RabbitMQ/Redis Broker"]:::infra
        FileStore["File Store (PDFs & Uploads)"]:::infra
        GPMigrations["GP Migrations"]:::infra
        IncMigrations["Incidents Migrations"]:::infra
        PDFModule["PDF Generation Module"]:::infra
    end

    %% External Zone
    subgraph "External Zone"
        SMTP["Email SMTP Server"]:::external
        ThirdParty["Third-Party APIs"]:::external
    end

    %% Dev/CI Zone
    subgraph "Dev/CI Zone"
        CI["GitHub Actions"]:::ci
        DockerContainers["Docker & Compose"]:::ci
        CLI["Management CLI & Commands"]:::ci
        APIDoc["OpenAPI Spec"]:::ci
        ArchDoc["Architecture Doc"]:::ci
    end

    %% Connections
    Browser -->|"HTTP(S)"| Proxy
    Proxy -->|"serves"| Static
    Proxy -->|"renders"| Templates
    Proxy -->|"proxies HTTP"| WSGI
    Proxy -->|"proxies HTTP"| ASGI

    WSGI -->|"loads"| CoreSettings
    ASGI -->|"loads"| CoreSettings
    CoreSettings -->|"initializes"| GovernanceApp
    CoreSettings -->|"initializes"| IncidentsApp

    GovernanceApp -->|"SQL"| Database
    IncidentsApp -->|"SQL"| Database
    IncidentsApp -->|"generate PDF"| PDFModule
    PDFModule -->|"store"| FileStore

    GovernanceApp -->|"enqueue AMQP"| Broker
    IncidentsApp -->|"enqueue AMQP"| Broker

    CeleryBeat -->|"schedule AMQP"| Broker
    CeleryWorker -->|"consume AMQP"| Broker
    CeleryWorker -->|"execute"| GPTasks
    CeleryWorker -->|"execute"| IncTasks

    GPTasks -->|"SQL"| Database
    IncTasks -->|"SQL"| Database
    IncTasks -->|"send email via SMTP"| SMTP
    IncTasks -->|"use PDF Module"| PDFModule

    IncidentsApp -->|"send email via SMTP"| SMTP
    IncidentsApp -->|"call API"| ThirdParty

    CI -->|"build/test"| DockerContainers
    DockerContainers -->|"deploy"| Proxy
    DockerContainers -->|"deploy"| WSGI
    DockerContainers -->|"deploy"| CeleryWorker

    CLI -->|"manage"| GovernanceApp
    CLI -->|"manage"| IncidentsApp

    GovernanceApp -->|"docs"| APIDoc
    GovernanceApp -->|"architecture"| ArchDoc

    %% Click Events
    click Static "https://github.com/informed-governance-project/nisinp/tree/master/static/"
    click Templates "https://github.com/informed-governance-project/nisinp/tree/master/templates/"
    click Templates "https://github.com/informed-governance-project/nisinp/tree/master/incidents/templates/"
    click Proxy "https://github.com/informed-governance-project/nisinp/blob/master/docker/apache2-example.conf"
    click WSGI "https://github.com/informed-governance-project/nisinp/blob/master/governanceplatform/wsgi.py"
    click ASGI "https://github.com/informed-governance-project/nisinp/blob/master/governanceplatform/asgi.py"
    click CoreSettings "https://github.com/informed-governance-project/nisinp/blob/master/governanceplatform/settings.py"
    click CoreSettings "https://github.com/informed-governance-project/nisinp/blob/master/governanceplatform/urls.py"
    click GovernanceApp "https://github.com/informed-governance-project/nisinp/tree/master/governanceplatform/"
    click IncidentsApp "https://github.com/informed-governance-project/nisinp/tree/master/incidents/"
    click GPMigrations "https://github.com/informed-governance-project/nisinp/tree/master/governanceplatform/migrations/"
    click IncMigrations "https://github.com/informed-governance-project/nisinp/tree/master/incidents/migrations/"
    click PDFModule "https://github.com/informed-governance-project/nisinp/blob/master/incidents/pdf_generation.py"
    click CeleryWorker "https://github.com/informed-governance-project/nisinp/blob/master/celery_worker.py"
    click CeleryBeat "https://github.com/informed-governance-project/nisinp/blob/master/celery_beat.py"
    click GPTasks "https://github.com/informed-governance-project/nisinp/blob/master/governanceplatform/tasks.py"
    click IncTasks "https://github.com/informed-governance-project/nisinp/blob/master/incidents/tasks.py"
    click SMTP "https://github.com/informed-governance-project/nisinp/blob/master/incidents/email.py"
    click CI "https://github.com/informed-governance-project/nisinp/tree/master/.github/workflows/"
    click DockerContainers "https://github.com/informed-governance-project/nisinp/tree/master/docker/Dockerfile"
    click DockerContainers "https://github.com/informed-governance-project/nisinp/blob/master/docker/docker-compose.example.yml"
    click CLI "https://github.com/informed-governance-project/nisinp/blob/master/manage.py"
    click CLI "https://github.com/informed-governance-project/nisinp/tree/master/governanceplatform/management/commands/"
    click APIDoc "https://github.com/informed-governance-project/nisinp/blob/master/docs/_static/openapi.yml"
    click ArchDoc "https://github.com/informed-governance-project/nisinp/blob/master/docs/_static/global-architecture.odg"

    %% Styles
    classDef ui fill:#bbdefb,stroke:#333,stroke-width:1px
    classDef backend fill:#c8e6c9,stroke:#333,stroke-width:1px
    classDef worker fill:#ffe0b2,stroke:#333,stroke-width:1px
    classDef infra fill:#e0e0e0,stroke:#333,stroke-width:1px
    classDef external fill:#e1bee7,stroke:#333,stroke-width:1px
    classDef ci fill:#d7ccc8,stroke:#333,stroke-width:1px
```
