# jtcheng26/canvas-task-extension architecture

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

- Interactive diagram: https://gitdiagram.com/jtcheng26/canvas-task-extension
- Repository: https://github.com/jtcheng26/canvas-task-extension

## Overview

##### Main Components
- Browser Extension Entry Points:
– Background Page: Shows up in src/pages/Background (background scripts handling events and extension life cycle).
– Content Scripts: Found in src/pages/Content. These inject UI elements into Canvas pages, handle DOM interactions, and drive the dynamic functionalities.
– Options Page: Provides configuration options for the user; located in src/pages/Options.
- Shared Modules and Libraries:
– UI Components: Under src/pages/Content/modules/components. They include buttons, dropdowns, charts, and task cards. Many of these components are designed in a React/TypeScript paradigm.
– Plugins: Located under src/pages/Content/modules/plugins. These provide adaptability for various LMS platforms (Canvas, Blackboard, Gradescope, Brightspace) with their own loaders and utility functions.
– Contexts, Hooks, and Utilities: Under src/pages/Content/modules/contexts, hooks, and utils, offering state management (via contexts and custom hooks) and helper functions to determine settings, dark mode etc.
– Asset Handling: Under src/assets, which provides images and manifests (manifest-chrome.json and manifest-firefox.json) to support different browsers.
- Testing & Development Infrastructure:
– E2E and integration tests under src/pages/Content/modules/tests.
– Build configuration files (webpack.config.js, package.json, tsconfig.json, etc.) that dictate how the application is bundled and linted (.eslintrc, .prettierrc, etc.).

##### Relationships and Data Flow
- The Background script acts as a controller for long-running processes and extension events, communicating with the Content scripts.
- Content scripts inject the React-based UI into the Canvas pages, drawing on multiple shared components (for tasks, progress bars, and settings).
- The Plugins act as adapters or layers that detect the specific LMS (e.g., Canvas) using files like detectCanvas.ts and run in their environment, then load assignments or course information from external APIs or page DOM.
- The Options and Popup pages provide user interaction for configuration and quick task views, reading from and writing to persistent settings.
- All components are tied together with state management (contexts and hooks) which synchronize data (assignments, course info, user preferences) across different parts of the extension.

##### Architectural Patterns and Design Principles
- Component-Based Architecture: The UI is modularized into React components, each handling a specific part of the UI (headers, buttons, charts, etc.).
- Separation of Concerns: There’s a clear split between the background operations, content injection of UI, and user configuration, which allows ease of testing and extension.
- Plugin/Adapter Pattern: Notice the modular “plugins” folders; this pattern provides a way to support different LMSs (Canvas, Blackboard, etc.) through interchangeable loaders and utils.
- Test-Driven Development: The presence of unit and integration tests shows an emphasis on reliability.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "Browser Extension Entry Points"
        BS["Background Script\n(src/pages/Background)"]:::backend
        CS["Content Scripts\n(src/pages/Content)"]:::frontend
        Popup["Popup Page UI\n(src/pages/Popup)"]:::frontend
        Options["Options Page UI\n(src/pages/Options)"]:::frontend
    end

    subgraph "Shared Modules & Libraries"
        UI["UI Components\n(src/pages/Content/modules/components)"]:::shared
        PL["Plugins (LMS Integrations)\n(src/pages/Content/modules/plugins)"]:::shared
        CT["Contexts (State Management)\n(src/pages/Content/modules/contexts)"]:::shared
        HK["Hooks (State Management)\n(src/pages/Content/modules/hooks)"]:::shared
        UT["Utilities (Helper Functions)\n(src/pages/Content/modules/utils)"]:::shared
        AS["Asset Handling\n(src/assets)"]:::shared
    end

    subgraph "Testing & Development Infrastructure"
        TS["Tests (E2E & Integration)\n(src/pages/Content/modules/tests)"]:::test
        SB["Storybook Setup\n(.storybook)"]:::test
        BC["Build Configuration\n(webpack.config.js, package.json, etc.)"]:::test
    end

    BS -->|"communicates"| CS
    CS -->|"injects_UI_into"| UI
    CS -->|"integrates_with"| PL
    CS -->|"loads_assets"| AS
    Popup -->|"updates_state"| CT
    Options -->|"updates_state"| CT
    UI -->|"uses"| CT
    UI -->|"uses"| HK
    PL -->|"uses_utilities"| UT
    SB -->|"visualizes"| UI
    TS -->|"tests"| UI
    TS -->|"tests"| PL
    BC -->|"bundles"| BS
    BC -->|"bundles"| CS
    BC -->|"bundles"| Popup
    BC -->|"bundles"| Options

    click BS "https://github.com/jtcheng26/canvas-task-extension/blob/main/src/pages/Background/index.ts"
    click CS "https://github.com/jtcheng26/canvas-task-extension/blob/main/src/pages/Content/index.ts"
    click Popup "https://github.com/jtcheng26/canvas-task-extension/tree/main/src/pages/Popup"
    click Options "https://github.com/jtcheng26/canvas-task-extension/tree/main/src/pages/Options"
    click UI "https://github.com/jtcheng26/canvas-task-extension/tree/main/src/pages/Content/modules/components"
    click PL "https://github.com/jtcheng26/canvas-task-extension/tree/main/src/pages/Content/modules/plugins"
    click CT "https://github.com/jtcheng26/canvas-task-extension/tree/main/src/pages/Content/modules/contexts"
    click HK "https://github.com/jtcheng26/canvas-task-extension/tree/main/src/pages/Content/modules/hooks"
    click UT "https://github.com/jtcheng26/canvas-task-extension/tree/main/src/pages/Content/modules/utils"
    click AS "https://github.com/jtcheng26/canvas-task-extension/tree/main/src/assets"
    click TS "https://github.com/jtcheng26/canvas-task-extension/tree/main/src/pages/Content/modules/tests"
    click SB "https://github.com/jtcheng26/canvas-task-extension/blob/main/.storybook"
    click BC "https://github.com/jtcheng26/canvas-task-extension/blob/main/webpack.config.js"

    classDef backend fill:#FDEDEC,stroke:#E74C3C,stroke-width:2px;
    classDef frontend fill:#E3F2FD,stroke:#3498DB,stroke-width:2px;
    classDef shared fill:#E8F5E9,stroke:#27AE60,stroke-width:2px;
    classDef test fill:#FFF3E0,stroke:#F39C12,stroke-width:2px;
```
