# cm090/rhitweaks architecture

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

- Interactive diagram: https://gitdiagram.com/cm090/rhitweaks
- Repository: https://github.com/cm090/rhitweaks

## Overview

##### Project Type and Purpose
- This project is a browser extension (specifically for Chromium, with some Firefox compatibility files present) aimed at modifying and enhancing the user experience on RHIT websites.
- The functionality is split across various content injection points (such as banners, moodle modifications, print components, and schedule adjustments) and a user interface provided by a popup.

##### File Structure
- Top-level configuration and tooling files (e.g., package.json, rollup.config.js, tsconfig.json, .eslintrc.js, and .prettierrc.yaml) indicate a well-organized, modern JavaScript/TypeScript project.
- The “src” directory houses the core source code:
- The background script (src/background.ts) handles long-running processes and messaging.
- The “content” subdirectory contains subdirectories (banner, moodle, print, schedule, common) that house content scripts, HTML templates, CSS, and modular TypeScript files corresponding to different webpage enhancements.
- The “pages” subdirectory (especially under src/pages/popup) holds React components and supporting files for the extension’s popup UI.
- The “compatibility” folder contains modifications and manifest files supporting Firefox, underscoring cross-browser considerations.
- This structure shows a clear separation of concerns: background processes, injected content scripts for DOM manipulation/enhancement, and a standalone UI layer for settings and user interaction.

##### README File for Additional Insights
- The README confirms the project is a Chromium extension (with linkage to Chrome Web Store) and provides steps for development, implying active preparation for live development and build processes.
- It references this extension as the successor to a previous project, hinting at iterative improvements and maintained codebases.

