# andrewdea/zhongwen architecture

> Architecture diagram of the GitHub repository andrewdea/zhongwen, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2024-12-28). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/andrewdea/zhongwen
- Repository: https://github.com/andrewdea/zhongwen

## Overview

##### Main Components

a. Browser Extension Components:
- Background Service (background.js)
- Content Script Layer (content.js)
- User Interface Components
- Popup Dictionary Window
- Options Page
- Word List Interface
- Help Page

b. Data Storage:
- Dictionary Data Store (cedict.ts.u8)
- Dictionary Index (cedict.idx)
- Grammar Keywords (grammarKeywordsMin.json)
- Vocabulary Keywords (vocabularyKeywordsMin.json)

c. External Services Integration:
- Chinese Grammar Wiki
- Online Dictionaries (LINE Dict, Forvo, Dict.cn, etc.)
- Skritter Integration
- Tatoeba

##### Component Relationships

- Background Service ↔ Content Script (bi-directional communication)
- Content Script → UI Components (controls popup display)
- Background Service → Data Storage (dictionary lookups)
- UI Components → External Services (integration points)

##### Flow Representation

Following key flows:
**User Interaction → Content Script → Dictionary Lookup → Popup Display**
**User Settings → Background Service → Content Script Configuration**
**Word List Management → Local Storage → Export Functionality**

##### Specific Implementation Details

Technical aspects:
- CSS styling system (css/content.css, css/wordlist.css)
- Zhuyin support module (js/zhuyin.js)
- Options management (js/options.js)
- Word list functionality (js/wordlist.js)

##### Key Integration Points

Integration capabilities:
- Text selection and hover detection
- Keyboard shortcut system
- External dictionary services
- Export functionality (Anki, Skritter)

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Core["Core Extension Components"]
        BG[Background Service]
        CS[Content Script Layer]
        DP[Dictionary Processing]
    end

    subgraph UI["User Interface Layer"]
        direction TB
        POP[Popup Dictionary Window]
        OPT[Options Page]
        WL[Word List Interface]
        HELP[Help Page]
    end

    subgraph Data["Data Storage"]
        direction TB
        DICT[(Dictionary Data)]
        IDX[(Dictionary Index)]
        GRAM[(Grammar Keywords)]
        VOC[(Vocabulary Keywords)]
    end

    subgraph External["External Services"]
        direction TB
        WIKI[Chinese Grammar Wiki]
        DICT_SERVICES[Online Dictionaries]
        SKR[Skritter]
        TAT[Tatoeba]
    end

    BG <--> CS
    CS --> POP
    CS --> DP
    DP --> Data
    UI --> External

    %% Component Mappings
    click BG "https://github.com/andrewdea/zhongwen/blob/master/background.js"
    click CS "https://github.com/andrewdea/zhongwen/blob/master/content.js"
    click DP "https://github.com/andrewdea/zhongwen/blob/master/dict.js"
    click OPT "https://github.com/andrewdea/zhongwen/blob/master/options.html"
    click WL "https://github.com/andrewdea/zhongwen/blob/master/wordlist.html"
    click HELP "https://github.com/andrewdea/zhongwen/blob/master/help.html"
    click DICT "https://github.com/andrewdea/zhongwen/blob/master/data/cedict_ts.u8"
    click IDX "https://github.com/andrewdea/zhongwen/blob/master/data/cedict.idx"
    click GRAM "https://github.com/andrewdea/zhongwen/blob/master/data/grammarKeywordsMin.json"
    click VOC "https://github.com/andrewdea/zhongwen/blob/master/data/vocabularyKeywordsMin.json"

    %% Styling
    classDef core fill:#a8d1f0,stroke:#333
    classDef ui fill:#ffd7a8,stroke:#333
    classDef data fill:#a8e6cf,stroke:#333
    classDef external fill:#e8e8e8,stroke:#333

    class BG,CS,DP core
    class POP,OPT,WL,HELP ui
    class DICT,IDX,GRAM,VOC data
    class WIKI,DICT_SERVICES,SKR,TAT external

    %% Legend
    subgraph Legend
        C1[Core Components]:::core
        U1[UI Components]:::ui
        D1[Data Storage]:::data
        E1[External Services]:::external
    end
```
