# renatoalmeidaoliveira/nbrisk architecture

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

- Interactive diagram: https://gitdiagram.com/renatoalmeidaoliveira/nbrisk
- Repository: https://github.com/renatoalmeidaoliveira/nbrisk

## Overview

1. **What this repo is**
   - `nb_risk` is a **NetBox plugin** built as a Django app.
   - It extends NetBox with a risk-management domain inspired by **NIST 800-30**, centered on vulnerabilities, threat sources/events, controls, and risks.

2. **Core domain boundary**
   - The main business logic lives in `nb_risk/models.py` and the migration history under `nb_risk/migrations/`.
   - The repository is organized around a small set of risk entities and their relationships to NetBox assets, especially the “vulnerability assignment” concept that links vulnerabilities to objects in NetBox and to additional configured asset models.

3. **NetBox integration model**
   - This is not a standalone app; it plugs into the existing NetBox UI and object model.
   - `nb_risk/template_content.py` and `nb_risk/navigation.py` indicate that the plugin injects panels and menu entries into NetBox pages rather than replacing NetBox screens.
   - The README’s `PLUGINS_CONFIG['nb_risk']['additional_assets']` setting is an important architectural boundary: the plugin can be extended to support extra asset models beyond the built-in NetBox ones.

4. **User-facing UI layer**
   - The main UI surface is Django-template based, under `nb_risk/templates/nb_risk/`.
   - `nb_risk/views.py` and `nb_risk/custom_views.py` provide the page controllers for list/detail/edit screens.
   - The templates suggest separate views for vulnerability, threat source, threat event, control, and risk pages, plus asset-specific vulnerability listings and assignment workflows.

5. **Presentation helpers and page composition**
   - `nb_risk/tables.py`, `nb_risk/filtersets.py`, `nb_risk/forms.py`, and `nb_risk/columns.py` show a classic NetBox/Django pattern:
     - filters for query narrowing,
     - forms for CRUD and assignment actions,
     - tables and columns for list views,
     - custom page content for object detail screens.
   - This layer is mostly about making the risk data browsable and editable inside NetBox.

6. **REST API subsystem**
   - `nb_risk/api/` contains `serializers.py`, `views.py`, and `urls.py`, so the plugin exposes a REST API in parallel with the HTML UI.
   - The API is likely used for automation and bulk integration, while the UI handles interactive inspection and assignment.

7. **Risk/CVE support modules**
   - `nb_risk/cve.py` and `nb_risk/choices.py` suggest helper logic for CVE/CVSS-related normalization and typed field choices.
   - This means the plugin is not just storing arbitrary notes; it models vulnerability severity/metadata in a structured way that supports scoring and classification.

8. **Model lifecycle and side effects**
   - `nb_risk/signals.py` and `nb_risk/middleware.py` indicate plugin-level hooks beyond simple CRUD.
   - Signals likely keep derived relationships or denormalized views in sync when risk objects or assignments change.
   - Middleware suggests there is some request-scoped behavior needed for the plugin’s interaction with NetBox, though the exact behavior is not visible from the tree alone.

9. **Administration and internal operations**
   - `nb_risk/admin.py` registers models in the Django admin, which is usually used for operational maintenance rather than primary end-user workflows.
   - `nb_risk/urls.py` and `nb_risk/api/urls.py` define the web entry points for the plugin.
   - `nb_risk/version.py` and `setup.py` show it is packaged as a distributable Python package for installation into NetBox.

10. **Development and deployment shape**
   - The `develop/` directory contains Docker-based local development assets (`Dockerfile`, `docker-compose.yml`, environment/config files).
   - This implies the plugin can be tested in a containerized NetBox-like environment, but production use is still as a plugin installed into an existing NetBox deployment.

11. **Testing coverage**
   - Tests are organized by feature area: `vulnerability`, `threatsource`, `vulnerabilityassignment`, and some `control`/custom tests.
   - The presence of API, filter, and view tests shows the main architectural seams are the REST layer, query/filter behavior, and page rendering.

12. **How data flows through the system**
   - Users or API clients create vulnerabilities, threat sources/events, controls, and risks.
   - Those records are linked to NetBox assets through assignment objects and configurable additional asset models.
   - NetBox object pages then render plugin-injected panels and tables showing affected assets, related vulnerabilities, and risk context.

13. **What to draw in an architecture diagram**
   - Show NetBox as the host platform.
   - Inside it, show the `nb_risk` plugin as three major slices:
     - **domain models + migrations**,
     - **UI/template/table/form/filter layers**,
     - **REST API**.
   - Add external/configured NetBox models as connected asset targets, with `additional_assets` as the extension mechanism.

Main entry points: [`nb_risk/__init__.py`](https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/__init__.py) (nb_risk), [`nb_risk/models.py`](https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/models.py) (Models), [`nb_risk/views.py`](https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/views.py) (Views), [`nb_risk/api/views.py`](https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/api/views.py) (API views)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_netbox["NetBox host"]
  node_netbox_platform["NetBox<br/>host platform"]
