# marksweb/django-nh3 architecture

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

- Interactive diagram: https://gitdiagram.com/marksweb/django-nh3
- Repository: https://github.com/marksweb/django-nh3

## Overview

django-nh3 integrates the nh3 HTML sanitizer into Django model fields, form fields, and a template filter. Each entry point obtains sanitizer options, cleans HTML, and returns or stores safe output. Model fields sanitize before database writes and mark database values safe when read; the README documents settings-based defaults and per-field overrides. The graph reflects the sampled implementation; integration details beyond the supplied source are omitted.

Main entry points: [`src/django_nh3/models.py`](https://github.com/marksweb/django-nh3/blob/main/src/django_nh3/models.py) (Sanitizing fields), [`src/django_nh3/forms.py`](https://github.com/marksweb/django-nh3/blob/main/src/django_nh3/forms.py) (Sanitizing form field), [`src/django_nh3/templatetags/nh3_tags.py`](https://github.com/marksweb/django-nh3/blob/main/src/django_nh3/templatetags/nh3_tags.py) (nh3 template filter), [`src/django_nh3/utils.py`](https://github.com/marksweb/django-nh3/blob/main/src/django_nh3/utils.py) (Option resolution)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_configuration["Configuration and checks"]
  node_app_config["App registration<br/>[apps.py]"]
  node_checks["Security check<br/>[checks.py]"]
  node_options["Option resolution<br/>[utils.py]"]
end

subgraph group_model["Model fields"]
  node_model_fields["Sanitizing fields<br/>[models.py]"]
end

subgraph group_forms["Form sanitization"]
  node_form_field["Sanitizing form field<br/>[forms.py]"]
end

subgraph group_templates["Template sanitization"]
  node_template_filter["nh3 template filter<br/>[nh3_tags.py]"]
end

node_developer(("Application developer"))
node_html["HTML content"]
node_django_settings["Django settings"]
node_nh3{{"nh3 sanitizer"}}
node_database[("Django database")]
node_safe_output["Safe HTML output"]

node_developer -->|"configures"| node_django_settings
node_django_settings -->|"provides defaults"| node_options
node_django_settings -->|"supplies settings"| node_checks
node_app_config -->|"registers"| node_checks
node_model_fields -->|"resolves options"| node_options
node_form_field -->|"resolves options"| node_options
node_template_filter -->|"resolves defaults"| node_options
node_html -->|"sets field value"| node_model_fields
node_model_fields -->|"sanitizes before save"| node_nh3
node_model_fields -->|"writes cleaned value"| node_database
node_database -->|"returns stored value"| node_model_fields
node_model_fields -->|"marks safe"| node_safe_output
node_html -->|"supplies form value"| node_form_field
node_form_field -->|"cleans value"| node_nh3
node_form_field -->|"returns safe value"| node_safe_output
node_html -->|"supplies template value"| node_template_filter
node_template_filter -->|"cleans value"| node_nh3
node_template_filter -->|"marks safe"| node_safe_output

click node_app_config "https://github.com/marksweb/django-nh3/blob/main/src/django_nh3/apps.py"
click node_checks "https://github.com/marksweb/django-nh3/blob/main/src/django_nh3/checks.py"
click node_options "https://github.com/marksweb/django-nh3/blob/main/src/django_nh3/utils.py"
click node_model_fields "https://github.com/marksweb/django-nh3/blob/main/src/django_nh3/models.py"
click node_form_field "https://github.com/marksweb/django-nh3/blob/main/src/django_nh3/forms.py"
click node_template_filter "https://github.com/marksweb/django-nh3/blob/main/src/django_nh3/templatetags/nh3_tags.py"

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_app_config,node_checks,node_options toneBlue
class node_model_fields,node_database toneAmber
class node_form_field toneMint
class node_template_filter toneRose
class node_developer,node_html,node_django_settings,node_nh3,node_safe_output toneIndigo
```

## Components

### Configuration and checks

- [App registration](https://github.com/marksweb/django-nh3/blob/main/src/django_nh3/apps.py): `src/django_nh3/apps.py`
- [Security check](https://github.com/marksweb/django-nh3/blob/main/src/django_nh3/checks.py): `src/django_nh3/checks.py`
- [Option resolution](https://github.com/marksweb/django-nh3/blob/main/src/django_nh3/utils.py): `src/django_nh3/utils.py`

### Model fields

- [Sanitizing fields](https://github.com/marksweb/django-nh3/blob/main/src/django_nh3/models.py): `src/django_nh3/models.py`

### Form sanitization

- [Sanitizing form field](https://github.com/marksweb/django-nh3/blob/main/src/django_nh3/forms.py): `src/django_nh3/forms.py`

### Template sanitization

- [nh3 template filter](https://github.com/marksweb/django-nh3/blob/main/src/django_nh3/templatetags/nh3_tags.py): `src/django_nh3/templatetags/nh3_tags.py`

### Other components

- **Application developer**
- **HTML content**
- **Django settings**
- **nh3 sanitizer**
- **Django database**
- **Safe HTML output**

## Connections

- Application developer → Django settings: configures
- Django settings → Option resolution: provides defaults
- Django settings → Security check: supplies settings
- App registration → Security check: registers
- Sanitizing fields → Option resolution: resolves options
- Sanitizing form field → Option resolution: resolves options
- nh3 template filter → Option resolution: resolves defaults
- HTML content → Sanitizing fields: sets field value
- Sanitizing fields → nh3 sanitizer: sanitizes before save
- Sanitizing fields → Django database: writes cleaned value
- Django database → Sanitizing fields: returns stored value
- Sanitizing fields → Safe HTML output: marks safe
- HTML content → Sanitizing form field: supplies form value
- Sanitizing form field → nh3 sanitizer: cleans value
- Sanitizing form field → Safe HTML output: returns safe value
- HTML content → nh3 template filter: supplies template value
- nh3 template filter → nh3 sanitizer: cleans value
- nh3 template filter → Safe HTML output: marks safe
