# kamingfung/chase_offer_auto_enroll architecture

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

- Interactive diagram: https://gitdiagram.com/kamingfung/chase_offer_auto_enroll
- Repository: https://github.com/kamingfung/chase_offer_auto_enroll

## Overview

##### Project Type and Purpose
- Type: Chrome browser extension
- Purpose: Automate the process of adding Chase Offers across multiple credit card accounts with pause/resume and real-time status updates.

##### File Structure
- manifest.json – Defines the extension’s metadata, permissions, and entry points
- popup.html – UI markup for the browser action popup
- popup.js – Logic for handling user interactions in the popup and coordinating with the content script
*(No background/service‐worker script is present, so popup.js likely orchestrates both UI and page‐injection logic.)*

##### Extract Key Architectural Insights from the README
- UI component allows “Add offers” and “Pause/Resume.”
- Script injection on the active Chase Offers page to click “Add to Card” buttons.
- Automatic account switching via navigation and sequential processing.
- Real-time status is sent back to the popup for display.
- Error handling and state management (running vs. paused).

##### Main Components
a. Browser & Chrome Extension Platform
b. manifest.json (Configuration)
c. Popup UI (popup.html + popup.js)
d. Content Script (injected JS code)
e. Chase Offers Web Page (target DOM)
f. Chrome Extension APIs (chrome.runtime, chrome.tabs, chrome.scripting)

##### Defining Relationships & Data Flows
2. In Popup UI, user clicks “Add offers” → popup.js sends a message (chrome.tabs.sendMessage) to the content script.
3. Content script runs in the context of the Chase page → uses DOM APIs to find and click “Add to Card” buttons.
4. Content script monitors navigation events (account switching) → when a page loads for the next account, continues injection.
5. Content script posts status updates back to popup.js (chrome.runtime.sendMessage).
6. Popup.js updates the UI (status area) and shows/hides the Pause/Resume button.
7. If user clicks “Pause,” popup.js sends a pause command → content script halts operations until “Resume” message arrives.

##### Architectural Patterns & Design Principles
- Event-driven messaging (chrome.runtime, chrome.tabs)
- Separation of concerns:
– UI layer (popup.html/js)
– Page-injection logic (content script)
– Configuration (manifest.json)
- Stateless UI with in-memory state in popup.js and content script for pause/resume
- Graceful degradation: error messages when buttons or pages change

##### Relevant Technologies, Frameworks, and Libraries
- Chrome Extension Manifest V3 (or V2)
- HTML/CSS for popup UI
- Vanilla JavaScript for popup.js and content script
- Chrome Extension APIs:
– chrome.runtime
– chrome.tabs
– chrome.scripting (for programmatic injection)

##### Detail
- Sequence: user action → popup logic → injection → DOM manipulation → navigation → status feedback → UI update.
- Error-handling paths (e.g., “no buttons found” → popup shows error).
- Pause/resume control flow (a loop that can be interrupted by user input).

## Diagram (Mermaid)

```mermaid
flowchart TB
  %% Chrome Extension Components
  subgraph "Chrome Extension"
    direction TB
    M["manifest.json"]:::config
    UI["popup.html"]:::ui
    PJS["popup.js"]:::logic
    CS["Content Script"]:::script
    Images["images/"]:::assets
  end

  %% External Systems
  Browser["Chrome Browser UI"]:::browser
  Chase["Chase Offers Web Page"]:::external

  %% Documentation
  subgraph "Project Documentation"
    README["README.md"]:::docs
  end

  %% User Interaction Flow
  User(["User"]):::user
  User -->|"click extension icon"| UI
  UI -->|"user clicks Add Offers/Pause/Resume"| PJS
  PJS -->|"chrome.tabs.sendMessage"| CS
  CS -->|"injects script & clicks Add to Card"| Chase
  CS -->|"listens navigation events"| CS
  CS -->|"chrome.runtime.sendMessage(status updates)"| PJS
  PJS -->|"update status in UI"| UI
  UI -->|"click Pause/Resume"| PJS
  PJS -->|"chrome.tabs.sendMessage(pause/resume)"| CS

  %% Click Events
  click M "https://github.com/kamingfung/chase_offer_auto_enroll/blob/main/manifest.json"
  click UI "https://github.com/kamingfung/chase_offer_auto_enroll/blob/main/popup.html"
  click PJS "https://github.com/kamingfung/chase_offer_auto_enroll/blob/main/popup.js"
  click Images "https://github.com/kamingfung/chase_offer_auto_enroll/tree/main/images/"
  click README "https://github.com/kamingfung/chase_offer_auto_enroll/blob/main/README.md"

  %% Styling
  classDef config fill:#f9f,stroke:#333;
  classDef ui fill:#bbf,stroke:#333;
  classDef logic fill:#bfb,stroke:#333;
  classDef script fill:#fbf,stroke:#333;
  classDef assets fill:#ff9,stroke:#333;
  classDef browser fill:#ccc,stroke:#333;
  classDef external fill:#fee,stroke:#333;
  classDef docs fill:#cff,stroke:#333;
  classDef user fill:#fff,stroke:#000,stroke-dasharray:2 2;
```
