How adityaboghara/better-moodle works
1. What this repo is
Better-Moodle is a client-side userscript that runs in the browser on Moodle pages. There is no central backend for the product itself; the script injects UI, patches page behavior, and stores user preferences locally.
2. Top-level runtime split
The main runtime is under src/, with a small set of entrypoints like core.tsx, cleanupStorage.ts, migrateStorage.ts, and unsupportedBrowserCheck.tsx. The core runtime is what users normally get; the other entrypoints handle storage maintenance and browser compatibility warnings.
3. Core orchestration
src/core.tsx is the bootstrapping layer. It ties together feature registration, university-specific configuration, i18n, settings, update checks, and global fixes before individual features run. src/core/globalFixes contains patches that apply broadly across Moodle, independent of a specific feature toggle.
4. Feature-based architecture
Most functionality is organized as independent modules in src/features/*. Each feature is typically self-contained, with its own entry file, styles, and often its own translations. This lets the build include only the features relevant to the selected university/configuration and lets users enable/disable them from settings.
5. Shared UI and infrastructure
src/_lib holds the common building blocks: reusable React components, drawers/modals, settings controls, DOM helpers, network helpers, storage wrappers, template helpers, and Moodle-specific string/semver/time utilities. This is the internal platform layer that features build on.
6. State and persistence
User preferences and migration logic are handled through TempStorage, migrateStorage.ts, and cleanupStorage.ts. The script persists settings in browser storage, migrates older data formats, and can clean up obsolete keys. That means feature state lives entirely on the client side.
7. University-specific boundaries
The repo is clearly split by institution. configs/ contains per-university and global JSON config, while src/fixes/cau and src/fixes/uzl contain institution-specific fixes. The README also shows separate distributed builds/downloads for CAU Kiel and Universität zu Lübeck, so the build output is university-targeted rather than one generic bundle.
8. External Moodle integration
The types/require.js tree shows strong coupling to Moodle’s AMD/RequireJS modules and templates. Better-Moodle does not replace Moodle; it extends it by consuming Moodle’s internal modules, DOM structure, and templates, which is why those ambient typings are a major architectural boundary.
9. Localized content and templating
src/i18n contains the language packs and formatting helpers, while many feature folders also have their own i18n subtrees. Mustache templates and SCSS modules are used where features need Moodle-compatible markup or scoped styling. The result is a localized, theme-aware userscript rather than a single-language overlay.
10. Feature-specific external data flows
Some features integrate third-party or campus services. Examples include weather providers (open-meteo, openweathermap, visualcrossing, wttr.in), canteen/menu parsing, NINA emergency integration, and event/semester data from data/*.json. These modules adapt external data into the script’s UI and settings model.
11. Auxiliary parser/runtime
The ics-parser/ directory is a separate TypeScript worker-style component with its own Wrangler config. It indicates a distinct parsing runtime for calendar/ICS-style data, separate from the browser userscript bundle.
12. Build and distribution pipeline
The repo uses a custom Vite-based toolchain in tooling/ to assemble the userscript, resolve features/fixes, process SCSS and Mustache, inject legacy/polyfill behavior, and format post-build output. Release automation is handled via GitHub Actions and Release Please, which produce the downloadable .user.js artifacts referenced in the README.
13. Testing and quality gates
Tests live under __tests__ and use Vitest plus browser-oriented helpers/Puppeteer. CI workflows cover build, test, config validation, icon generation, release automation, and download tracking, so the repository is structured as a packaged extension-like artifact with strong build-time verification.
Main entry points: core.tsx Core · framework.ts Tooling · index.ts Courses · TempStorage.ts TempStorage
Components 25
Runtime
Userscript entrypoints and browser-facing boot logic.
- Core · Main startup path that wires config, settings, i18n, fixes, and features.
src/core.tsx - Settings UI · Client-side settings surface for enabling features and preferences.
src/settingsModal.tsx - Migrate Storage · Upgrades persisted user data to newer formats.
src/migrateStorage.ts - Cleanup Storage · Removes obsolete local keys and stale data.
src/cleanupStorage.ts - Browser Check · Warns when the host browser is unsupported.
src/unsupportedBrowserCheck.tsx - Global Fixes · Moodle-wide behavior patches applied independently of feature toggles.
src/core/globalFixes/index.ts
Shared Platform
Common UI, storage, i18n, and Moodle integration helpers.
- Feature Base · Common registration and lifecycle primitives for features.
src/_lib/Feature.tsx - TempStorage · Browser storage abstraction used for preferences and migrations.
src/_lib/TempStorage.ts - Shared UI · Reusable drawers, modals, blocks, settings controls, and related UI pieces.
src/_lib/Components.tsx - DOM Helpers · Helpers for querying and patching Moodle page structure.
src/_lib/DOM.ts - Moodle AMD · Integration layer for Moodle RequireJS modules and templates.
src/_lib/require.js.ts - i18n Core · Shared translation formatting and language loading.
src/i18n/i18n.ts
Features
Independent Moodle feature modules grouped by subsystem.
- Courses · Course-page enhancements such as cards, grades, navigation, and role changes.
src/features/courses/index.ts - General · Global visual and navigation tweaks reused across Moodle pages.
src/features/general/index.ts - Dashboard · Dashboard layout and course block/sidebar adjustments.
src/features/dashboard/index.ts - Messages · Messaging enhancements such as hotkeys and markdown support.
src/features/messages/index.ts - Weather · Weather widget backed by multiple third-party providers.
src/features/weather/index.tsx - Canteen · Menu and canteen integration for campus food plans.
src/features/speiseplan/index.tsx - NINA · Emergency alert integration for campus- or region-level notices.
src/features/nina/index.tsx - Marquee · Top-bar marquee and event/time announcements.
src/features/navbarMarquee/index.ts - CAU Fixes · University-specific patches for CAU Kiel.
src/fixes/cau/loginDivider.tsx - UZL Fixes · University-specific patches for Universität zu Lübeck.
src/fixes/uzl/zensus.ts
Build
Custom Vite-based tooling and auxiliary runtime pieces.
- Tooling · Custom build and assembly pipeline for userscript packaging.
tooling/framework.ts - ICS Parser · Separate worker-style parser for calendar and recurrence data.
ics-parser/index.ts
External Boundaries
Typed interfaces to Moodle, browser APIs, and third-party data.
- Require Types · Typed boundary describing Moodle AMD modules, templates, and selectors.
types/require.d.ts
Connections 26
- Core → Feature Base: registers · Core bootstraps feature lifecycle and registration.
- Core → Global Fixes: applies · Loads broad Moodle patches before feature execution.
- Core → i18n Core: loads · Initializes language packs and shared formatting.
- Core → TempStorage: reads/writes · Uses local storage for preferences and runtime state.
- Core → Settings UI: opens · Wires settings UI into the userscript.
- Core → Courses: enables · Installs course-related feature bundle.
- Core → General: enables · Installs global visual and navigation tweaks.
- Core → Dashboard: enables · Installs dashboard-specific enhancements.
- Core → Messages: enables · Installs message composer and readability features.
- Core → Weather: enables · Installs weather widget features.
- Core → Canteen: enables · Installs canteen/menu integration.
- Core → NINA: enables · Installs emergency alert integration.
- Core → Marquee: enables · Installs marquee/event announcement features.
- Core → CAU Fixes: targets · Includes CAU-specific fixes when configured.
- Core → UZL Fixes: targets · Includes UZL-specific fixes when configured.
- Migrate Storage → TempStorage: migrates · Transforms persisted settings to newer schemas.
- Cleanup Storage → TempStorage: cleans · Removes obsolete persisted data.
- Browser Check → Moodle AMD: detects · Uses Moodle/browser environment assumptions for compatibility warnings.
- Courses → DOM Helpers: patches · Manipulates Moodle page structure and course views.
- Courses → Shared UI: renders · Uses shared UI controls and drawers.
- Messages → DOM Helpers: patches · Extends message page behavior and editing flows.
- Weather → Tooling: fetches · Consumes external weather providers through the feature build.
- Canteen → Tooling: fetches · Consumes campus menu data and parser adapters.
- NINA → Tooling: fetches · Consumes external emergency alert data.
- Tooling → Require Types: validates · Build-time typing boundary for Moodle integrations.
- Tooling → ICS Parser: bundles · Connects the main userscript with the separate parser runtime.