DOCS

v1.3.37
 // Pro v1.2.25

 · Latest

Docs/Extending Order Daemon/Architecture Reference

Architecture Reference

System architecture

Order Daemon is a rules-driven automation layer on top of WooCommerce. It listens to order and external events, evaluates configurable rules (triggers + conditions), and executes actions. All activity is recorded as structured timelines.

flowchart TD
    WC[WooCommerce]
    Core[Core]
    Proc[EventProcessor]
    Log[AuditLog]

    WC -->|order and checkout hooks| Core
    Core -->|UniversalEvent| Proc
    Proc -->|executes matched actions| WC
    Proc -->|records timeline| Log

Event processing flow

flowchart TD
    hook["WooCommerce fires payment_complete"]
    event["Core builds UniversalEvent"]
    rules["EventProcessor finds matching rules"]
    check{"Conditions met?"}
    exec["Execute matched actions"]
    log["Record timeline in AuditLog"]

    hook --> event --> rules --> check
    check -- yes --> exec --> log
    check -- no --> log

Core component groups

1. Bootstrap

  • Plugin.php – Main entry point; controlled initialization sequence; registers CPT, loads options, initializes Core/admin/REST.
  • Installer.php – Database schema management and version upgrades.
  • Custom post type odcm_order_rule registered early (priority 5) to prevent race conditions.

2. Universal events

  • UniversalEvent – Standardized event envelope with real timestamps, gateway source, primary object type/ID.
  • UniversalEventProcessor – Central event processing pipeline: match rules → evaluate conditions → execute actions → log.
  • Event adapters – Gateway-specific adapters normalize external webhooks into UniversalEvent objects.

3. Rule engine

  • RuleComponentRegistry – Discovers and manages triggers, conditions, and actions.
  • Evaluator – Rule matching and condition evaluation.
  • ActionExecutor – Safe action execution with error handling.

4. Security

  • GuardChecker – Central guard execution with audit logging.
  • CapabilityGuard – Role-based access control.
  • NonceGuard – Request CSRF validation.

See Security guards for usage examples.

5. Logging and audit

  • ProcessLogger – Structured timeline logging.
  • AuditLogEndpoint – REST API for reading audit data.
  • odcm_log_event() – Public function for emitting structured audit events.

6. Fail-safe mechanisms

  • CheckoutCircuitBreaker – Prevents checkout failures if processing fails.
  • DuplicatePrevention – Idempotent operation handling (uses idempotency keys from gateway adapters).

Key classes and files

Class / fileRole
src/Plugin.phpBootstrap, CPT registration, orchestration
src/Core/Core.phpWooCommerce hook listeners, event dispatch
src/Core/Events/UniversalEvent.phpNormalized event envelope
src/Core/Events/UniversalEventProcessor.phpRule evaluation and action execution
src/Core/RuleComponents/RuleComponentRegistry.phpComponent discovery and registry
src/Core/RuleComponents/Interfaces/TriggerInterface, ConditionInterface, ComponentInterface
src/Core/Security/GuardChecker.phpSecurity execution + audit logging
src/Includes/functions.phpPublic helper functions (odcm_log_event, etc.)
src/API/RuleBuilderApiController.phpRule CRUD REST endpoints
src/API/AuditLogEndpoint.phpAudit/Insight timeline REST endpoints
src/API/WebhookController.phpInbound webhook receiver

Extension points

Extension typeHow
Custom rule componentsImplement TriggerInterface, ConditionInterface, or ActionInterface; register via odcm_register_components
Custom event sourcesBuild a class extending AbstractGatewayAdapter; register via odcm_register_gateway_adapters
REST API extensionsAdd endpoints via rest_api_init; use the guard system for security
Audit log entriesCall odcm_log_event() from anywhere

What’s next