How moodlehq/moodleapp works
Project type and purpose
• This is a hybrid mobile client (“Moodle App”) built with Ionic/Angular and Cordova.
• It provides a full-featured Moodle experience on mobile: UI (pages, components), offline‐first data caching, sync, plugin support, theming, testing.
• It connects to a remote Moodle server via REST web services, uses a local SQLite database for offline storage, and integrates native capabilities (camera, storage, push notifications) via Cordova plugins.
High‐level analysis of the file structure
• Top‐level config/deployment: Dockerfile, GitHub workflows, Travis, nginx.conf, gulp scripts, Cordova config.xml.
• Native plugin wrapper: cordova-plugin-moodleapp (in /cordova-plugin-moodleapp) providing low-level secure storage, diagnostics, referrer.
• Build and test tooling: gulp/ task scripts, Jest, Behat plugin, local_moodleappbehat tests.
• Source code under src/:
– /app: root Angular module, routing, app component.
– /core: shared services, classes, delegates, database proxies, native-to-Angular adapters, interceptors.
– /addons: feature modules (forums, quizzes, calendar, messages, etc.), each structured as Angular modules with pages, components, services, handlers and offline/db subfolders.
– /theme: SCSS and CSS assets for Ionic/Moodle theming.
– /assets, /types, polyfills, main.ts, index.html: Angular/Ionic scaffolding for PWA and Cordova build.
• Configuration: angular.json, tsconfig*, webpack.config.js, Cordova plugins, GoogleService-Info.plist & google-services.json for Android/iOS.
Key architectural patterns
• Modular Angular architecture: core module vs feature (addon) modules, lazy loading for features.
• Delegate/handler pattern: services delegate between feature modules and core (e.g., plugin-file-delegate, sync-cron handlers).
• Offline-first + sync: local SQLite DB proxies in core/classes/database, offline and sync services co-existing (-offline.ts, ‑sync.ts).
• Cordova native abstraction: Cordova plugin directory plus core/native services under core/features/native and core/services.
• Theming + PWA: theme SCSS overrides, service worker (if enabled by Ionic PWA support).
Main components
A. Mobile UI Layer
– Ionic/Angular Components & Pages (src/app + src/addons/*/pages + src/core/components)
– Angular Routing & Lazy Loading
B. Feature Modules (src/addons)
– Each major Moodle feature (courses, quiz, forum, calendar, messages, user profile, etc.) as its own Angular module with pages, components, services, handlers.
C. Core Library (src/core)
– Shared classes (cancellable-promise, caching, delegates, database-table proxies)
– Shared components (attachments, loading, navigation, context-menu)
– Shared services (app, config, network, sync manager, plugin-file delegate, analytics)
D. Data Layer
– Local SQLite / IndexedDB (via core/classes/database/) for caching web service data and user‐generated content.
– Offline services (.offline.ts) and Sync services (.sync.ts) within each addon.
E. Native Bridge / Plugins
– Cordova plugin wrapper (/cordova-plugin-moodleapp) for SecureStorage, Diagnostic, InstallReferrer
– Core feature “native” services (camera, file, geolocation, in-app browser, notifications)
F. Network/Web Service Layer
– Moodle REST APIs (SiteService, CoreService, Plugin-specific endpoints)
– HTTP interceptor and error handling (core/classes/interceptor, core/services/ws.ts)
G. External Services
– Google Firebase / Apple Push (google-services.json, GoogleService-Info.plist)
– Analytics, BrowserStack testing, CI/CD (GitHub Actions, Travis CI)
H. Build & Deployment
– Gulp/Node scripts for translation, patching, assets, Cordova hooks (scripts/cordova-hooks)
– Ionic/Cordova build chain via npm, webpack, angular.json
Relationships and data flows
• UI Components → Feature Services → Core Services → Network layer / Local DB
• Feature Services coordinate .offline.ts (write/read local DB) and .sync.ts (background or user-triggered sync to server)
• Core Services manage app lifecycle, site auth, network status, sync events, plugin-file delegation
• Cordova plugins invoked by core/native services (e.g., SecureStorage) and feature services when necessary
• External push/analytics events routed back into core services, then to feature modules as handlers