# mr-sanjai-offl/algovault architecture

> Architecture diagram of the GitHub repository mr-sanjai-offl/algovault, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-07-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/mr-sanjai-offl/algovault
- Repository: https://github.com/mr-sanjai-offl/algovault

## Overview

#### Purpose and execution model
AlgoVault is a Chrome Manifest V3 extension that detects accepted LeetCode submissions, persists them locally, and synchronizes structured solutions plus a generated dashboard to a user-selected GitHub repository. Its runtime is split across a MV3 background service worker, LeetCode content scripts, React popup/options surfaces, and Chrome extension storage.

#### Extension entry points
- Background orchestration starts in `src/background/service-worker.ts`, with cross-context request routing in `src/background/messageHandler.ts`.
- LeetCode page integration starts in `src/content/index.ts`; page changes and submission-state observation are handled by `src/content/observer.ts`.
- The browser-action UI is React-based at `src/popup/main.tsx` and `src/popup/App.tsx`.
- The options UI has an independent React entry at `src/options/main.tsx`.
- Static extension assets and manifest-related browser resources reside in `public/manifest.json` and `public/content-loader.js`.

#### Submission capture pipeline
Content scripts observe LeetCode’s dynamic UI, extract accepted-submission data, and send it to the background layer:
- DOM/problem/submission parsing: `src/content/extractor.ts`
- SPA lifecycle and acceptance detection: `src/content/observer.ts`
- Shared message contracts: `src/shared/types/messages.ts`, `src/shared/types/submission.ts`

The content/background boundary is Chrome runtime messaging. This keeps site DOM access outside the privileged background process and lets the service worker own persistence, authentication, and outbound GitHub calls.

#### Background sync and GitHub boundary
The service worker coordinates the main control flow: receive submission, deduplicate/persist it, obtain repository configuration, then commit solution and dashboard updates through GitHub APIs.
- GitHub HTTP/API adapter: `src/background/github/client.ts`
- LeetCode API integration: `src/background/leetcode/api.ts`
- Repository manifest/state of synchronized files: `src/background/manifest/manifestStore.ts`
- Error classification shared across stages: `src/shared/errors/taxonomy.ts`

GitHub authentication uses OAuth Device Flow in `src/background/auth/deviceFlow.ts`. GitHub and optional OpenRouter-related contracts are represented by shared types, including `src/shared/types/ai.ts`.

#### Local state, durability, and recovery
State is intentionally separated by access pattern:
- High-volume submission/history persistence: `src/background/storage/indexedDb.ts`
- Extension configuration and lightweight state: `src/background/storage/configStore.ts`
- Encrypted local credential storage: `src/background/storage/encryptedStorage.ts`

This layer shields sync orchestration from browser service-worker restarts and retains unsynchronized work/history locally. Configuration, manifest, and sync message types define the durable state boundaries in `src/shared/types/config.ts`, `src/shared/types/manifest.ts`, and `src/shared/types/sync.ts`.

#### Repository generation and analytics
After successful synchronization, the extension derives portfolio-facing repository artifacts:
- Aggregate history/statistics: `src/background/stats/aggregator.ts`
- GitHub dashboard README generation: `src/background/markdown/dashboardBuilder.ts`
- Per-solution/readme content generation: `src/background/markdown/readmeBuilder.ts`

These builders transform persisted submission data into Markdown rather than exposing raw browser-captured data directly to GitHub.

#### User-facing control plane
The popup is the operational UI for login, repository settings, sync status, history, statistics, and theme preferences:
- Page composition: `src/popup/pages/DashboardPage.tsx`, `src/popup/pages/SettingsPage.tsx`, `src/popup/pages/HistoryPage.tsx`
- Background-facing state hooks: `src/popup/hooks/useAuth.ts`, `src/popup/hooks/useSync.ts`, `src/popup/hooks/useHistory.ts`
- Auth entry page: `src/popup/pages/LoginPage.tsx`

React/Vite/TypeScript build the UI and extension bundles; Chrome APIs, GitHub Device Flow/GitHub APIs, LeetCode pages/APIs, IndexedDB, and `chrome.storage.local` are the material platform dependencies.

