# rikilele/custom-dict-chrome architecture

> Architecture diagram of the GitHub repository rikilele/custom-dict-chrome, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-02-15). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rikilele/custom-dict-chrome
- Repository: https://github.com/rikilele/custom-dict-chrome

## Overview

##### Main components
- Manifest & Configuration: At the heart of the extension is the manifest.json file. It defines the extension’s permissions, background scripts, content scripts, popups, and settings pages.
- Background Script (background/background.js): This script runs in the background, manages events (such as browser actions or context menu triggers), and communicates with other components.
- Content Script (contentScript/contentScript.js and associated CSS): Injected into web pages to enable the highlighting feature; it detects words on pages and applies the custom definitions.
- Popup UI (popup/popup.html, popup/popup.js): Provides a user interface accessible via the browser toolbar for manual dictionary editing and quick interactions.
- Settings UI (settings/settings.html, settings/settings.js, settings/settings.css): Allows users to further manage their custom dictionary and allowlist.

##### Relationships and interactions
- The manifest.json serves as the extension's blueprint, linking the background script, content script, popup, and settings.
- The background script acts as the central hub that listens for events (like a right-click context menu or interactions from the popup) and passes information or commands between different components.
- The content script interacts directly with the web page. It receives instructions from the background or listens for user selections and then highlights matching words.
- Communication flows between the popup/settings UI and the background script using Chrome’s message-passing system, ensuring that user modifications to the dictionary data are synchronized across the extension.
- The popup and settings pages are independent UI layers that connect to the background script for configuration and data persistence (likely using the Chrome storage API).

##### Important architectural patterns/design principles
- Decoupled, event-driven architecture: The background script handles events and coordinates the interactions, keeping the UI and content script independent.
- Separation of concerns: Each directory encapsulates a specific responsibility (e.g., background processing, content injection, UI rendering), making it easy to extend or modify individual parts.
- A clear division between configuration (manifest), service logic (background), UI components (popup/settings), and page manipulation (content script).

##### Relevant technologies/frameworks
- Chrome Extension API: For managing background tasks, content injection, and messaging.
- Standard web technologies (HTML, CSS, JavaScript): For the user interfaces in popup and settings, and for dynamically modifying webpages via the content script.

## Diagram (Mermaid)

```mermaid
flowchart TD
    Browser["Chrome Browser (Extension API)"]:::browser
    Manifest["Manifest.json"]:::config
    Background["Background Script"]:::service
    Storage["Chrome Storage API"]:::service
    Content["Content Script"]:::service
    Popup["Popup UI"]:::ui
    Settings["Settings UI"]:::ui
    Icons["Icons"]:::asset

    Browser --> Manifest
    Manifest --> Background
    Manifest --> Content
    Manifest --> Popup
    Manifest --> Settings
    Manifest --> Icons

    Background -->|"storesData"| Storage

    Popup -->|"sendsMessage"| Background
    Settings -->|"sendsMessage"| Background
    Background -->|"communicates"| Content
    Content -->|"communicates"| Background

    click Manifest "https://github.com/rikilele/custom-dict-chrome/blob/main/manifest.json"
    click Background "https://github.com/rikilele/custom-dict-chrome/blob/main/background/background.js"
    click Content "https://github.com/rikilele/custom-dict-chrome/blob/main/contentScript/contentScript.js"
    click Popup "https://github.com/rikilele/custom-dict-chrome/blob/main/popup/popup.html"
    click Settings "https://github.com/rikilele/custom-dict-chrome/blob/main/settings/settings.html"
    click Icons "https://github.com/rikilele/custom-dict-chrome/tree/main/icons"

    classDef browser fill:#CCF,stroke:#339,stroke-width:2px;
    classDef config fill:#F9D,stroke:#C66,stroke-width:2px;
    classDef service fill:#CFC,stroke:#393,stroke-width:2px;
    classDef ui fill:#FFD,stroke:#996,stroke-width:2px;
    classDef asset fill:#FCC,stroke:#933,stroke-width:2px;
```
