Skip to content

Rules & Business Rules ​

MapexOS provides an enterprise-grade automation layer designed for high-volume event pipelines, multi-tenant governance, and auditable execution.

The platform separates reusable logic from tenant-specific configuration using a two-layer model:

  • Rules — reusable automation templates (built once, reused across orgs)
  • Business Rules — configured instances of a Rule, scoped to specific organizations and assets

This pattern enables consistent automation at scale while allowing each tenant to customize thresholds, recipients, filters, and actions—without duplicating logic.

Applies to v1.0.0 — Redis-backed state, visual rule builder, test mode, technical + communication actions, and persistent logs (EVA-indexed).


Conceptual model ​

Rule (template) ​

A Rule defines the automation blueprint:

  • Conditional logic (single conditions and nested groups)
  • Reusable actions (state, logs, external executions)
  • Optional parameters (resolved by the Business Rule)

Example (template):

txt
Rule: "High Temperature Alert"
When: temperature >= {threshold}
Do: notify {channel}

Business Rule (configured instance) ​

A Business Rule is a scoped deployment of a Rule, bound to:

  • Organization scope (tenant isolation + optional child scope)
  • Asset filters (template, tags, identifiers)
  • Parameters (thresholds, destinations, recipients)
  • Operational settings (timezone, enablement, debugging)

Example (instance):

txt
Business Rule: "Factory Alpha High Temp"
Template: "High Temperature Alert"
Parameters: threshold = 80, channel = "#ops-alerts"
Scope: org "Factory Alpha" (+ children)

Rule vs Business Rule ​

AspectRule (template)Business Rule (instance)
LogicGeneric reusableTenant-configured
ParametersPlaceholdersConcrete values
ScopeGlobal / org templateOrg-specific execution
GovernanceShared across orgsOwned by the tenant

UI configuration overview (Edit Rule) ​

In MapexOS, a Business Rule is configured through five tabs:

TabPurpose
GeneralIdentity, enablement, sharing, and timezone behavior
VariablesRule Variables (state) and Capture Fields (logging schema)
ActionsAction catalog (State, Log, Exec) reused by conditions/groups
RulesVisual builder: conditions, groups, operators, and action attachments
DebugTest Mode execution with simulated events and trace output

Enterprise note
Treat Rules as production artifacts. Use naming conventions, versioning, and controlled sharing to ensure consistency across tenants and environments.


General tab ​

Basic information ​

SettingDescription
NameBusiness Rule identifier
DescriptionOperational purpose and usage notes
Rule enabledWhen enabled, the rule is active and processes events
Mark as shared templateMakes this Rule available for child organizations

Sharing across the organization hierarchy ​

When Mark as shared template is enabled, the Rule can be reused by child organizations. This supports standardized policies such as:

  • “All factories must emit incident alerts above threshold”
  • “Child sites inherit the same escalation workflow”
  • “Subsidiaries reuse centrally defined compliance rules”

Timezone behavior ​

Timezone selection affects any operator and action that evaluates or constructs date/time values.

TypeDescription
Fixed timezoneAll date/time comparisons use a single timezone (e.g., UTC)
Dynamic timezoneTimezone resolved by tenant context or event metadata (when supported)

Enterprise note
Timezone alignment is critical for schedules, SLAs, “business-hours” alerts, and regional compliance reporting.


Variables tab ​

The Variables tab has two sections: Rule Variables and Capture Fields.

Rule Variables (stateful execution) ​

Rule Variables are typed state values persisted via Redis and designed to track context across events.

They enable:

  • Stateful automation (counters, incident flags, cooldowns)
  • Autocomplete in the Rule Builder and Actions
  • Type safety with explicit defaults
PropertyDescription
NameVariable identifier (valid JavaScript identifier)
Typenumber, text, boolean
Default ValueInitial value when the state key is missing

Example variables:

