# ccu-class/homework2calendar architecture

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

- Interactive diagram: https://gitdiagram.com/ccu-class/homework2calendar
- Repository: https://github.com/ccu-class/homework2calendar

## Overview

The project “Moodle to Google Calendar Extension” is a Chrome/Edge browser extension that helps students export Moodle (eCourse2) calendar events to Google Calendar. Its purpose is to provide a convenient one-click solution to either download a .ics calendar file or directly update Google Calendar with events, streamlining the management of academic deadlines.

##### Main Components
- Chrome Extension Components: Since this is a Manifest V3 extension, include components such as:
- Manifest (src/manifest.json): The central configuration that defines extension permissions, background scripts, content scripts, and popup UI.
- Background Script (src/js/background.js): Manages persistent tasks, event listeners, and communication between components.
- Content Scripts (src/js/content.js, src/js/calendar.js, etc.): Injected into Moodle pages for harvesting calendar events.
- Popup UI (src/popup.html along with src/js/popup.js): Provides the interface for user interaction (e.g., selecting month/year, triggering export/import).
- Authentication and OAuth: Highlight integration with Google OAuth using `chrome.identity` and `launchWebAuthFlow` (src/js/oauth.js).
- Styling and Build Tools: Mention Tailwind CSS (src/css/input.css) for styling, while Vite (vite.config.js) is used as the build tool. ESLint (eslint.config.mjs) and Prettier (.prettierrc) are used for code quality.
- Supporting Scripts: Note additional scripts such as build/deployment scripts (upload.sh, zip_dist.sh) and markdown-to-HTML conversion (scripts/md-to-html.mjs).

##### Interactions Between Components
- User Action (Popup) → triggers events in popup.js.
- Popup → communicates with background.js (for authentication and data fetching).
- The Content Scripts are injected to extract calendar events from Moodle and then relay these events to either the background script or directly prepare download (.ics) or update Google Calendar.
- The OAuth component (oauth.js) interacts with external Google services:
- Background or Popup script initiates OAuth flow that uses secure communication with Google’s authentication endpoints.
- Build and Packaging:
- Use Vite as the build tool to bundle the extension code.
- That the end result is assembled into a distributable folder (dist/ directory produced after running “npm run build”).

##### Architectural Patterns and Design Principles
- Modular Structure: Code is organized into separate directories – JS logic (src/js), CSS styling (src/css) – representing clean separation of concerns.
- Event-Driven Communication: Use of background messaging and events to coordinate among popup, content scripts, and OAuth handling.
- Declarative Configuration: The manifest defines extension components, permissions, and resource locations.
- Developer Tooling: Incorporate development practices like linting and code formatting (via ESLint and Prettier).

##### Additional Details
- That deployment and build steps are captured even though they are developer-focused (represented by the configuration files like vite.config.js, tailwind.config.js, and GitHub Actions workflows in .github/workflows).
- Clear separation between user interface (Popup) and the extension’s processing logic (background and content scripts), which is central to the design.
- That the privacy and security aspects are important (the extension only accesses data upon user action, limited Google OAuth permissions).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Extension Core Components
    subgraph "Extension Core"
        M["Manifest Configuration (src/manifest.json)"]:::internal
        B["Background Script (src/js/background.js)"]:::internal
        P["Popup UI (src/popup.html + src/js/popup.js)"]:::internal
        C["Content Scripts (src/js/content.js & src/js/calendar.js)"]:::internal
        O["Authentication/OAuth (src/js/oauth.js)"]:::internal
    end

    %% Build and Tooling Components
    subgraph "Build & Tooling"
        S["Styling (src/css/input.css & tailwind.config.js)"]:::tooling
        BP["Build & Packaging Tools (vite.config.js, upload.sh, zip_dist.sh, scripts/md-to-html.mjs)"]:::tooling
        D["Developer Tooling (eslint.config.mjs & .prettierrc)"]:::tooling
    end

    %% External Services
    subgraph "External Services"
        G["Google Services (OAuth & Calendar API)"]:::external
        MOO["Moodle Platform"]:::external
    end

    %% Data flow connections among extension components
    M -->|"defines"| B
    M -->|"defines"| P
    M -->|"defines"| C
    M -->|"defines"| O

    P -->|"triggerAction"| B
    P -->|"initiateAuth"| O
    C -->|"sendEventData"| B

    %% Communication with external services
    O -->|"authTokenFlow"| G
    B -->|"calendarUpdate"| G
    C -- "scrapeEvents" --> MOO

    %% Styles for Build & Tooling (informational only, not part of runtime)
    S --- BP
    S --- D

    %% Click Events
    click M "https://github.com/ccu-class/homework2calendar/blob/main/src/manifest.json"
    click B "https://github.com/ccu-class/homework2calendar/blob/main/src/js/background.js"
    click P "https://github.com/ccu-class/homework2calendar/blob/main/src/popup.html"
    click P "https://github.com/ccu-class/homework2calendar/blob/main/src/js/popup.js"
    click C "https://github.com/ccu-class/homework2calendar/blob/main/src/js/content.js"
    click C "https://github.com/ccu-class/homework2calendar/blob/main/src/js/calendar.js"
    click O "https://github.com/ccu-class/homework2calendar/blob/main/src/js/oauth.js"
    click S "https://github.com/ccu-class/homework2calendar/blob/main/src/css/input.css"
    click S "https://github.com/ccu-class/homework2calendar/blob/main/tailwind.config.js"
    click BP "https://github.com/ccu-class/homework2calendar/blob/main/vite.config.js"
    click BP "https://github.com/ccu-class/homework2calendar/blob/main/upload.sh"
    click BP "https://github.com/ccu-class/homework2calendar/blob/main/zip_dist.sh"
    click BP "https://github.com/ccu-class/homework2calendar/blob/main/scripts/md-to-html.mjs"
    click D "https://github.com/ccu-class/homework2calendar/blob/main/eslint.config.mjs"
    click D "https://github.com/ccu-class/homework2calendar/blob/main/.prettierrc"

    %% Styles
    classDef internal fill:#bbf,stroke:#333,stroke-width:2px;
    classDef external fill:#fbb,stroke:#333,stroke-width:2px;
    classDef tooling fill:#bfb,stroke:#333,stroke-width:2px;
```
