# decodingafterlife/sweetcode architecture

> Architecture diagram of the GitHub repository decodingafterlife/sweetcode, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-09-26). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/decodingafterlife/sweetcode
- Repository: https://github.com/decodingafterlife/sweetcode

## Overview

SweetCode is a browser extension that turns successful LeetCode practice into timed access to selected social sites, and spends that allowance on AI hints. Its main loop is submission detection, validation and difficulty-based reward, followed by allowance enforcement and countdown on social pages. The popup also configures the AI model and reset period, extracts problem context, requests hints from Groq and charges time; content.js presents reward feedback. README documents these capabilities, while excerpts omit some wiring details, so uncertain connections are not shown.

Main entry points: [`background.js`](https://github.com/decodingafterlife/sweetcode/blob/main/background.js) (Extension coordinator), [`popup.js`](https://github.com/decodingafterlife/sweetcode/blob/main/popup.js) (Hint generation), [`content.js`](https://github.com/decodingafterlife/sweetcode/blob/main/content.js) (Reward feedback), [`popup.html`](https://github.com/decodingafterlife/sweetcode/blob/main/popup.html) (Extension popup)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_practice["Practice rewards"]
  node_background["Extension coordinator<br/>[background.js]"]
  node_submission["Submission tracking<br/>[background.js]"]
  node_reward["Reward calculation<br/>[background.js]"]
  node_feedback["Reward feedback<br/>[content.js]"]
end

subgraph group_access["Access control"]
  node_allowance[("Allowance state<br/>[background.js]")]
  node_reset["Daily and period reset<br/>[background.js]"]
  node_sitecheck["Social-site matching<br/>[background.js]"]
  node_gate["Navigation gate<br/>[background.js]"]
  node_countdown["Access countdown<br/>[background.js]"]
  node_blocked["Blocked page<br/>[blocked.html]"]
end

subgraph group_assistant["Hint assistant"]
  node_popup["Extension popup<br/>[popup.html]"]
  node_popupjs["Popup behavior<br/>[popup.js]"]
  node_settings["Hint and model settings<br/>[popup.js]"]
  node_context["Problem context extraction<br/>[popup.js]"]
  node_hint["Hint generation<br/>[popup.js]"]
end

node_user(("Learner"))
node_leetcode["LeetCode"]
node_social["Social sites"]
node_groq["Groq API"]

node_leetcode -->|"submits to"| node_submission
node_submission -->|"notifies"| node_background
node_background -->|"fetches history"| node_leetcode
node_background -->|"checks difficulty"| node_reward
node_reward -->|"adds reward"| node_allowance
node_background -->|"dispatches popup"| node_feedback
node_feedback -->|"shows reward"| node_user
node_background -->|"loads and saves"| node_allowance
node_reset -->|"resets"| node_allowance
node_background -->|"checks schedule"| node_reset
node_background -->|"checks URL"| node_sitecheck
node_background -->|"registers navigation"| node_gate
node_gate -->|"tests destination"| node_sitecheck
node_gate -->|"redirects"| node_blocked
node_background -->|"starts timer"| node_countdown
node_countdown -->|"reads and decrements"| node_allowance
node_countdown -->|"redirects at zero"| node_blocked
node_user -->|"opens"| node_popup
node_popup -->|"runs"| node_popupjs
node_popupjs -->|"loads and saves"| node_settings
node_settings -->|"reads allowance"| node_allowance
node_popupjs -->|"extracts problem"| node_context
node_context -->|"reads page"| node_leetcode
node_popupjs -->|"requests hint"| node_hint
node_hint -->|"sends context"| node_groq
node_groq -->|"returns hint"| node_hint
node_hint -->|"requests deduction"| node_background
node_background -->|"deducts hint cost"| node_allowance
node_hint -->|"displays hint"| node_user
node_user -->|"visits"| node_social
node_gate -->|"allows when funded"| node_social

click node_background "https://github.com/decodingafterlife/sweetcode/blob/main/background.js"
click node_submission "https://github.com/decodingafterlife/sweetcode/blob/main/background.js"
click node_reward "https://github.com/decodingafterlife/sweetcode/blob/main/background.js"
click node_feedback "https://github.com/decodingafterlife/sweetcode/blob/main/content.js"
click node_allowance "https://github.com/decodingafterlife/sweetcode/blob/main/background.js"
click node_reset "https://github.com/decodingafterlife/sweetcode/blob/main/background.js"
click node_sitecheck "https://github.com/decodingafterlife/sweetcode/blob/main/background.js"
click node_gate "https://github.com/decodingafterlife/sweetcode/blob/main/background.js"
click node_countdown "https://github.com/decodingafterlife/sweetcode/blob/main/background.js"
click node_blocked "https://github.com/decodingafterlife/sweetcode/blob/main/blocked.html"
click node_popup "https://github.com/decodingafterlife/sweetcode/blob/main/popup.html"
click node_popupjs "https://github.com/decodingafterlife/sweetcode/blob/main/popup.js"
click node_settings "https://github.com/decodingafterlife/sweetcode/blob/main/popup.js"
click node_context "https://github.com/decodingafterlife/sweetcode/blob/main/popup.js"
click node_hint "https://github.com/decodingafterlife/sweetcode/blob/main/popup.js"

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_background,node_submission,node_reward,node_feedback toneBlue
class node_allowance,node_reset,node_sitecheck,node_gate,node_countdown,node_blocked toneAmber
class node_popup,node_popupjs,node_settings,node_context,node_hint,node_groq toneMint
class node_user,node_leetcode,node_social toneIndigo
```

## Components

### Practice rewards

- [Extension coordinator](https://github.com/decodingafterlife/sweetcode/blob/main/background.js): `background.js`
- [Submission tracking](https://github.com/decodingafterlife/sweetcode/blob/main/background.js): `background.js`
- [Reward calculation](https://github.com/decodingafterlife/sweetcode/blob/main/background.js): `background.js`
- [Reward feedback](https://github.com/decodingafterlife/sweetcode/blob/main/content.js): `content.js`

### Access control

- [Allowance state](https://github.com/decodingafterlife/sweetcode/blob/main/background.js): `background.js`
- [Daily and period reset](https://github.com/decodingafterlife/sweetcode/blob/main/background.js): `background.js`
- [Social-site matching](https://github.com/decodingafterlife/sweetcode/blob/main/background.js): `background.js`
- [Navigation gate](https://github.com/decodingafterlife/sweetcode/blob/main/background.js): `background.js`
- [Access countdown](https://github.com/decodingafterlife/sweetcode/blob/main/background.js): `background.js`
- [Blocked page](https://github.com/decodingafterlife/sweetcode/blob/main/blocked.html): `blocked.html`

### Hint assistant

- [Extension popup](https://github.com/decodingafterlife/sweetcode/blob/main/popup.html): `popup.html`
- [Popup behavior](https://github.com/decodingafterlife/sweetcode/blob/main/popup.js): `popup.js`
- [Hint and model settings](https://github.com/decodingafterlife/sweetcode/blob/main/popup.js): `popup.js`
- [Problem context extraction](https://github.com/decodingafterlife/sweetcode/blob/main/popup.js): `popup.js`
- [Hint generation](https://github.com/decodingafterlife/sweetcode/blob/main/popup.js): `popup.js`

### Other components

- **Learner**
- **LeetCode**
- **Social sites**
- **Groq API**

## Connections

- LeetCode → Submission tracking: submits to
- Submission tracking → Extension coordinator: notifies
- Extension coordinator → LeetCode: fetches history
- Extension coordinator → Reward calculation: checks difficulty
- Reward calculation → Allowance state: adds reward
- Extension coordinator → Reward feedback: dispatches popup
- Reward feedback → Learner: shows reward
- Extension coordinator → Allowance state: loads and saves
- Daily and period reset → Allowance state: resets
- Extension coordinator → Daily and period reset: checks schedule
- Extension coordinator → Social-site matching: checks URL
- Extension coordinator → Navigation gate: registers navigation
- Navigation gate → Social-site matching: tests destination
- Navigation gate → Blocked page: redirects
- Extension coordinator → Access countdown: starts timer
- Access countdown → Allowance state: reads and decrements
- Access countdown → Blocked page: redirects at zero
- Learner → Extension popup: opens
- Extension popup → Popup behavior: runs
- Popup behavior → Hint and model settings: loads and saves
- Hint and model settings → Allowance state: reads allowance
- Popup behavior → Problem context extraction: extracts problem
- Problem context extraction → LeetCode: reads page
- Popup behavior → Hint generation: requests hint
- Hint generation → Groq API: sends context
- Groq API → Hint generation: returns hint
- Hint generation → Extension coordinator: requests deduction
- Extension coordinator → Allowance state: deducts hint cost
- Hint generation → Learner: displays hint
- Learner → Social sites: visits
- Navigation gate → Social sites: allows when funded
