# obuchiyuki/gittohabu architecture

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

- Interactive diagram: https://gitdiagram.com/obuchiyuki/gittohabu
- Repository: https://github.com/obuchiyuki/gittohabu

## Overview

##### Project type and purpose
- This is a browser (Chrome) extension whose sole function is to Japanese-localize the GitHub UI. It injects translation logic into GitHub pages (content scripts), offers a popup UI for on-demand translation and enabling/disabling, and provides an options page for API-key configuration.

##### File structure
- manifest.json
- Defines extension metadata, permissions (tabs, storage, host permissions for github.com), and entry points (content scripts, popup page, options page).
- content.js + dictionary.js
- The “content” component that runs in the context of every GitHub page.
- Loads the built-in dictionary (dictionary.js), observes & replaces UI text, and conditionally calls external translation APIs.
- popup.html + popup.js
- Browser-action (toolbar) UI that lets the user trigger an immediate translation pass and toggle the extension on/off.
- options.html + options.css + options.js
- Options page where the user enters API-keys and toggles “use external API” on/off. Settings are stored via chrome.storage.
- Static assets for the extension’s toolbar and options UI.
- README.md
- Confirms project flow: injection → dictionary replace → optional API call → DOM patch.

##### README for architectural hints
- Confirms use cases (auto-translate, manual translate via popup, enable/disable via Alt+J).
- Mentions privacy boundaries (chrome.storage + external API).
- Notes runtime environment: SPA GitHub DOM changes, so content.js likely uses a MutationObserver.

a. Main components
- Browser (Chrome)
- Manifest (static config)
- Content Script (content.js + dictionary.js)
- Extension UI:
– Popup (popup.html/js)
– Options Page (options.html/css/js)
- Storage (chrome.storage.sync or local)
- External Translation Services (DeepL, Google Cloud, Azure)
b. Relationships and interactions
- Browser reads manifest.json and injects content.js into GitHub pages.
- Content script loads dictionary, observes DOM changes, and replaces text.
- If “external API” is enabled, content script issues HTTP requests to the chosen translation provider.
- Popup sends messages (chrome.runtime.sendMessage) to content script to trigger manual translation or toggle.
- Options page reads/writes user settings (API keys, toggles) into chrome.storage.
- Content script retrieves settings from chrome.storage when it initializes or whenever a toggle occurs.
c. Architectural patterns/design principles
- Event-driven: content script reacts to page load, DOM mutations, and messages from popup/options.
- Separation of concerns: translation logic (dictionary.js + API calls) is decoupled from UI (popup/options).
- State persistence via chrome.storage.
d. Key technologies, frameworks, or libraries
- Chrome Extension APIs (tabs, runtime, storage)
- Fetch or XHR for HTTP calls to translation services
- MutationObserver for dynamic SPA handling
- Plain JavaScript, HTML, CSS (no front-end frameworks)

## Diagram (Mermaid)

```mermaid
flowchart TD
    Manifest["Manifest (manifest.json)"]:::config
    Browser["Browser (Chrome)"]:::runtime
    Manifest -->|"defines and injects"| Browser
    Browser -->|"loads on github.com"| GitHubPage["GitHub Page Context"]:::runtime

    subgraph "Content Script"
        ContentScript["content.js\n(MutationObserver)"]:::runtime
        Dictionary["dictionary.js"]:::runtime
    end

    GitHubPage --> ContentScript
    ContentScript --> Dictionary
    Dictionary -->|"provides terms"| ContentScript
    ContentScript -->|"read/write settings"| Storage[(chrome.storage)]:::config
    ContentScript -->|"if external API enabled"| ExternalAPI["Translation API"]:::external

    subgraph "Popup UI"
        PopupHTML["popup.html"]:::ui
        PopupJS["popup.js"]:::ui
    end

    PopupHTML --> PopupJS
    PopupJS -->|"sendMessage"| ContentScript
    PopupJS --> Storage

    subgraph "Options UI"
        OptionsHTML["options.html"]:::ui
        OptionsCSS["options.css"]:::ui
        OptionsJS["options.js"]:::ui
    end

    OptionsHTML --> OptionsCSS
    OptionsHTML --> OptionsJS
    OptionsJS --> Storage

    Storage -->|"sync settings"| ContentScript

    subgraph "External Translation Services"
        DeepL["DeepL"]:::external
        Google["Google Cloud Translate"]:::external
        Azure["Azure Translator"]:::external
    end

    ExternalAPI --> DeepL
    ExternalAPI --> Google
    ExternalAPI --> Azure

    classDef ui fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef runtime fill:#d4edda,stroke:#333,stroke-width:1px
    classDef config fill:#fff3cd,stroke:#333,stroke-width:1px
    classDef external fill:#ffe5b4,stroke:#333,stroke-width:1px

    click Manifest "https://github.com/obuchiyuki/gittohabu/blob/main/manifest.json"
    click ContentScript "https://github.com/obuchiyuki/gittohabu/blob/main/content.js"
    click Dictionary "https://github.com/obuchiyuki/gittohabu/blob/main/dictionary.js"
    click PopupHTML "https://github.com/obuchiyuki/gittohabu/blob/main/popup.html"
    click PopupJS "https://github.com/obuchiyuki/gittohabu/blob/main/popup.js"
    click OptionsHTML "https://github.com/obuchiyuki/gittohabu/blob/main/options.html"
    click OptionsCSS "https://github.com/obuchiyuki/gittohabu/blob/main/options.css"
    click OptionsJS "https://github.com/obuchiyuki/gittohabu/blob/main/options.js"
    click icons "https://github.com/obuchiyuki/gittohabu/tree/main/icons/"
    click README "https://github.com/obuchiyuki/gittohabu/blob/main/README.md"
```