VariableTypeDefaultEnterprise use case
counternumber0Escalation after N occurrences
incidentOpenbooleanfalseIncident lifecycle control
lastAlertAttext""Cooldown / deduplication

Enterprise note
Rule Variables are not just “local variables”. They represent durable state used to build deterministic behavior across distributed event streams.

Capture Fields (persistent logging schema) ​

Capture Fields define the log schema used by Log actions. Each field becomes queryable for auditing and reporting.

Capture Fields support EVA-indexed storage, which enables:

  • Operational dashboards (counts and trends)
  • Incident forensics (“what happened before this alert?”)
  • Compliance evidence (“which rule fired, when, and why?”)
PropertyDescription
Field NameKey stored in the log record
Typenumber, text, boolean, date (depending on UI support)
SourceWhere the value comes from: Event, State, Variable, Literal

Value sources (Event, State, Variable, Literal) ​

Across conditions, actions, and log mapping, MapexOS uses a consistent value-source model:

SourceDescriptionEnterprise benefit
EventValues from the incoming Standard EventTemplate-aware field autocomplete
StateValues from Rule Variables (Redis)Stateful, deterministic automation
VariableValues from Business Rule parametersMulti-tenant customization without cloning
LiteralFixed values defined directly in the ruleExplicit and predictable comparisons

Autocomplete behavior ​

  • Event values are suggested from the Asset Template structure (when available).
  • State values are suggested from defined Rule Variables.
  • Variable values represent tenant-configurable parameters (Business Rule configuration).
  • Literal values are manually typed and strongly recommended for constants.

Actions tab ​

Actions define “what the rule can do”. They are reusable and can be attached to:

  • A specific condition
  • An entire group

MapexOS supports three action categories:

1) State actions ​

State actions manipulate Rule Variables (Redis-backed state).

ActionDescriptionExample
IncrementAdds a value to a numeric statecounter += 1
DecrementSubtracts a value from a numeric stateretries -= 1
SetAssigns/overwrites a state valueincidentOpen = true

UI mapping example:

txt
Increment State
- Variable: counter
- Source: Literal
- Increment by: 1

2) Log actions (persistent capture) ​

Log actions persist structured values for later analysis and reporting.

Typical flow:

txt
Log Action
└── Save Capture Data
    └── Map values to Capture Fields

Example mapping:

Capture FieldSourceExample
temperatureEventevent.data.temperature
assetIdEventevent.metadata.assetId
counterStatestate.counter
thresholdVariableparams.threshold

Enterprise note
Log actions are the foundation of auditability. In regulated environments, treat capture fields as part of your compliance evidence strategy.

3) Exec actions (technical + communication) ​

Exec actions interact with external systems and notification channels.

CategoryExamples
TechnicalHTTP, MQTT, NATS, Kafka, RabbitMQ, WebSocket
CommunicationEmail, Slack, Microsoft Teams

Execution control ​

Exec actions support operational controls:

SettingOptionsPurpose
Execution ModeSequential, ParallelControls how a group of actions executes
Error HandlingContinue, StopControls behavior when an action fails

Slack example (conceptual):

json
{
  "type": "slack",
  "config": {
    "channel": "#ops-alerts",
    "message": "Alert #{{state.counter}}: temperature {{event.data.temperature}} on {{metadata.assetId}}"
  }
}

Rules tab (visual builder) ​

The Rules tab is where the business logic is assembled using:

  • Groups (containers with logical operators)
  • Conditions (comparisons using sources and operators)
  • Attached actions (condition-level or group-level)

Groups (logical operators) ​

Groups combine conditions through a selected operator:

Group TypeMeaning
All conditionsAND — all conditions must match
Any conditionOR — at least one condition must match
Not all conditionsNAND — not all may be true
Not any conditionNOR — none may be true

Condition structure ​

Each condition compares:

  • Left side: value source + field selection
  • Operator: equals, greater-than, between, etc.
  • Right side: value source + value/field selection

Conceptually:

