# fatehzid/gapray architecture

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

- Interactive diagram: https://gitdiagram.com/fatehzid/gapray
- Repository: https://github.com/fatehzid/gapray

## Overview

GapRay is a local Chrome extension for inspecting webpage layout directly on the page. Users activate it from the toolbar or shortcut, then hover, click, drag, or use Alt-hover to inspect geometry and computed styles; displayed values can be copied. The implementation centers on a content script that coordinates page interaction and overlay rendering, with popup, settings, shortcut lookup, and background dispatch around it. The content-script excerpt is partial, so internal feature links reflect only shown calls and documented behavior.

Main entry points: [`extension/popup.js`](https://github.com/fatehzid/gapray/blob/main/extension/popup.js) (Toolbar popup), [`extension/content.js`](https://github.com/fatehzid/gapray/blob/main/extension/content.js) (Content-script coordinator), [`extension/background.js`](https://github.com/fatehzid/gapray/blob/main/extension/background.js) (Background dispatcher), [`extension/settings.js`](https://github.com/fatehzid/gapray/blob/main/extension/settings.js) (Settings page)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_activation["Activation and settings"]
  node_popup["Toolbar popup<br/>[popup.js]"]
  node_settings["Settings page<br/>[settings.js]"]
  node_shortcut["Shortcut lookup<br/>[commands.js]"]
  node_dispatcher["Background dispatcher<br/>[background.js]"]
end

subgraph group_inspection["Page inspection"]
  node_content["Content-script coordinator<br/>[content.js]"]
  node_selection["Selection and hover<br/>[content.js]"]
  node_measurement["Geometry and styles<br/>[content.js]"]
  node_distance["Distance measurement<br/>[content.js]"]
end

subgraph group_presentation["Overlay and results"]
  node_overlay["Overlay rendering<br/>[content.js]"]
  node_cards["Inspection cards<br/>[content.js]"]
  node_copy["Copy and feedback<br/>[content.js]"]
end

node_user(("User"))
node_chrome["Chrome APIs"]
node_page["Active webpage"]

node_user -->|"opens"| node_popup
node_user -->|"inspects"| node_page
node_popup -->|"reads shortcut"| node_shortcut
node_settings -->|"reads shortcut"| node_shortcut
node_popup -->|"queries tab"| node_chrome
node_settings -->|"opens shortcuts"| node_chrome
node_popup -->|"sends toggle"| node_dispatcher
node_dispatcher -->|"injects script"| node_chrome
node_dispatcher -->|"injects"| node_content
node_chrome -->|"dispatches command"| node_dispatcher
node_content -->|"handles interaction"| node_selection
node_selection -->|"reads geometry"| node_measurement
node_selection -->|"measures elements"| node_distance
node_measurement -->|"renders values"| node_cards
node_content -->|"renders overlay"| node_overlay
node_cards -->|"copies values"| node_copy
node_content -->|"reads styles"| node_page

click node_popup "https://github.com/fatehzid/gapray/blob/main/extension/popup.js"
click node_settings "https://github.com/fatehzid/gapray/blob/main/extension/settings.js"
click node_shortcut "https://github.com/fatehzid/gapray/blob/main/extension/commands.js"
click node_dispatcher "https://github.com/fatehzid/gapray/blob/main/extension/background.js"
click node_content "https://github.com/fatehzid/gapray/blob/main/extension/content.js"
click node_selection "https://github.com/fatehzid/gapray/blob/main/extension/content.js"
click node_measurement "https://github.com/fatehzid/gapray/blob/main/extension/content.js"
click node_distance "https://github.com/fatehzid/gapray/blob/main/extension/content.js"
click node_overlay "https://github.com/fatehzid/gapray/blob/main/extension/content.js"
click node_cards "https://github.com/fatehzid/gapray/blob/main/extension/content.js"
click node_copy "https://github.com/fatehzid/gapray/blob/main/extension/content.js"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_popup,node_settings,node_shortcut,node_dispatcher,node_user toneBlue
class node_content,node_selection,node_measurement,node_distance toneAmber
class node_overlay,node_cards,node_copy,node_chrome toneMint
class node_page toneIndigo
```

## Components

### Activation and settings

- [Toolbar popup](https://github.com/fatehzid/gapray/blob/main/extension/popup.js): `extension/popup.js`
- [Settings page](https://github.com/fatehzid/gapray/blob/main/extension/settings.js): `extension/settings.js`
- [Shortcut lookup](https://github.com/fatehzid/gapray/blob/main/extension/commands.js): `extension/commands.js`
- [Background dispatcher](https://github.com/fatehzid/gapray/blob/main/extension/background.js): `extension/background.js`

### Page inspection

- [Content-script coordinator](https://github.com/fatehzid/gapray/blob/main/extension/content.js): `extension/content.js`
- [Selection and hover](https://github.com/fatehzid/gapray/blob/main/extension/content.js): `extension/content.js`
- [Geometry and styles](https://github.com/fatehzid/gapray/blob/main/extension/content.js): `extension/content.js`
- [Distance measurement](https://github.com/fatehzid/gapray/blob/main/extension/content.js): `extension/content.js`

### Overlay and results

- [Overlay rendering](https://github.com/fatehzid/gapray/blob/main/extension/content.js): `extension/content.js`
- [Inspection cards](https://github.com/fatehzid/gapray/blob/main/extension/content.js): `extension/content.js`
- [Copy and feedback](https://github.com/fatehzid/gapray/blob/main/extension/content.js): `extension/content.js`

### Other components

- **User**
- **Chrome APIs**
- **Active webpage**

## Connections

- User → Toolbar popup: opens (evidence: `README.md`)
- User → Active webpage: inspects (evidence: `README.md`)
- Toolbar popup → Shortcut lookup: reads shortcut (evidence: `extension/popup.js`)
- Settings page → Shortcut lookup: reads shortcut (evidence: `extension/settings.js`)
- Toolbar popup → Chrome APIs: queries tab (evidence: `extension/popup.js`)
- Settings page → Chrome APIs: opens shortcuts (evidence: `extension/settings.js`)
- Toolbar popup → Background dispatcher: sends toggle (evidence: `extension/popup.js`)
- Background dispatcher → Chrome APIs: injects script (evidence: `extension/background.js`)
- Background dispatcher → Content-script coordinator: injects (evidence: `extension/background.js`)
- Chrome APIs → Background dispatcher: dispatches command (evidence: `extension/background.js`)
- Content-script coordinator → Selection and hover: handles interaction (evidence: `extension/content.js`)
- Selection and hover → Geometry and styles: reads geometry (evidence: `extension/content.js`)
- Selection and hover → Distance measurement: measures elements (evidence: `extension/content.js`)
- Geometry and styles → Inspection cards: renders values (evidence: `extension/content.js`)
- Content-script coordinator → Overlay rendering: renders overlay (evidence: `extension/content.js`)
- Inspection cards → Copy and feedback: copies values (evidence: `extension/content.js`)
- Content-script coordinator → Active webpage: reads styles (evidence: `README.md`)
