# avr1i/nsfw-blocker-extension architecture

> Architecture diagram of the GitHub repository avr1i/nsfw-blocker-extension, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/avr1i/nsfw-blocker-extension
- Repository: https://github.com/avr1i/nsfw-blocker-extension

## Overview

NSFW Defender is a client-side Chromium extension for YouTube. The user enables monitoring in the popup; its messages toggle the content script, which periodically captures video frames, classifies them with the bundled model, and blurs or restores the video. The README also documents manifest-based page injection and TensorFlow.js. The sampled source shows the popup messaging and content-script loop; other wiring and library details are supported only by the README, so the graph does not infer additional calls.

Main entry points: [`EXTENSION/contents.js`](https://github.com/avr1i/nsfw-blocker-extension/blob/main/EXTENSION/contents.js) (NSFW classification), [`EXTENSION/extension.html`](https://github.com/avr1i/nsfw-blocker-extension/blob/main/EXTENSION/extension.html) (Popup controls), [`EXTENSION/popup.js`](https://github.com/avr1i/nsfw-blocker-extension/blob/main/EXTENSION/popup.js) (Toggle messaging), [`EXTENSION/Model/model.json`](https://github.com/avr1i/nsfw-blocker-extension/blob/main/EXTENSION/Model/model.json) (Classification model)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interface["User interface"]
  node_popup["Popup controls<br/>[extension.html]"]
  node_popup_logic["Toggle messaging<br/>[popup.js]"]
end

subgraph group_detection["Video detection"]
  node_content["Content script<br/>[contents.js]"]
  node_capture["Frame capture<br/>[contents.js]"]
  node_classifier["NSFW classification<br/>[contents.js]"]
  node_model["Classification model<br/>[model.json]"]
  node_weights["Model weights"]
  node_blur["Video blur<br/>[contents.js]"]
end

subgraph group_runtime["Extension runtime"]
  node_manifest["Page injection config<br/>[manifest.json]"]
  node_tf["TensorFlow.js runtime<br/>[tf.js]"]
end

node_user(("Extension user"))
node_youtube["YouTube video page"]

node_user -->|"opens"| node_popup
node_popup -->|"uses"| node_popup_logic
node_popup_logic -->|"sends toggles"| node_content
node_manifest -->|"injects on YouTube"| node_content
node_youtube -->|"hosts"| node_content
node_content -->|"runs periodically"| node_capture
node_capture -->|"classifies frame"| node_classifier
node_classifier -->|"loads and classifies with"| node_model
node_model -.->|"uses weights"| node_weights
node_classifier -.->|"uses runtime"| node_tf
node_classifier -->|"sets blur state"| node_blur
node_blur -->|"blurs video"| node_youtube

click node_popup "https://github.com/avr1i/nsfw-blocker-extension/blob/main/EXTENSION/extension.html"
click node_popup_logic "https://github.com/avr1i/nsfw-blocker-extension/blob/main/EXTENSION/popup.js"
click node_manifest "https://github.com/avr1i/nsfw-blocker-extension/blob/main/EXTENSION/manifest.json"
click node_content "https://github.com/avr1i/nsfw-blocker-extension/blob/main/EXTENSION/contents.js"
click node_capture "https://github.com/avr1i/nsfw-blocker-extension/blob/main/EXTENSION/contents.js"
click node_classifier "https://github.com/avr1i/nsfw-blocker-extension/blob/main/EXTENSION/contents.js"
click node_model "https://github.com/avr1i/nsfw-blocker-extension/blob/main/EXTENSION/Model/model.json"
click node_weights "https://github.com/avr1i/nsfw-blocker-extension/blob/main/EXTENSION/Model/group1-shard1of1"
click node_blur "https://github.com/avr1i/nsfw-blocker-extension/blob/main/EXTENSION/contents.js"
click node_tf "https://github.com/avr1i/nsfw-blocker-extension/blob/main/EXTENSION/tf.js"

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_popup,node_popup_logic,node_user toneBlue
class node_content,node_capture,node_classifier,node_model,node_weights,node_blur toneAmber
class node_manifest,node_tf toneMint
class node_youtube toneIndigo
```

## Components

### User interface

- [Popup controls](https://github.com/avr1i/nsfw-blocker-extension/blob/main/EXTENSION/extension.html): `EXTENSION/extension.html`
- [Toggle messaging](https://github.com/avr1i/nsfw-blocker-extension/blob/main/EXTENSION/popup.js): `EXTENSION/popup.js`

### Video detection

- [Content script](https://github.com/avr1i/nsfw-blocker-extension/blob/main/EXTENSION/contents.js): `EXTENSION/contents.js`
- [Frame capture](https://github.com/avr1i/nsfw-blocker-extension/blob/main/EXTENSION/contents.js): `EXTENSION/contents.js`
- [NSFW classification](https://github.com/avr1i/nsfw-blocker-extension/blob/main/EXTENSION/contents.js): `EXTENSION/contents.js`
- [Classification model](https://github.com/avr1i/nsfw-blocker-extension/blob/main/EXTENSION/Model/model.json): `EXTENSION/Model/model.json`
- [Model weights](https://github.com/avr1i/nsfw-blocker-extension/blob/main/EXTENSION/Model/group1-shard1of1): `EXTENSION/Model/group1-shard1of1`
- [Video blur](https://github.com/avr1i/nsfw-blocker-extension/blob/main/EXTENSION/contents.js): `EXTENSION/contents.js`

### Extension runtime

- [Page injection config](https://github.com/avr1i/nsfw-blocker-extension/blob/main/EXTENSION/manifest.json): `EXTENSION/manifest.json`
- [TensorFlow.js runtime](https://github.com/avr1i/nsfw-blocker-extension/blob/main/EXTENSION/tf.js): `EXTENSION/tf.js`

### Other components

- **Extension user**
- **YouTube video page**

## Connections

- Extension user → Popup controls: opens (evidence: `README.md`)
- Popup controls → Toggle messaging: uses (evidence: `README.md`)
- Toggle messaging → Content script: sends toggles (evidence: `EXTENSION/popup.js`)
- Page injection config → Content script: injects on YouTube (evidence: `README.md`)
- YouTube video page → Content script: hosts (evidence: `README.md`)
- Content script → Frame capture: runs periodically (evidence: `EXTENSION/contents.js`)
- Frame capture → NSFW classification: classifies frame (evidence: `EXTENSION/contents.js`)
- NSFW classification → Classification model: loads and classifies with (evidence: `EXTENSION/contents.js`)
- Classification model → Model weights: uses weights
- NSFW classification → TensorFlow.js runtime: uses runtime
- NSFW classification → Video blur: sets blur state (evidence: `EXTENSION/contents.js`)
- Video blur → YouTube video page: blurs video (evidence: `EXTENSION/contents.js`)
