# dreuxx/grammar-checker-v1 architecture

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

- Interactive diagram: https://gitdiagram.com/dreuxx/grammar-checker-v1
- Repository: https://github.com/dreuxx/grammar-checker-v1

## Overview

##### Project type and purpose
- This is a Chrome browser extension (“Grammar Checker”) that provides in‐browser grammar and spelling correction for user‐selected text. It uses the OpenAI API as an external service for natural language processing.

##### File structure
- manifest.json: Declares extension metadata, permissions (e.g., storage, activeTab), background scripts, content scripts, UI pages.
- background.js: Runs in the extension’s background context (service worker), handles installation events, stores/retrieves the API key in Chrome storage, mediates communication between UI and content scripts.
- content.js: Injected into web pages, handles text selection, underlines errors in page, listens for messages from popup or background to highlight suggestions.
- options.html & options.js: The settings page where the user enters and saves their OpenAI API key (persisted in Chrome storage).
- styles.css: Shared CSS for popup.html and possibly for injected highlights.

##### README for additional insights
- Confirms the API‐driven grammar correction workflow: detect language, send text to OpenAI, parse suggestions.
- Highlights major features: multi-language support, error highlighting without modifying original text, secure storage of API key.

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph "Chrome Browser"
        direction TB
        Manifest["Manifest Metadata"]:::config
        subgraph "Extension Components"
            direction TB
            BG["Background Service Worker"]:::background
            CSP["Content Script Injector"]:::content
            subgraph "Popup UI"
                direction TB
                PopupHTML["popup.html"]:::ui
                PopupJS["popup.js"]:::ui
            end
            subgraph "Options UI"
                direction TB
                OptionsHTML["options.html"]:::ui
                OptionsJS["options.js"]:::ui
            end
            Storage[(Chrome Storage)]:::storage
            Styles["Shared Stylesheet"]:::asset
            Images["UI Icons"]:::asset
        end
    end

    OpenAI[(OpenAI API)]:::external

    %% Interactions
    Manifest --> BG
    Manifest --> CSP
    Manifest --> PopupHTML
    Manifest --> OptionsHTML
    Manifest --> Styles
    Manifest --> Images

    PopupHTML --> Styles
    OptionsHTML --> Styles

    PopupHTML --> PopupJS
    OptionsHTML --> OptionsJS

    PopupJS -->|checkGrammar request| BG
    BG -->|get/set API key| Storage
    OptionsJS -->|save API key| Storage

    BG -->|HTTP POST| OpenAI
    OpenAI -->|JSON response| BG

    BG -->|suggestions| PopupJS
    PopupJS -->|highlight commands| CSP

    CSP --> Styles

    %% Click Events
    click Manifest "https://github.com/dreuxx/grammar-checker-v1/blob/main/manifest.json"
    click BG "https://github.com/dreuxx/grammar-checker-v1/blob/main/background.js"
    click CSP "https://github.com/dreuxx/grammar-checker-v1/blob/main/content.js"
    click PopupHTML "https://github.com/dreuxx/grammar-checker-v1/blob/main/popup.html"
    click PopupJS "https://github.com/dreuxx/grammar-checker-v1/blob/main/popup.js"
    click OptionsHTML "https://github.com/dreuxx/grammar-checker-v1/blob/main/options.html"
    click OptionsJS "https://github.com/dreuxx/grammar-checker-v1/blob/main/options.js"
    click Styles "https://github.com/dreuxx/grammar-checker-v1/blob/main/styles.css"
    click Images "https://github.com/dreuxx/grammar-checker-v1/tree/main/images/"

    %% Styles
    classDef ui fill:#D0E8FF,stroke:#0366D6
    classDef background fill:#E6F4EA,stroke:#22863A
    classDef content fill:#FFEFD5,stroke:#E36209
    classDef storage fill:#F0F0F0,stroke:#666
    classDef external fill:#FDECEA,stroke:#D73A49
    classDef config fill:#FEEFB3,stroke:#BF8700
    classDef asset fill:#F5F5F5,stroke:#444
```
