You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/architecture.md
+6-3Lines changed: 6 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,6 +2,8 @@
2
2
3
3
CoderChart follows the typical MV3 separation: a background service worker maintains defaults, the content script renders diagrams in-page, and the options UI manages configuration. Shared utilities in `src/shared` allow all surfaces to agree on settings and URL matching.
4
4
5
+
For a user-centric walkthrough of the lifecycle, see [`extension-flow.md`](./extension-flow.md).
6
+
5
7
## Runtime Components
6
8
7
9
-**Background (`src/background/index.ts`)**
@@ -25,7 +27,7 @@ CoderChart follows the typical MV3 separation: a background service worker maint
25
27
26
28
```mermaid
27
29
flowchart TD
28
-
A[Load content script] --> B[getSettings()]
30
+
A[Load content script] --> B[Fetch settings]
29
31
B --> C{autoRender enabled?}
30
32
C -- No --> D[Stay idle]
31
33
C -- Yes --> E{URL matches whitelist?}
@@ -55,5 +57,6 @@ flowchart TD
55
57
56
58
## Known Constraints
57
59
58
-
- Builds occasionally report Rollup chunk-size warnings; adjust splitting before release if bundle size grows.
59
-
- Rendering currently assumes Mermaid syntax; invalid diagrams surface an inline error but do not retry automatically.
60
+
- Clearing all host patterns in options is not persisted: `normalizeSettings` restores the default ChatGPT domains, so disable `autoRender` to pause rendering globally.
61
+
- PNG export relies on drawing the generated SVG into a canvas; diagrams that pull in external assets or exceed canvas limits can fail to export and log a warning.
62
+
- Mermaid parse failures surface inline with a copyable fix prompt, but there is still no automatic retry or self-healing.
This guide walks through the end-to-end experience from installation to exporting rendered diagrams.
3
+
This guide outlines the user-visible lifecycle. For component responsibilities and deeper mechanics, see [`architecture.md`](./architecture.md).
4
4
5
-
## Narrative Flow
5
+
## Lifecycle Overview
6
6
7
-
1.**Install:** User loads the unpacked build or installs from the Chrome Web Store. The background script seeds default settings in `chrome.storage.sync`.
8
-
2.**Grant permissions:** Chrome applies host permissions declared in `manifest.ts` (ChatGPT domains and localhost during development).
9
-
3.**Open supported page:** When the user opens chatgpt.com or another whitelisted host, the content script loads, retrieves settings, and checks the URL against the whitelist.
10
-
4.**Render diagrams:** Matching Mermaid code fences trigger the inline renderer. Mermaid initialises with theme selection, generates SVG, and injects a container with toolbar controls.
11
-
5.**Adjust settings:** Users can visit `options.html` to disable auto-rendering, edit host patterns, or reset to defaults. Changes sync across devices.
12
-
6.**Use toolbar:** Inline buttons allow collapsing/expanding the diagram, scrolling back to the source code block, and exporting as SVG or PNG.
13
-
7.**Download pipeline:** SVG downloads reuse the cached render, while PNG downloads convert the SVG via an off-screen canvas before prompting a file save.
14
-
8.**Keep updated:** A MutationObserver re-runs rendering when the chat adds new content, and storage listeners reconfigure the script when settings change.
7
+
| Step | Trigger | Primary owner | Notes |
8
+
| --- | --- | --- | --- |
9
+
| Install or upgrade | Extension installed from source or Web Store | Background service worker | Seeds defaults and handles migrations (`architecture.md` → Runtime Components). |
10
+
| Host access granted | Chrome applies `manifest.ts` host permissions | Chrome / MV3 platform | Controls where the content script can run (`architecture.md` → Runtime Components). |
11
+
| Page activation | User opens a whitelisted URL | Content script | Fetches settings, checks URL against patterns, and, if allowed, initialises Mermaid (`architecture.md` → Data Flow Sequence). |
0 commit comments