end

subgraph group_core["Plugin core"]
  node_plugin_root["nb_risk<br/>netbox plugin<br/>[__init__.py]"]
  node_risk_models[("Models<br/>[models.py]")]
  node_risk_migrations["Migrations<br/>schema history<br/>[0001_initial.py]"]
  node_cve_helpers["CVE utils<br/>normalization helpers<br/>[cve.py]"]
  node_choice_defs["Choices<br/>typed enums<br/>[choices.py]"]
  node_signals_hooks["Signals<br/>lifecycle hooks<br/>[signals.py]"]
  node_request_mw["Middleware<br/>request hook<br/>[middleware.py]"]
end

subgraph group_ui["UI layer"]
  node_ui_views["Views<br/>page controllers<br/>[views.py]"]
  node_custom_views["Custom views<br/>specialized pages<br/>[custom_views.py]"]
  node_ui_forms["Forms<br/>[forms.py]"]
  node_ui_filters["Filters<br/>[filtersets.py]"]
  node_ui_tables["Tables<br/>[tables.py]"]
  node_ui_columns["Columns<br/>[columns.py]"]
  node_tpl_content["Panels<br/>template hooks"]
  node_nav_config["Navigation<br/>menu config<br/>[navigation.py]"]
  node_templates["Templates<br/>[vulnerability.html]"]
end

subgraph group_api["REST API"]
  node_api_views["API views<br/>rest endpoints<br/>[views.py]"]
  node_api_serializers["Serializers<br/>api schema<br/>[serializers.py]"]
  node_api_urls["API routes<br/>route map<br/>[urls.py]"]
end

subgraph group_ops["Packaging & dev"]
  node_package_setup["Package<br/>distribution config<br/>[setup.py]"]
  node_dev_env["Dev env<br/>container tooling<br/>[docker-compose.yml]"]
end

node_netbox_platform -->|"hosts"| node_plugin_root
node_plugin_root -->|"defines"| node_risk_models
node_risk_models -->|"evolves via"| node_risk_migrations
node_risk_models -->|"uses"| node_cve_helpers
node_risk_models -->|"uses"| node_choice_defs
node_risk_models -->|"triggers"| node_signals_hooks
node_plugin_root -->|"loads"| node_request_mw
node_plugin_root -->|"exposes"| node_ui_views
node_plugin_root -->|"extends"| node_custom_views
node_ui_views -->|"uses"| node_ui_forms
node_ui_views -->|"uses"| node_ui_filters
node_ui_views -->|"uses"| node_ui_tables
node_ui_tables -->|"uses"| node_ui_columns
node_ui_views -->|"renders"| node_templates
node_tpl_content -->|"injects into"| node_netbox_platform
node_nav_config -->|"adds menu to"| node_netbox_platform
node_plugin_root -->|"registers"| node_tpl_content
node_plugin_root -->|"registers"| node_nav_config
node_plugin_root -->|"exposes"| node_api_urls
node_api_urls -->|"routes to"| node_api_views
node_api_views -->|"uses"| node_api_serializers
node_api_views -->|"reads/writes"| node_risk_models
node_ui_views -->|"reads/writes"| node_risk_models
node_templates -->|"presents"| node_risk_models
node_plugin_root -->|"packaged by"| node_package_setup
node_plugin_root -->|"developed with"| node_dev_env

