# ujjwalsharma01/leetcode2ankiplus architecture

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

- Interactive diagram: https://gitdiagram.com/ujjwalsharma01/leetcode2ankiplus
- Repository: https://github.com/ujjwalsharma01/leetcode2ankiplus

## Overview

##### Main Components
- Browser Environment & Userscript:
– LeetCode Web Interface: The webpage where users solve problems.
– Userscript (leetcode2ankibyUjjwal.user.js): Injected into the browser via Tampermonkey/Violentmonkey, responsible for detecting problem events, extracting solution data, and offering UI controls (e.g., “Save to Anki”, “Save to Sheet”).
- Anki Integration Component:
– Anki Application running on the user’s machine with the AnkiConnect add-on.
– API communication from the userscript to the locally running AnkiConnect (typically over a specific port).
- Google Sheets & Google Apps Script:
– Google Apps Script File (GoogleAppsScript.gs) deployed as a Web App that receives problem data submissions.
– Google Sheets (the database) holding problem data (columns like Timestamp, ID, Title, etc.) and interfacing with the SRS.
– Spaced Repetition System Script (LeetcodeSRS.gs) that operates within Google Sheets to manage review scheduling.
- Direct Test Utility:
– The Node.js script (direct_submission_node.js) which is used for testing the connectivity between the Google Apps Script endpoint and Google Sheets.

##### Relationships and Data Flow
– The userscript in the browser monitors LeetCode pages, captures problem completion and solution details, and initiates two key actions:
- It sends an HTTP request to the Google Apps Script Web App URL (via the googleScriptUrl configuration) to log the solved problem data to Google Sheets.
- It communicates with AnkiConnect (running locally) via an API call to create well-formatted flashcards.
– The Google Apps Script acts as an intermediary, receiving data from the userscript and updating the Google Sheet.
– The SRS script within the Google Sheet (LeetcodeSRS.gs or the separately opened SpacedRepetitionSystem.gs) manages review scheduling and user interactions directly within the spreadsheet interface.
– The Node.js script facilitates direct testing by simulating the submission of problem data to the Google Apps Script endpoint.

##### Architectural Patterns and Design Principles
– Client-Server Communication: Emphasize the communication flows between the browser (client-side userscript) and the Google Apps Script (server-side endpoint), as well as local inter-process communication with AnkiConnect.
– Extensibility: Note the possibility to update or swap out components (e.g., different problem detection strategies within the script) without impacting the entire architecture.

##### Relevant Technologies and Frameworks
– JavaScript is the primary programming language both in the userscript and the Apps Script files.
– Tampermonkey/Violentmonkey provides the runtime for the browser userscript.
– Google Apps Script and Google Sheets serve as lightweight backend services.
– Node.js is used for running test scripts.
– AnkiConnect is the bridge used to integrate with the Anki application.

##### Additional Details to Capture
– Integration points, especially where configuration variables (e.g., “googleScriptUrl” in the userscript) come into play.
– The overall flow from detection (when a problem is solved) to data logging and card generation.
– Where extensibility or error-handling components are implemented, such as the robust error handling strategy and retry logic described in the README.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Side
    subgraph "Client Side"
        LC("LeetCode Web Interface"):::client
        US("Userscript – LeetCode2Anki Plus"):::client
    end

    %% Integration Components
    subgraph "Integration"
        ANKI("Anki (with AnkiConnect)"):::external
    end

    %% Server Side
    subgraph "Server Side"
        GAS("Google Apps Script Web App"):::server
        GS("Google Sheet – Problem Log & SRS"):::server
    end

    %% Direct Testing Utility (outside subgraph for emphasis)
    DS("Direct Testing Utility (Node.js)"):::server

    %% Data Flow Connections
    LC -->|"triggers"| US
    US -->|"createFlashcard"| ANKI
    US -->|"logSubmission"| GAS
    GAS -->|"updates"| GS
    DS -->|"simulateSubmission"| GAS

    %% Click Events
    click US "https://github.com/ujjwalsharma01/leetcode2ankiplus/blob/main/leetcode2ankibyUjjwal.user.js"
    click GAS "https://github.com/ujjwalsharma01/leetcode2ankiplus/blob/main/GoogleAppsScript.gs"
    click GS "https://github.com/ujjwalsharma01/leetcode2ankiplus/blob/main/LeetcodeSRS.gs"
    click DS "https://github.com/ujjwalsharma01/leetcode2ankiplus/blob/main/direct_submission_node.js"

    %% Styles
    classDef client fill:#9fc5e8,stroke:#6d9eeb,stroke-width:2px;
    classDef external fill:#93c47d,stroke:#6aa84f,stroke-width:2px;
    classDef server fill:#f6b26b,stroke:#e69138,stroke-width:2px;
```
