# dai-mywk/ad-blocker-extension architecture

> Architecture diagram of the GitHub repository dai-mywk/ad-blocker-extension, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-29). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dai-mywk/ad-blocker-extension
- Repository: https://github.com/dai-mywk/ad-blocker-extension

## Overview

##### Main Components
- Manifest (manifest.json): Acts as the configuration file for the extension and defines metadata, permissions, and the required scripts.
- Background Script (background.js): Contains the logic for setting up and enforcing block rules using Chrome’s declarativeNetRequest API.
- Popup Page (popup.html): Provides a simple user interface for the extension (if any additional interaction, though basic as per current file structure).

##### Relationships and Interactions
- The Manifest is the entry point and configuration hub; it registers the background script and the popup page.
- The Background Script is autonomously run by the Chrome runtime, and it interacts with the declarativeNetRequest API to enforce the blocking rules.
- The declarativeNetRequest API (an external Chrome API) is used by the background script to carry out the actual ad blocking.

##### Important Architectural Patterns and Principles
- Modularity: Each file has a clear purpose — configuration (manifest.json), background processing (background.js), and user interface (popup.html).
- Separation of Concerns: The extension separates configuration, functionality, and presentation. The declarativeNetRequest API usage is handled solely within the background script, while the popup handles UI concerns.
- Event-Driven Operation: The background script likely responds to events (like network requests) and applies rules accordingly.

##### Relevant Technologies and Frameworks
- Chrome Extension API: Specifically, the declarativeNetRequest API.
- JavaScript/HTML/CSS: Standard technologies used to implement the background logic and popup interface.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Components in the Extension Core
    MANIFEST["Manifest (manifest.json)"]:::config
    BG["Background Script (background.js)"]:::functionality
    POPUP["Popup Page (popup.html)"]:::ui
    ICONS["Icons (icons/)"]:::asset
    %% External Chrome API
    API["Chrome API: declarativeNetRequest"]:::external

    %% Relationships
    MANIFEST -->|"registers"| BG
    MANIFEST -->|"registers"| POPUP
    MANIFEST -->|"references"| ICONS
    BG -->|"uses"| API

    %% Click Events
    click MANIFEST "https://github.com/dai-mywk/ad-blocker-extension/blob/main/manifest.json"
    click BG "https://github.com/dai-mywk/ad-blocker-extension/blob/main/background.js"
    click POPUP "https://github.com/dai-mywk/ad-blocker-extension/blob/main/popup.html"
    click ICONS "https://github.com/dai-mywk/ad-blocker-extension/tree/main/icons/"

    %% Styles
    classDef config fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef functionality fill:#ccffcc,stroke:#009900,stroke-width:2px;
    classDef ui fill:#cce5ff,stroke:#003399,stroke-width:2px;
    classDef asset fill:#fff2cc,stroke:#b38f00,stroke-width:2px;
    classDef external fill:#f2f2f2,stroke:#666666,stroke-width:2px;
```