Main entry points: [`src/background/service-worker.ts`](https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/service-worker.ts) (Service worker), [`src/background/messageHandler.ts`](https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/messageHandler.ts) (Message router), [`src/background/storage/indexedDb.ts`](https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/storage/indexedDb.ts) (Submission history), [`src/background/github/client.ts`](https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/github/client.ts) (GitHub client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_extension["Extension contexts"]
  node_content["LeetCode content script<br/>content runtime<br/>[index.ts]"]
  node_observer["Submission observer<br/>SPA observer<br/>[observer.ts]"]
  node_extractor["Submission extractor<br/>DOM parser<br/>[extractor.ts]"]
  node_popup["Popup control plane<br/>React UI<br/>[App.tsx]"]
  node_options["Options UI<br/>React entry<br/>[main.tsx]"]
end

subgraph group_background["Background orchestration"]
  node_service_worker{{"Service worker<br/>MV3 orchestrator<br/>[service-worker.ts]"}}
  node_message_handler["Message router<br/>request routing<br/>[messageHandler.ts]"]
  node_github_auth["GitHub device auth<br/>OAuth Device Flow<br/>[deviceFlow.ts]"]
  node_github_client["GitHub client<br/>HTTP adapter<br/>[client.ts]"]
  node_leetcode_api["LeetCode API<br/>API adapter<br/>[api.ts]"]
end

subgraph group_state["Local durable state"]
  node_submission_db[("Submission history<br/>IndexedDB store<br/>[indexedDb.ts]")]
  node_config_store[("Configuration store<br/>chrome.storage<br/>[configStore.ts]")]
  node_credential_store[("Credential store<br/>encrypted storage")]
  node_sync_manifest["Sync manifest<br/>repository state<br/>[manifestStore.ts]"]
end

subgraph group_generation["Repository generation"]
  node_stats["Statistics aggregator<br/>analytics<br/>[aggregator.ts]"]
  node_solution_markdown["Solution Markdown builder<br/>content generator<br/>[readmeBuilder.ts]"]
  node_dashboard_markdown["Dashboard builder<br/>Markdown generator"]
end

subgraph group_external["External platforms"]
  node_leetcode["LeetCode<br/>site and API"]
  node_github["GitHub repository<br/>OAuth and GitHub API"]
end

node_leetcode -->|"renders problem UI"| node_content
node_content -->|"starts observation"| node_observer
node_observer -->|"accepted submission"| node_extractor
node_extractor -->|"submission message"| node_message_handler
node_popup -->|"auth and sync requests"| node_message_handler
node_options -->|"configuration requests"| node_message_handler
node_message_handler -->|"routed requests"| node_service_worker
node_service_worker -->|"persists and deduplicates"| node_submission_db
node_service_worker -->|"reads repository settings"| node_config_store
node_service_worker -->|"reads credentials"| node_credential_store
node_service_worker -->|"reads and updates state"| node_sync_manifest
node_service_worker -->|"initiates login"| node_github_auth
node_github_auth -->|"Device Flow"| node_github
node_service_worker -->|"fetches supplemental data"| node_leetcode_api
node_leetcode_api -->|"API calls"| node_leetcode
node_submission_db -->|"submission history"| node_stats
node_submission_db -->|"solution data"| node_solution_markdown
node_stats -->|"aggregate statistics"| node_dashboard_markdown
node_service_worker -->|"generates repository artifacts"| node_solution_markdown
node_service_worker -->|"generates dashboard"| node_dashboard_markdown
node_solution_markdown -->|"solution files"| node_github_client
node_dashboard_markdown -->|"dashboard README"| node_github_client
node_github_client -->|"commits artifacts"| node_github

click node_content "https://github.com/mr-sanjai-offl/algovault/blob/main/src/content/index.ts"
click node_observer "https://github.com/mr-sanjai-offl/algovault/blob/main/src/content/observer.ts"
click node_extractor "https://github.com/mr-sanjai-offl/algovault/blob/main/src/content/extractor.ts"
click node_popup "https://github.com/mr-sanjai-offl/algovault/blob/main/src/popup/App.tsx"
click node_options "https://github.com/mr-sanjai-offl/algovault/blob/main/src/options/main.tsx"
click node_service_worker "https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/service-worker.ts"
click node_message_handler "https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/messageHandler.ts"
click node_github_auth "https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/auth/deviceFlow.ts"
click node_github_client "https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/github/client.ts"
click node_leetcode_api "https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/leetcode/api.ts"
click node_submission_db "https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/storage/indexedDb.ts"
click node_config_store "https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/storage/configStore.ts"
click node_credential_store "https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/storage/encryptedStorage.ts"
click node_sync_manifest "https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/manifest/manifestStore.ts"
click node_stats "https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/stats/aggregator.ts"
click node_solution_markdown "https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/markdown/readmeBuilder.ts"
click node_dashboard_markdown "https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/markdown/dashboardBuilder.ts"

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_content,node_observer,node_extractor,node_popup,node_options toneBlue
class node_service_worker,node_message_handler,node_github_auth,node_github_client,node_leetcode_api toneAmber
class node_submission_db,node_config_store,node_credential_store,node_sync_manifest toneMint
class node_stats,node_solution_markdown,node_dashboard_markdown toneRose
class node_leetcode,node_github toneIndigo
```

## Components

### Extension contexts

- [LeetCode content script](https://github.com/mr-sanjai-offl/algovault/blob/main/src/content/index.ts): content runtime · Observes pages and captures accepted submissions. · `src/content/index.ts`
- [Submission observer](https://github.com/mr-sanjai-offl/algovault/blob/main/src/content/observer.ts): SPA observer · Tracks page lifecycle and acceptance state. · `src/content/observer.ts`
- [Submission extractor](https://github.com/mr-sanjai-offl/algovault/blob/main/src/content/extractor.ts): DOM parser · `src/content/extractor.ts`
- [Popup control plane](https://github.com/mr-sanjai-offl/algovault/blob/main/src/popup/App.tsx): React UI · Login, settings, sync status, history, and statistics. · `src/popup/App.tsx`
- [Options UI](https://github.com/mr-sanjai-offl/algovault/blob/main/src/options/main.tsx): React entry · `src/options/main.tsx`

### Background orchestration

- [Service worker](https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/service-worker.ts): MV3 orchestrator · Owns capture handling, persistence, auth, and synchronization. · `src/background/service-worker.ts`
- [Message router](https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/messageHandler.ts): request routing · Routes cross-context Chrome runtime requests. · `src/background/messageHandler.ts`
- [GitHub device auth](https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/auth/deviceFlow.ts): OAuth Device Flow · `src/background/auth/deviceFlow.ts`
- [GitHub client](https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/github/client.ts): HTTP adapter · `src/background/github/client.ts`
- [LeetCode API](https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/leetcode/api.ts): API adapter · `src/background/leetcode/api.ts`

### Local durable state

- [Submission history](https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/storage/indexedDb.ts): IndexedDB store · Durable high-volume submissions and unsynced work. · `src/background/storage/indexedDb.ts`
- [Configuration store](https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/storage/configStore.ts): chrome.storage · Repository configuration and lightweight extension state. · `src/background/storage/configStore.ts`
- [Credential store](https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/storage/encryptedStorage.ts): encrypted storage · `src/background/storage/encryptedStorage.ts`
- [Sync manifest](https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/manifest/manifestStore.ts): repository state · Tracks synchronized repository files. · `src/background/manifest/manifestStore.ts`

### Repository generation

- [Statistics aggregator](https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/stats/aggregator.ts): analytics · `src/background/stats/aggregator.ts`
- [Solution Markdown builder](https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/markdown/readmeBuilder.ts): content generator · `src/background/markdown/readmeBuilder.ts`
- [Dashboard builder](https://github.com/mr-sanjai-offl/algovault/blob/main/src/background/markdown/dashboardBuilder.ts): Markdown generator · `src/background/markdown/dashboardBuilder.ts`

### External platforms

- **LeetCode**: site and API
- **GitHub repository**: OAuth and GitHub API · User-selected destination repository.

## Connections

- LeetCode → LeetCode content script: renders problem UI
- LeetCode content script → Submission observer: starts observation
- Submission observer → Submission extractor: accepted submission
- Submission extractor → Message router: submission message · Chrome runtime messaging boundary.
- Popup control plane → Message router: auth and sync requests
- Options UI → Message router: configuration requests
- Message router → Service worker: routed requests
- Service worker → Submission history: persists and deduplicates
- Service worker → Configuration store: reads repository settings
- Service worker → Credential store: reads credentials
- Service worker → Sync manifest: reads and updates state
- Service worker → GitHub device auth: initiates login
- GitHub device auth → GitHub repository: Device Flow
- Service worker → LeetCode API: fetches supplemental data
- LeetCode API → LeetCode: API calls
- Submission history → Statistics aggregator: submission history
- Submission history → Solution Markdown builder: solution data
- Statistics aggregator → Dashboard builder: aggregate statistics
- Service worker → Solution Markdown builder: generates repository artifacts
- Service worker → Dashboard builder: generates dashboard
- Solution Markdown builder → GitHub client: solution files
- Dashboard builder → GitHub client: dashboard README
- GitHub client → GitHub repository: commits artifacts