txt
LEFT (source + field)   OPERATOR   RIGHT (source + value)

Attaching actions ​

Actions can be attached at two levels:

LevelBehavior
ConditionExecutes only if that condition matches
GroupExecutes if the group resolves to true

Enterprise note
Prefer group-level actions for consistent, auditable behaviors. Use condition-level actions for incremental state updates and fine-grained workflows.


Debug tab (Test Mode) ​

MapexOS includes Test Mode for validating rules safely before production rollout.

Test Mode flow ​

txt
1. Open Debug tab (or enable Test Mode toggle)
2. Select an Asset Template (defines expected payload structure)
3. Enable Test Mode
4. Click Start
5. Review evaluation trace, state updates, and action results

What Test Mode validates ​

CapabilityWhat it verifies
Condition logicOperators, groups, and comparisons behave correctly
State behaviorVariables increment/set as expected (Redis semantics)
Capture logsValues map correctly into Capture Fields
Exec actionsExternal calls are triggered (use sandbox endpoints)

Enterprise note
Test Mode uses the same engine and evaluation semantics as production. The primary difference is the event source (simulated vs live).


Runtime execution model ​

At runtime, MapexOS evaluates rules as events arrive:

txt
1. Receive Standard Event
2. Resolve tenant scope (org + hierarchy, if applicable)
3. Load Business Rule configuration
4. Load Rule Variables (state) from Redis
5. Evaluate groups/conditions using value sources
6. Execute actions in the configured order:
   State → Log → Exec (as configured)
7. Persist logs (when enabled) for audit/query

State scoping (collision safe) ​

State keys are scoped to avoid collisions across tenants and rules:

txt
state:{orgId}:{businessRuleId}:{variableName}

Example:

txt
state:org-123:br-456:counter
state:org-123:br-456:incidentOpen

Enterprise patterns ​

Cooldown / deduplication ​

Prevent alert fatigue by throttling notifications:

txt
Variables:
- lastAlertAt (text)

Rule:
IF event.temperature >= params.threshold
AND now() - state.lastAlertAt > params.cooldownSeconds

Actions:
- Exec: Notify channel
- State: Set lastAlertAt = now()

Escalation after N occurrences ​

Trigger escalation only after repeated events:

txt
Variables:
- counter (number)

Rule:
IF event.status equals "critical"
  → State: counter += 1

IF state.counter >= params.escalateAfter
  → Exec: Escalate
  → State: counter = 0

Incident lifecycle (open/close) ​

Create deterministic incident handling:

txt
Variables:
- incidentOpen (boolean)

Open:
IF event.status equals "critical"
AND state.incidentOpen equals false
  → Exec: Open ticket
  → State: incidentOpen = true
  → Log: "incident_opened"

Close:
IF event.status equals "ok"
AND state.incidentOpen equals true
  → Exec: Close ticket
  → State: incidentOpen = false
  → Log: "incident_closed"

Governance and sharing ​

Visibility and reuse ​

ScopeDescription
System RuleProvided by MapexOS, available across the platform
Organization RuleDefined by a tenant, private by default
Shared RuleOrganization Rule shared with child organizations

To share a rule, enable Mark as shared template for use by child organizations in the General tab.

Change management recommendations ​

  • Use structured naming: ALERT - Temperature - v1
  • Prefer parameterization over cloning
  • Validate in Test Mode before enabling
  • Add Capture Fields for audit-critical flows
  • Keep Exec actions idempotent when possible

Best practices ​

PracticeRecommendation
Define state upfrontCreate Rule Variables before building complex logic
Use meaningful namesalertCounter instead of c1
Prefer parametersUse Variable source for thresholds and channels
Throttle notificationsCooldowns prevent alert storms
Log for auditabilityCapture Fields provide long-term traceability
Test before enablingUse Test Mode with realistic payloads
Monitor failuresReview Exec action outcomes and delivery rates

Next steps ​

Business Source License (BSL 1.1)