# hoangtrung1801/filter-for-kids-extension architecture

> Architecture diagram of the GitHub repository hoangtrung1801/filter-for-kids-extension, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-01-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hoangtrung1801/filter-for-kids-extension
- Repository: https://github.com/hoangtrung1801/filter-for-kids-extension

## Overview

##### Main Components

a. Browser Extension Components:
- Popup Interface (entry: src/popup.tsx)
- Content Scripts (src/contents/)
- Background Service Worker (src/background.ts)

b. Core Feature Modules:
- Image Processing System (models/)
- NSFW Detection Model
- Violence Detection Model
- Layers Model
- Text Processing System
- Acronym Handler
- Word Replacement System
- Sino Word Handler

c. Supporting Systems:
- Queue System (src/lib/background/queue/)
- DOM Watching System (src/lib/content/DomWatcher.ts)
- Filter System (src/lib/content/filters/)

**┌─ User Interface Layer ─────┐**
- Popup                   │
- Content UI Overlays     │
- Processing Layer ─────────┤
- Content Scripts         │
- Background Worker       │
- Core Services Layer ──────┤
- ML Models              │
- Text Processing        │
- Queue Management       │
- ┘

##### Key Relationships to Highlight

a. Data Flow:
- Interaction between DOM Watcher and content filters
- ML model processing pipeline

b. Component Integration:
- How the Queue system manages processing requests
- How filters interact with ML models
- Demonstrate popup interface connections to background services

##### Technical Details

- TensorFlow.js Model Integration
- React Components for UI
- Background Worker Architecture
- Content Script Injection Points

##### Implementation Notes

- Rectangles: Core components
- Hexagons: Processing units
- Rounded rectangles: UI elements

##### User interaction (Popup and overlays)

- Abbreviations used

Keep the abstraction level focused on the architectural components while showing the relationship between the extension's various systems. This will help other developers understand both the high-level structure and the specific implementation details of the extension.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and Classes
    classDef ui fill:#3498db,stroke:#2980b9,color:white
    classDef processing fill:#2ecc71,stroke:#27ae60,color:white
    classDef model fill:#f1c40f,stroke:#f39c12,color:black
    classDef queue fill:#9b59b6,stroke:#8e44ad,color:white
    classDef filter fill:#e74c3c,stroke:#c0392b,color:white
    classDef asset fill:#95a5a6,stroke:#7f8c8d,color:white

    %% User Interface Layer
    subgraph UI
        Popup["Popup Interface"]:::ui
        ContentUI["Content UI Overlays"]:::ui
    end

    %% Processing Layer
    subgraph Processing
        ContentScripts["Content Scripts"]:::processing
        BackgroundWorker["Background Service Worker"]:::processing
        DOMWatcher["DOM Watching System"]:::processing
    end

    %% Core Services Layer
    subgraph CoreServices
        %% ML Models
        subgraph MLModels
            NSFWModel["NSFW Detection"]:::model
            ViolenceModel["Violence Detection"]:::model
            LayersModel["Layers Model"]:::model
        end

        %% Text Processing
        subgraph TextProcessing
            AcronymHandler["Acronym Handler"]:::processing
            WordReplacement["Word Replacement"]:::processing
            SinoHandler["Sino Word Handler"]:::processing
        end

        %% Queue System
        QueueSystem["Queue System"]:::queue
    end

    %% Filter System
    subgraph Filters
        ImageFilter["Image Filter"]:::filter
        TextFilter["Text Filter"]:::filter
    end

    %% Assets
    subgraph Assets
        BadWords["Bad Words Dict"]:::asset
        AcronymDict["Acronym Dict"]:::asset
        HanVietDict["Han-Viet Dict"]:::asset
        WordDict["Word Dict"]:::asset
    end

    %% Relationships
    Popup --> BackgroundWorker
    ContentUI --> ContentScripts
    ContentScripts --> BackgroundWorker
    DOMWatcher --> ContentScripts
    BackgroundWorker --> QueueSystem
    QueueSystem --> MLModels
    QueueSystem --> TextProcessing
    ImageFilter --> MLModels
    TextFilter --> TextProcessing
    TextProcessing --> Assets
    ContentScripts --> Filters

    %% Click Events
    click Popup "https://github.com/hoangtrung1801/filter-for-kids-extension/blob/master/src/popup.tsx"
    click ContentScripts "https://github.com/hoangtrung1801/filter-for-kids-extension/tree/master/src/contents/"
    click BackgroundWorker "https://github.com/hoangtrung1801/filter-for-kids-extension/blob/master/src/background.ts"
    click NSFWModel "https://github.com/hoangtrung1801/filter-for-kids-extension/tree/master/models/nsfw-mobilenet/"
    click ViolenceModel "https://github.com/hoangtrung1801/filter-for-kids-extension/tree/master/models/violence-model/"
    click LayersModel "https://github.com/hoangtrung1801/filter-for-kids-extension/tree/master/models/layers-model/"
    click AcronymHandler "https://github.com/hoangtrung1801/filter-for-kids-extension/blob/master/src/lib/content/text/acronymResult.tsx"
    click WordReplacement "https://github.com/hoangtrung1801/filter-for-kids-extension/blob/master/src/contents/replace-words.ts"
    click SinoHandler "https://github.com/hoangtrung1801/filter-for-kids-extension/blob/master/src/lib/content/text/sinowordResult.tsx"
    click QueueSystem "https://github.com/hoangtrung1801/filter-for-kids-extension/tree/master/src/lib/background/queue/"
    click DOMWatcher "https://github.com/hoangtrung1801/filter-for-kids-extension/blob/master/src/lib/content/DomWatcher.ts"
    click ImageFilter "https://github.com/hoangtrung1801/filter-for-kids-extension/blob/master/src/lib/content/filters/ImageFilter.ts"
    click BadWords "https://github.com/hoangtrung1801/filter-for-kids-extension/blob/master/assets/bad_words.json"
    click AcronymDict "https://github.com/hoangtrung1801/filter-for-kids-extension/blob/master/assets/dict_acronym.json"
    click HanVietDict "https://github.com/hoangtrung1801/filter-for-kids-extension/blob/master/assets/hanviet.json"
    click WordDict "https://github.com/hoangtrung1801/filter-for-kids-extension/blob/master/assets/word.json"

    %% Legend
    subgraph Legend
        UI_L["UI Components"]:::ui
        Processing_L["Processing Components"]:::processing
        Model_L["ML Models"]:::model
        Queue_L["Queue Systems"]:::queue
        Filter_L["Filters"]:::filter
        Asset_L["Assets"]:::asset
    end
```