click node_plugin_root "https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/__init__.py"
click node_risk_models "https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/models.py"
click node_risk_migrations "https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/migrations/0001_initial.py"
click node_cve_helpers "https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/cve.py"
click node_choice_defs "https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/choices.py"
click node_signals_hooks "https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/signals.py"
click node_request_mw "https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/middleware.py"
click node_ui_views "https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/views.py"
click node_custom_views "https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/custom_views.py"
click node_ui_forms "https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/forms.py"
click node_ui_filters "https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/filtersets.py"
click node_ui_tables "https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/tables.py"
click node_ui_columns "https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/columns.py"
click node_tpl_content "https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/template_content.py"
click node_nav_config "https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/navigation.py"
click node_templates "https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/templates/nb_risk/vulnerability.html"
click node_api_views "https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/api/views.py"
click node_api_serializers "https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/api/serializers.py"
click node_api_urls "https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/api/urls.py"
click node_package_setup "https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/setup.py"
click node_dev_env "https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/develop/docker-compose.yml"

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_netbox_platform toneBlue
class node_plugin_root,node_risk_models,node_risk_migrations,node_cve_helpers,node_choice_defs,node_signals_hooks,node_request_mw toneAmber
class node_ui_views,node_custom_views,node_ui_forms,node_ui_filters,node_ui_tables,node_ui_columns,node_tpl_content,node_nav_config,node_templates toneMint
class node_api_views,node_api_serializers,node_api_urls toneRose
class node_package_setup,node_dev_env toneIndigo
```

## Components

### NetBox host

External platform extended by the plugin

- **NetBox**: host platform · Underlying NetBox application and object model

### Plugin core

Domain model, lifecycle hooks, and package entry points

- [nb_risk](https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/__init__.py): netbox plugin · Django plugin that adds risk management to NetBox · `nb_risk/__init__.py`
- [Models](https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/models.py): domain models · Core risk entities and their relationships · `nb_risk/models.py`
- [Migrations](https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/migrations/0001_initial.py): schema history · Database evolution for the risk domain · `nb_risk/migrations/0001_initial.py`
- [CVE utils](https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/cve.py): normalization helpers · CVE and CVSS-related parsing and scoring helpers · `nb_risk/cve.py`
- [Choices](https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/choices.py): typed enums · Shared field choice definitions · `nb_risk/choices.py`
- [Signals](https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/signals.py): lifecycle hooks · Model side effects and relationship maintenance · `nb_risk/signals.py`
- [Middleware](https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/middleware.py): request hook · Request-scoped plugin behavior · `nb_risk/middleware.py`

### UI layer

HTML views, tables, forms, filters, and injected panels

- [Views](https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/views.py): page controllers · List, detail, and edit screen controllers · `nb_risk/views.py`
- [Custom views](https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/custom_views.py): specialized pages · Nonstandard workflow and composite page logic · `nb_risk/custom_views.py`
- [Forms](https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/forms.py): edit forms · CRUD and assignment form definitions · `nb_risk/forms.py`
- [Filters](https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/filtersets.py): query filters · Search and narrowing logic for list views · `nb_risk/filtersets.py`
- [Tables](https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/tables.py): list tables · Tabular list-view composition · `nb_risk/tables.py`
- [Columns](https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/columns.py): table columns · Custom table column definitions · `nb_risk/columns.py`
- [Panels](https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/template_content.py): template hooks · NetBox page content injection points · `nb_risk/template_content.py`
- [Navigation](https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/navigation.py): menu config · Plugin menu and navigation entries · `nb_risk/navigation.py`
- [Templates](https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/templates/nb_risk/vulnerability.html): django templates · HTML templates for risk pages and embedded panels · `nb_risk/templates/nb_risk/vulnerability.html`

### REST API

Automation-facing JSON API

- [API views](https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/api/views.py): rest endpoints · REST resource handlers · `nb_risk/api/views.py`
- [Serializers](https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/api/serializers.py): api schema · Object-to-JSON mapping for the REST API · `nb_risk/api/serializers.py`
- [API routes](https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/nb_risk/api/urls.py): route map · REST API URL registration · `nb_risk/api/urls.py`

### Packaging & dev

Distribution metadata and local development tooling

- [Package](https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/setup.py): distribution config · Python package build and installation metadata · `setup.py`
- [Dev env](https://github.com/renatoalmeidaoliveira/nbrisk/blob/NetBox_v4.1/develop/docker-compose.yml): container tooling · Docker-based local development environment · `develop/docker-compose.yml`

## Connections

- NetBox → nb_risk: hosts · NetBox loads the plugin into its app and object model
- nb_risk → Models: defines · Core domain entities live in the plugin models
- Models → Migrations: evolves via · Schema changes are captured in migrations
- Models → CVE utils: uses · Vulnerability data is normalized and scored with CVE helpers
- Models → Choices: uses · Models share typed choice values
- Models → Signals: triggers · Model changes can emit side effects and sync relationships
- nb_risk → Middleware: loads · Plugin-level request behavior is inserted through middleware
- nb_risk → Views: exposes · Primary HTML workflow entry points
- nb_risk → Custom views: extends · Specialized workflows and composite pages
- Views → Forms: uses · Views depend on forms for CRUD and assignment actions
- Views → Filters: uses · List views narrow results through filtersets
- Views → Tables: uses · Views render tabular collections
- Tables → Columns: uses · Tables are composed from reusable columns
- Views → Templates: renders · Page controllers render Django templates
- Panels → NetBox: injects into · Panels are attached to NetBox object pages
- Navigation → NetBox: adds menu to · The plugin contributes navigation entries to NetBox
- nb_risk → Panels: registers · Plugin hooks into NetBox page composition
- nb_risk → Navigation: registers · Plugin exposes its menu structure
- nb_risk → API routes: exposes · REST API routing is part of the plugin surface
- API routes → API views: routes to · API URLs dispatch to resource views
- API views → Serializers: uses · REST views serialize and validate payloads
- API views → Models: reads/writes · API manipulates the core risk domain objects
- Views → Models: reads/writes · HTML workflows operate on the same domain models
- Templates → Models: presents · Templates show vulnerabilities, controls, risks, and assignments
- nb_risk → Package: packaged by · The plugin is distributed as a Python package
- nb_risk → Dev env: developed with · Local Docker tooling supports plugin development