a. Main Components to Include:
- Extension Core:
- Manifest (src/manifest.json) that defines the extension, permissions, and initialization scripts.
- Background Script (src/background.ts) that manages event handlers and interprocess communication.
- Content Scripts:
- Banner Scripts (src/content/banner/*): Modules, HTML, and CSS that dynamically modify banner elements on targeted pages.
- Moodle Tweaks (src/content/moodle/*): Scripts and modules that inject enhancements into Moodle pages, including UI components like buttons and search modals.
- Print Enhancements (src/content/print/*): Code that controls modifications on print-related pages.
- Schedule Adjustments (src/content/schedule/*): Scripts that reformat or enhance schedule displays.
- Shared/Utility Modules (within src/content/common and other common files such as src/defaults.ts) for data and configuration used across various injections.
- Popup UI:
- React-based popup components (src/pages/popup/components/*) including settings pages and dialogs that let the user configure which tweaks are active.
- The popup’s main page (src/pages/popup/index.tsx and its associated index.html and styles.css).
- Build/Tooling Components:
- Build configuration (rollup.config.js) and dependency management (package.json) that tie the project together.
- Linting and formatting configurations (.eslintrc.js, .prettierrc.yaml).

b. Relationships and Interactions:
- The extension manifest directs the browser to load the background script and inject specific content scripts into web pages based on URL matching rules.
- Background processes may communicate (using message passing APIs) with both the popup UI for settings and with content scripts to manage dynamic behavior.
- The React popup provides a front-end interface for configuration settings, which can influence the behavior of the content scripts.
- Modular content scripts (grouped by functionality such as banner, moodle, print, and schedule) interact directly with the web page’s DOM to implement the tweaks.

c. Architectural Patterns & Design Principles:
- Modular decomposition: Each enhancement (banner, moodle, print, schedule) is broken into its own directory with clearly defined modules.
- Separation of concerns: Distinct layers separate background processes (logic and messaging), content script injections (DOM manipulation), and UI presentation (React-based popup).
- Configuration-driven build and lint processes support maintainability and code quality.
- Cross-browser compatibility is addressed by having a designated folder (compatibility) for Firefox-specific changes.

d. Technologies, Frameworks, and Libraries:
- TypeScript is used throughout for robust type safety.
- React is used for building the popup UI.
- Rollup is used as the module bundler.
- Standard development tools: ESLint, Prettier, and npm scripts for build and development.
- Chromium extension APIs as defined in the manifest file.

##### Final Advice
- Be as detailed as possible. Don’t hesitate to break down umbrella components (like “Content Scripts”) into their individual submodules, showing the relationships between general-purpose modules (like shared utilities) and feature-specific modules.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Tooling & Configuration
    subgraph "Tooling & Configuration"
        Package["package.json"]:::config
        Rollup["rollup.config.js"]:::config
        Tsconfig["tsconfig.json"]:::config
        ESLint[".eslintrc.js"]:::config
        Prettier[".prettierrc.yaml"]:::config
    end

    %% Browser Extension Core
    subgraph "Browser Extension Core"
        Manifest["Manifest"]:::core
        Background["Background Script"]:::core
    end

    %% Content Injection Layer
    subgraph "Content Injection Layer"
        %% Banner Subgraph
        subgraph "Banner"
            BannerScript["Banner Script"]:::content
            BannerTemplate["Banner Template"]:::content
            BannerModules["Banner Modules"]:::content
            BannerStyles["Banner Styles"]:::content
        end
        %% Moodle Subgraph
        subgraph "Moodle"
            MoodleScript["Moodle Script"]:::content
            HeaderButtons["Header Buttons"]:::content
            SearchModal["Search Modal"]:::content
            MoodleStyles["Moodle Styles"]:::content
            MoodleModules["Moodle Modules"]:::content
        end
        %% Print Subgraph
        subgraph "Print"
            PrintScript["Print Script"]:::content
            PrintModules["Print Modules"]:::content
        end
        %% Schedule Subgraph
        subgraph "Schedule"
            ScheduleScript["Schedule Script"]:::content
            ScheduleTemplates["Schedule Templates"]:::content
            ScheduleStyles["Schedule Styles"]:::content
        end
        Utilities["Shared Utilities"]:::util
        GlobalDefaults["Global Defaults"]:::util
    end

    %% User Interface Layer
    subgraph "User Interface Layer"
        PopupMain["Popup Main UI"]:::ui
        PopupComponents["Popup Components"]:::ui
        PopupStyles["Popup Styles"]:::ui
    end

    %% Cross-Browser Compatibility
    subgraph "Cross-Browser Compatibility"
        Firefox["Firefox Compatibility"]:::compat
    end

    %% Relationships
    %% Manifest loads background and content scripts
    Manifest -->|"loads"| Background
    Manifest -->|"injects"| BannerScript
    Manifest -->|"injects"| MoodleScript
    Manifest -->|"injects"| PrintScript
    Manifest -->|"injects"| ScheduleScript

    %% Background communicates with content scripts and popup UI
    Background -->|"msg"| BannerScript
    Background -->|"msg"| MoodleScript
    Background -->|"msg"| PrintScript
    Background -->|"msg"| ScheduleScript
    Background <-->|"msg"| PopupMain

    %% Content scripts use shared utilities and defaults
    BannerScript -->|"uses"| Utilities
    BannerScript -->|"uses"| GlobalDefaults

    MoodleScript -->|"uses"| Utilities
    MoodleScript -->|"uses"| GlobalDefaults

    PrintScript -->|"uses"| Utilities
    PrintScript -->|"uses"| GlobalDefaults

    ScheduleScript -->|"uses"| Utilities
    ScheduleScript -->|"uses"| GlobalDefaults

    %% Click Events for Tooling & Configuration
    click Package "https://github.com/cm090/rhitweaks/blob/main/package.json"
    click Rollup "https://github.com/cm090/rhitweaks/blob/main/rollup.config.js"
    click Tsconfig "https://github.com/cm090/rhitweaks/blob/main/tsconfig.json"
    click ESLint "https://github.com/cm090/rhitweaks/blob/main/.eslintrc.js"
    click Prettier "https://github.com/cm090/rhitweaks/blob/main/.prettierrc.yaml"

    %% Click Events for Browser Extension Core
    click Manifest "https://github.com/cm090/rhitweaks/blob/main/src/manifest.json"
    click Background "https://github.com/cm090/rhitweaks/blob/main/src/background.ts"

    %% Click Events for Banner Content Script
    click BannerScript "https://github.com/cm090/rhitweaks/blob/main/src/content/banner/banner.ts"
    click BannerTemplate "https://github.com/cm090/rhitweaks/blob/main/src/content/banner/home-page.html"
    click BannerModules "https://github.com/cm090/rhitweaks/tree/main/src/content/banner/modules"
    click BannerStyles "https://github.com/cm090/rhitweaks/blob/main/src/content/banner/styles.css"

    %% Click Events for Moodle Content Script
    click MoodleScript "https://github.com/cm090/rhitweaks/blob/main/src/content/moodle/moodle.ts"
    click HeaderButtons "https://github.com/cm090/rhitweaks/blob/main/src/content/moodle/header-buttons.html"
    click SearchModal "https://github.com/cm090/rhitweaks/blob/main/src/content/moodle/search-modal.html"
    click MoodleStyles "https://github.com/cm090/rhitweaks/blob/main/src/content/moodle/styles.css"
    click MoodleModules "https://github.com/cm090/rhitweaks/tree/main/src/content/moodle/modules"

    %% Click Events for Print Content Script
    click PrintScript "https://github.com/cm090/rhitweaks/blob/main/src/content/print/print.ts"
    click PrintModules "https://github.com/cm090/rhitweaks/tree/main/src/content/print/modules"

    %% Click Events for Schedule Content Script
    click ScheduleScript "https://github.com/cm090/rhitweaks/blob/main/src/content/schedule/schedule.ts"
    click ScheduleTemplates "https://github.com/cm090/rhitweaks/tree/main/src/content/schedule"
    click ScheduleStyles "https://github.com/cm090/rhitweaks/blob/main/src/content/schedule/styles.css"

    %% Click Events for Shared/Utility Modules
    click Utilities "https://github.com/cm090/rhitweaks/tree/main/src/content/common"
    click GlobalDefaults "https://github.com/cm090/rhitweaks/blob/main/src/defaults.ts"

    %% Click Events for Popup User Interface
    click PopupMain "https://github.com/cm090/rhitweaks/blob/main/src/pages/popup/index.tsx"
    click PopupComponents "https://github.com/cm090/rhitweaks/tree/main/src/pages/popup/components"
    click PopupStyles "https://github.com/cm090/rhitweaks/blob/main/src/pages/popup/styles.css"

    %% Click Events for Cross-Browser Compatibility
    click Firefox "https://github.com/cm090/rhitweaks/tree/main/compatibility"

    %% Styles
    classDef config fill:#AED6F1,stroke:#1F618D,stroke-width:2px;
    classDef core fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef content fill:#D5F5E3,stroke:#27AE60,stroke-width:2px;
    classDef util fill:#FADBD8,stroke:#C0392B,stroke-width:2px;
    classDef ui fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
    classDef compat fill:#FDEDEC,stroke:#E74C3C,stroke-width:2px;
```
