Skip to main content

File Structure

Complete annotated directory and file listing for the MIH plugin.


Directory Tree

local/integrationhub/

├── amd/ # AMD JavaScript modules
│ ├── src/ # Source files (edit these)
│ │ ├── dashboard.js # Dashboard: charts, service form, circuit reset
│ │ ├── rules.js # Rules: form toggle, service type detection
│ │ └── queue.js # Queue monitor: DLQ table, replay/delete actions
│ └── build/ # Minified output (generated by grunt amd)
│ ├── dashboard.min.js
│ ├── dashboard.min.js.map
│ ├── rules.min.js
│ ├── rules.min.js.map
│ ├── queue.min.js
│ └── queue.min.js.map

├── assets/
│ └── min/
│ └── chart.umd.min.js # Chart.js (locally hosted, avoids CDN dependency)

├── classes/ # PHP classes (PSR-4 autoloaded by Moodle)
│ │
│ ├── event/
│ │ ├── observer.php # Universal event listener (catches all events from Moodle™ platform)
│ │ └── webhook_received.php # Custom event fired when an inbound webhook arrives
│ │
│ ├── service/
│ │ ├── circuit_breaker.php # CLOSED/OPEN/HALFOPEN state management
│ │ ├── registry.php # Service CRUD (local_integrationhub_svc table)
│ │ └── retry_policy.php # Retry logic with exponential backoff
│ │
│ ├── task/
│ │ ├── consume_responses_task.php # Scheduled: consume AMQP response queues
│ │ ├── dispatch_event_task.php # Adhoc: dispatch one event to one service
│ │ └── queue_manager.php # Shared queue/DLQ utilities
│ │
│ ├── transport/
│ │ ├── contract.php # Interface: all drivers must implement execute()
│ │ ├── http.php # REST/HTTP driver (cURL)
│ │ ├── amqp.php # RabbitMQ driver (php-amqplib)
│ │ ├── amqp_helper.php # AMQP connection factory (plain + SSL)
│ │ ├── soap.php # SOAP driver (PHP SoapClient)
│ │ └── transport_utils.php # Trait: success_result() and error_result()
│ │
│ ├── mih.php # Main orchestrator (Facade/Singleton). Public API.
│ ├── mih_request.php # Fluent request builder
│ ├── mih_response.php # Immutable response value object
│ └── webhook_handler.php # Handles inbound webhook HTTP requests

├── db/ # Moodle database and hook definitions
│ ├── access.php # Capability definitions (manage, view)
│ ├── caches.php # Cache definitions (event_dedupe)
│ ├── events.php # Event observer registration
│ ├── install.xml # XMLDB schema (5 tables)
│ ├── tasks.php # Scheduled task definitions
│ └── upgrade.php # DB upgrade script (version migrations)

├── docs/ # Plugin documentation
│ ├── README.md # Documentation index
│ ├── documento_maestro.md # Single-file master reference (English)
│ ├── en/ # English documentation (individual files)
│ │ ├── 01-overview.md
│ │ ├── 02-architecture.md
│ │ ├── 03-installation.md
│ │ ├── 04-admin-guide.md
│ │ ├── 05-mih-api.md
│ │ ├── 06-event-bridge.md
│ │ ├── 07-data-flow.md
│ │ ├── 08-resilience.md
│ │ ├── 09-transports.md
│ │ ├── 10-database.md
│ │ ├── 11-class-reference.md
│ │ ├── 12-ajax.md
│ │ ├── 13-permissions.md
│ │ ├── 14-tasks.md
│ │ └── 15-file-structure.md
│ └── es/ # Spanish documentation (individual files)
│ ├── 01-descripcion-general.md
│ ├── 02-arquitectura.md
│ ├── 03-instalacion.md
│ ├── 04-guia-administrador.md
│ ├── 05-api-mih.md
│ ├── 06-event-bridge.md
│ ├── 07-flujo-de-datos.md
│ ├── 08-resiliencia.md
│ ├── 09-transportes.md
│ ├── 10-base-de-datos.md
│ ├── 11-referencia-clases.md
│ ├── 12-ajax.md
│ ├── 13-permisos.md
│ ├── 14-tareas.md
│ └── 15-estructura-archivos.md

├── lang/ # Language strings
│ ├── en/
│ │ └── local_integrationhub.php # English strings
│ └── es/
│ └── local_integrationhub.php # Spanish strings

├── vendor/ # Composer dependencies (not committed to git)
│ └── php-amqplib/ # AMQP library (only if using RabbitMQ)

├── ajax.php # Internal AJAX endpoint (preview_payload)
├── composer.json # Composer configuration
├── composer.lock # Composer lock file
├── events.php # Sent events log page
├── index.php # Main dashboard (services tab)
├── logs.php # Request log viewer
├── queue.php # Dead Letter Queue viewer
├── README.md # GitHub README
├── rules.php # Event Bridge rules management
├── settings.php # Plugin admin settings page
├── version.php # Plugin version and requirements
└── webhook.php # Inbound webhook receiver endpoint

Key Files Explained

version.php

Defines the plugin version, component name, and minimum Moodle version:

$plugin->version   = 2026021800;
$plugin->requires = 2023042400; // Moodle 4.2
$plugin->component = 'local_integrationhub';

db/install.xml

The XMLDB schema file. Defines all five tables with their columns, types, indexes, and constraints. Processed by Moodle during installation.

db/events.php

Registers the universal event observer:

$observers = [
[
'eventname' => '\core\event\base',
'callback' => '\local_integrationhub\event\observer::handle_event',
],
];

db/tasks.php

Registers the scheduled task:

$tasks = [
[
'classname' => '\local_integrationhub\task\consume_responses_task',
'minute' => '*',
// runs every minute
],
];

db/caches.php

Defines the event deduplication cache:

$definitions = [
'event_dedupe' => [
'mode' => cache_store::MODE_APPLICATION,
'simplekeys' => true,
'ttl' => 60,
],
];

amd/src/dashboard.js

AMD module for the dashboard page. Responsibilities:

  • Toggle the "Add Service" form visibility
  • Handle service type changes (show/hide AMQP connection builder, SOAP fields)
  • Render the status pie chart and latency line chart using Chart.js
  • Handle circuit reset button clicks (AJAX calls to Moodle's core AJAX API)

amd/src/rules.js

AMD module for the rules page. Responsibilities:

  • Toggle the "Add Rule" form visibility
  • Show/hide the HTTP method selector based on service type (hidden for AMQP/SOAP)
  • Handle the "Preview Payload" button (calls ajax.php)

assets/min/chart.umd.min.js

Chart.js UMD bundle, hosted locally. This avoids CDN dependencies and works in offline/intranet Moodle™ deployments.


What Is Not Committed to Git

PathReason
vendor/Composer dependencies — run composer install
amd/build/Generated by grunt amd — do not edit manually
*.logLog files

Adding New Files

New PHP Class

Place it in the appropriate classes/ subdirectory. Moodle's PSR-4 autoloader will find it automatically based on the namespace:

NamespaceDirectory
local_integrationhub\classes/
local_integrationhub\service\classes/service/
local_integrationhub\transport\classes/transport/
local_integrationhub\task\classes/task/
local_integrationhub\event\classes/event/

New AMD Module

  1. Create amd/src/mymodule.js
  2. Run grunt amd to build amd/build/mymodule.min.js
  3. Load it from PHP: $PAGE->requires->js_call_amd('local_integrationhub/mymodule', 'init', [$data])

New Page

  1. Create mypage.php in the plugin root
  2. Add a tab link in the navigation section of existing pages
  3. Add language strings in lang/en/local_integrationhub.php