How marcosarnold/cash-cow works
1. Repository shape
- This is a Chrome Extension MV3 with a React/TypeScript frontend and a Python sidecar server.
- The extension UI is built with Vite and styled with Tailwind CSS.
- The architecture is split into browser-resident logic, local persistence, and a local AI/classification service.
2. Top-level runtime boundaries
- Browser extension runtime: popup, content scripts, background service worker, settings/dashboard UI.
- Local Python server on localhost:8080: merchant classification via Anthropic Claude.
- Offline scraping pipeline: Python scraper generates card reward data consumed by the extension.
3. Checkout detection layer
- The content-script entrypoints live under src/pages/content/.
- amazon-amount.js and related content code detect supported merchant checkout pages, extract the transaction amount and merchant context, and emit a CHECKOUT_DETECTED-style event.
- This layer is intentionally narrow: it observes the page, but does not do recommendation logic itself.
4. Extension orchestration
- The background service worker in src/pages/background/index.ts is the coordination hub.
- It listens for messages from content scripts, updates the extension badge, and handles keyboard shortcut behavior.
- This keeps page instrumentation separated from UI rendering and from the recommendation engine.
5. Popup and primary user experience
- popup.html, src/popup.tsx, and src/components/MainPopup.tsx drive the main extension surface.
- The popup shows the recommended card, supporting rationale, and a card carousel.
- The popup is the primary point where browser-detected checkout data becomes an actionable recommendation.
6. Rewards recommendation engine
- Core reward logic lives in src/lib/rewards/.
- engine.ts, rules.ts, and cardDataService.ts load card definitions, map merchant category to reward rules, and compute expected value using transaction amount × reward rate.
- The output is a ranked list of cards, not just a single match, which lets the UI explain tradeoffs.
7. Card and merchant data model
- Static reward data is bundled in src/lib/credit_card_rewards.json.
- Type definitions in src/lib/types.ts and src/lib/creditCardTypes.ts normalize card issuer/reward structures for the engine and UI.
- Merchant classification helpers in src/lib/merchant/agenticDetect.ts and related parser code bridge raw merchant names to reward categories.
8. AI classification service
- server/agent.py is a FastAPI-based local service that calls Anthropic Claude.
- Its job is to classify merchants into reward categories such as dining, groceries, gas, travel, and e-commerce.
- This is the main networked dependency in the architecture, and it sits outside the extension so the browser can keep the rest of the flow local.
9. Data ingestion / scraping pipeline
- server/scraper.py is a separate offline acquisition tool that scrapes credit card reward data from external sources.
- The scraper feeds structured reward metadata into the JSON used by the extension.
- This creates a clear separation between data collection and runtime recommendation.
10. Settings, preferences, and local state
- src/components/settings/ contains account/privacy, card management, and reward preference UI.
- src/lib/storage.ts is the likely persistence boundary for extension-local settings and user preferences.
- This part of the system is designed to keep user-specific configuration in-browser rather than in the Python service.
11. Dashboard and secondary UI surfaces
- src/components/RewardsDashboard.tsx provides a broader analytics view beyond the checkout popup.
- UI primitives such as MinimizedWidget, ThemeContext, and the shared card components support alternate extension states and reusable rendering.
- These are presentation layers over the same rewards data, not separate business logic.
12. Content/page-specific UX and assets
- src/pages/content/style.css and the assets under src/assets/ provide the embedded page-facing styling and imagery.
- The extension also includes localization (src/locales/en/messages.json) and shared global styling (src/styles/globals.css, src/assets/styles/tailwind.css).
- These assets support a polished extension experience but do not change the core data flow.
13. End-to-end flow
- Page checkout is detected in the content script → background worker is notified → merchant context is classified by the local agent server when needed → the reward engine ranks cards using stored reward data → popup/dashboard renders the recommendation.
- The system is architected so that most decision-making can happen locally, with the Python server only handling AI classification.
Main entry points: engine.ts Rewards Engine · index.ts Background SW · MainPopup.tsx Main Popup · index.tsx Checkout Detect
Components 18
Browser Extension
MV3 extension runtime, UI, and local persistence in the browser.
- Checkout Detect · Page observers that detect supported checkout pages and extract amount and merchant context.
src/pages/content/index.tsx - Amazon Amount · Merchant-specific checkout instrumentation for amount extraction.
src/pages/content/amazon-amount.js - Merchant Detect · Merchant-page detection helpers and heuristics for supported sites.
src/pages/content/merchant/detect.ts - Background SW · Coordinates messages, badge updates, and keyboard shortcut behavior.
src/pages/background/index.ts - Popup UI · Main popup entry that renders the checkout recommendation experience.
src/popup.tsx - Main Popup · Primary popup surface with recommendation, rationale, and carousel state.
src/components/MainPopup.tsx - Rewards Dashboard · Broader rewards analytics surface beyond the checkout popup.
src/components/RewardsDashboard.tsx - Settings Menu · Entry point for preferences and account/privacy controls.
src/components/settings/SettingsMenu.tsx - Manage Cards · Card management and reward preference configuration.
src/components/settings/ManageCards.tsx - Local Storage · Extension-local persistence boundary for settings and user preferences.
src/lib/storage.ts - Rewards Engine · Computes expected value and ranks cards for a detected purchase.
src/lib/rewards/engine.ts - Reward Rules · Maps merchant categories and card rules into reward calculations.
src/lib/rewards/rules.ts - Card Data · Loads card definitions and exposes structured reward metadata to the engine.
src/lib/rewards/cardDataService.ts - Agentic Detect · Bridges raw merchant names to reward categories, including AI-assisted classification paths.
src/lib/merchant/agenticDetect.ts - Category Parser · Python-side category parsing and normalization helpers.
src/category_parser.py
Local Python Service
Local merchant-classification and scraping utilities running outside the extension.
- Claude Agent · Local Python classification service that calls Anthropic Claude for merchant categorization.
server/agent.py - Reward Scraper · Offline data acquisition tool that scrapes reward metadata for bundling.
server/scraper.py
Reward Data
Static reward catalog and merchant/category mapping used by the engine.
- Reward Catalog · Bundled JSON reward catalog consumed by the extension runtime.
src/lib/credit_card_rewards.json
Connections 18
- Checkout Detect → Merchant Detect: page context · Content scripts use merchant detection to narrow supported checkout pages.
- Checkout Detect → Background SW: checkout detected · Detected checkout data is sent to the background worker for orchestration.
- Amazon Amount → Checkout Detect: specialized entry · Amazon-specific amount extraction feeds the broader content-script flow.
- Background SW → Popup UI: open UI · Background state can surface the popup experience when checkout data arrives.
- Popup UI → Main Popup: renders · Popup entry mounts the main recommendation UI.
- Main Popup → Rewards Engine: request ranking · Popup asks the reward engine for card recommendations and rationale.
- Rewards Dashboard → Rewards Engine: reuse logic · Dashboard reuses the same rewards ranking logic for analytics views.
- Rewards Engine → Reward Rules: apply rules · Engine evaluates card reward rules against the transaction amount and merchant category.
- Rewards Engine → Card Data: load cards · Engine loads structured card definitions before ranking.
- Card Data → Reward Catalog: read catalog · Card data service is backed by the bundled reward catalog.
- Rewards Engine → Agentic Detect: classify merchant · Engine-side merchant normalization can invoke merchant classification helpers.
- Agentic Detect → Claude Agent: local call · AI-assisted merchant classification delegates to the local Python service when needed.
- Claude Agent → Category Parser: normalize category · Python service uses category parsing/normalization for merchant-to-category mapping.
- Reward Scraper → Reward Catalog: populate data · Offline scraper feeds structured reward metadata into the bundled catalog.
- Local Storage → Settings Menu: preferences · Settings UI persists user configuration through the local storage boundary.
- Settings Menu → Manage Cards: configure · Settings menu routes into card and reward preference management.
- Main Popup → Local Storage: read prefs · Popup reads user-specific settings to shape recommendation behavior.
- Background SW → Local Storage: sync state · Background worker may keep extension-local state in sync with stored preferences.