# joystrife/context-restorer-for-freshservice architecture

> Architecture diagram of the GitHub repository joystrife/context-restorer-for-freshservice, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/joystrife/context-restorer-for-freshservice
- Repository: https://github.com/joystrife/context-restorer-for-freshservice

## Overview

This Chromium extension preserves Freshservice navigation context per tab and restores it after authentication is positively observed. The workflow detects and classifies portal navigation, records useful destinations and session-loss state, waits for authentication, then restores the affected tab or tabs. The popup exposes status, portal controls, counters, and a manual fallback. The sampled code shows the background worker importing the URL rules and using browser storage; finer restore and message-handler details are not fully excerpted, so unsupported internal links are omitted.

Main entry points: [`extension/popup.js`](https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/popup.js) (Popup interface), [`extension/background.js`](https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/background.js) (Navigation observer), [`extension/popup.html`](https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/popup.html) (Popup layout), [`extension/popup.css`](https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/popup.css) (Popup styling)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_detect["Detection and rules"]
  node_rules["URL classification<br/>[rules.js]"]
  node_navigation["Navigation observer<br/>[background.js]"]
end

subgraph group_recovery["Context recovery"]
  node_context["Tab context tracking<br/>[background.js]"]
  node_authwait["Authentication waiting<br/>[background.js]"]
  node_restore["Tab restoration<br/>[background.js]"]
end

subgraph group_state["Local state"]
  node_portalregistry[("Portal registry<br/>[background.js]")]
  node_tabstate[("Session tab state<br/>[background.js]")]
  node_stats[("Restore counters<br/>[background.js]")]
  node_debug[("Session debug log<br/>[background.js]")]
end

subgraph group_ui["Popup controls"]
  node_popup["Popup interface<br/>[popup.js]"]
  node_popupmarkup["Popup layout<br/>[popup.html]"]
  node_popupstyle["Popup styling<br/>[popup.css]"]
end

node_user(("Extension user"))
node_browser(("Chromium browser"))
node_portal(("Freshservice portal"))
node_auth(("Freshworks authentication"))

node_browser -->|"emits navigation"| node_navigation
node_navigation -->|"classifies URLs"| node_rules
node_navigation -->|"updates context"| node_context
node_context -->|"reads/writes"| node_tabstate
node_context -->|"updates portal"| node_portalregistry
node_navigation -->|"records events"| node_debug
node_auth -.->|"signals auth"| node_navigation
node_authwait -->|"dispatches recovery"| node_restore
node_restore -.->|"navigates tab"| node_browser
node_restore -->|"records success"| node_stats
node_popupmarkup -->|"provides controls"| node_popup
node_popupstyle -.->|"styles interface"| node_popup
node_user -.->|"opens controls"| node_popup
node_popup -->|"queries active tab"| node_browser
node_popup -->|"requests inspection"| node_navigation
node_popup -->|"reads status"| node_tabstate
node_popup -->|"reads registry"| node_portalregistry
node_popup -->|"reads counters"| node_stats
node_popup -->|"reads events"| node_debug
node_popup -->|"sends controls"| node_context
node_portal -.->|"provides page URLs"| node_navigation

click node_rules "https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/rules.js"
click node_navigation "https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/background.js"
click node_context "https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/background.js"
click node_authwait "https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/background.js"
click node_restore "https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/background.js"
click node_portalregistry "https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/background.js"
click node_tabstate "https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/background.js"
click node_stats "https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/background.js"
click node_debug "https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/background.js"
click node_popup "https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/popup.js"
click node_popupmarkup "https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/popup.html"
click node_popupstyle "https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/popup.css"

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_rules,node_navigation,node_user,node_browser toneBlue
class node_context,node_authwait,node_restore toneAmber
class node_portalregistry,node_tabstate,node_stats,node_debug toneMint
class node_popup,node_popupmarkup,node_popupstyle toneRose
class node_portal,node_auth toneIndigo
```

## Components

### Detection and rules

- [URL classification](https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/rules.js): `extension/rules.js`
- [Navigation observer](https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/background.js): `extension/background.js`

### Context recovery

- [Tab context tracking](https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/background.js): `extension/background.js`
- [Authentication waiting](https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/background.js): `extension/background.js`
- [Tab restoration](https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/background.js): `extension/background.js`

### Local state

- [Portal registry](https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/background.js): `extension/background.js`
- [Session tab state](https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/background.js): `extension/background.js`
- [Restore counters](https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/background.js): `extension/background.js`
- [Session debug log](https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/background.js): `extension/background.js`

### Popup controls

- [Popup interface](https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/popup.js): `extension/popup.js`
- [Popup layout](https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/popup.html): `extension/popup.html`
- [Popup styling](https://github.com/joystrife/context-restorer-for-freshservice/blob/main/extension/popup.css): `extension/popup.css`

### Other components

- **Extension user**
- **Chromium browser**
- **Freshservice portal**
- **Freshworks authentication**

## Connections

- Chromium browser → Navigation observer: emits navigation (evidence: `extension/background.js`)
- Navigation observer → URL classification: classifies URLs (evidence: `extension/background.js`)
- Navigation observer → Tab context tracking: updates context (evidence: `extension/background.js`)
- Tab context tracking → Session tab state: reads/writes (evidence: `extension/background.js`)
- Tab context tracking → Portal registry: updates portal (evidence: `extension/background.js`)
- Navigation observer → Session debug log: records events (evidence: `extension/background.js`)
- Freshworks authentication → Navigation observer: signals auth
- Authentication waiting → Tab restoration: dispatches recovery (evidence: `extension/background.js`)
- Tab restoration → Chromium browser: navigates tab
- Tab restoration → Restore counters: records success (evidence: `extension/background.js`)
- Popup layout → Popup interface: provides controls (evidence: `extension/popup.js`)
- Popup styling → Popup interface: styles interface
- Extension user → Popup interface: opens controls
- Popup interface → Chromium browser: queries active tab (evidence: `extension/popup.js`)
- Popup interface → Navigation observer: requests inspection (evidence: `extension/popup.js`)
- Popup interface → Session tab state: reads status (evidence: `extension/popup.js`)
- Popup interface → Portal registry: reads registry (evidence: `extension/popup.js`)
- Popup interface → Restore counters: reads counters (evidence: `extension/popup.js`)
- Popup interface → Session debug log: reads events (evidence: `extension/popup.js`)
- Popup interface → Tab context tracking: sends controls (evidence: `extension/popup.js`)
- Freshservice portal → Navigation observer: provides page URLs
