Skip to main content
Version: 1.1.0
Last Updated: 2026-03-06
Owner: FM (Facilities Management)

Overview

This document defines the integration contracts for the Facilities Management (FM) core module. All FM events follow the standard event contract pattern defined in EVENT_CONTRACTS.md.

Event Categories

1. Work Order Events (FM-01)

work_order_created

Published when: A work order is created (request, scheduled, PM-generated, or inspection-generated).
Consumers:
  • PF-10 (Notifications): Notify facilities manager of new work orders
  • FA (Finance): Track pending maintenance costs

work_order_completed

Published when: A work order status changes to completed.
Consumers:
  • FA (Finance): Create cost allocation journal entries
  • FM-04 (Preventive Maintenance): Update PM schedule next due date
  • FM-05 (Asset Management): Update asset maintenance history
  • FM-06 (Compliance): Update inspection compliance status
  • FM-03 (Vendor Management): Update vendor performance metrics

work_order_overdue

Published when: A work order passes its due date without completion.
Consumers:
  • PF-10 (Notifications): Alert facilities manager and assigned technician/vendor

2. Inventory Events (FM-02)

inventory_low_stock

Published when: Inventory quantity falls below reorder point.
Consumers:
  • PF-10 (Notifications): Alert procurement manager
  • FA-04 (Purchase Orders): Auto-create purchase order (if enabled)

inventory_item_used

Published when: Inventory is used on a work order (usage transaction created).
Consumers:
  • FM-01 (Work Orders): Update work order material cost
  • FA (Finance): Track inventory cost allocation

3. Vendor Events (FM-03)

vendor_certification_expiring

Published when: Vendor certification is within 90/60/30 days of expiration.
Consumers:
  • PF-10 (Notifications): Alert compliance officer and facilities manager
  • GR (Governance): Track compliance status

vendor_work_order_assigned

Published when: A work order is assigned to an external vendor.
Consumers:
  • PF-10 (Notifications): Notify vendor of assignment
  • FA-03 (Accounts Payable): Prepare for vendor invoice matching

4. Preventive Maintenance Events (FM-04)

pm_due

Published when: A PM schedule is due (work order auto-generated).
Consumers:
  • PF-10 (Notifications): Alert facilities manager and assigned technician
  • FM-05 (Asset Management): Track upcoming maintenance

pm_overdue

Published when: A PM schedule passes its due date without completion.
Consumers:
  • PF-10 (Notifications): Alert facilities manager and compliance officer
  • GR (Governance): Track compliance violations

pm_completed

Published when: A PM work order is completed.
Consumers:
  • FM-05 (Asset Management): Update asset maintenance history
  • FA (Finance): Track maintenance costs

5. Asset Events (FM-05)

asset_purchased

Published when: A new asset is created/registered.
Consumers:
  • FA (Finance): Create capitalization journal entry

asset_disposed

Published when: An asset status changes to disposed.
Consumers:
  • FA (Finance): Create disposal journal entry
  • FM-04 (Preventive Maintenance): Deactivate PM schedules for asset

asset_warranty_expiring

Published when: Asset warranty is within 90/60/30 days of expiration.
Consumers:
  • PF-10 (Notifications): Alert compliance officer and asset manager

6. Inspection & Compliance Events (FM-06)

inspection_due

Published when: An inspection schedule is due (work order auto-generated).
Consumers:
  • PF-10 (Notifications): Alert inspector and compliance officer
  • GR (Governance): Track upcoming compliance inspections

inspection_failed

Published when: An inspection is completed with failed checklist items.
Consumers:
  • PF-10 (Notifications): Alert facilities manager and compliance officer
  • GR (Governance): Track compliance violations
  • FM-01 (Work Orders): Create corrective action work order

inspection_compliant

Published when: An inspection is completed with all checklist items passed.
Consumers:
  • GR (Governance): Update compliance status
  • FM-05 (Asset Management): Update asset inspection history (if asset-based)

Cross-Module Dependencies

FM-04 ↔ FM-05 Circular Dependency Resolution

Issue: FM-04 (Preventive Maintenance) and FM-05 (Asset Management) have mutual dependencies:
  • FM-04 PM schedules reference assets (FM-05)
  • FM-05 asset maintenance history references PM completions (FM-04)
Resolution Strategy:
  1. Database Level: Use foreign key references with ON DELETE SET NULL where appropriate to allow independent table creation
  2. Event-Based Updates: Use events (pm_completed, asset_disposed) for cross-module state updates rather than direct queries
  3. Implementation Order:
    • Phase 1: Implement FM-05 base tables (fm_assets)
    • Phase 2: Implement FM-04 with asset references
    • Phase 3: Add FM-05 maintenance history integration via events
  4. RLS Policies: Both use fm_has_org_access() SECURITY DEFINER function to avoid RLS recursion

RLS Security Pattern

All FM tables use the fm_has_org_access() SECURITY DEFINER function for RLS policies to avoid infinite recursion:

FA Integration Dependencies

The following FA specs are referenced by FM but not yet implemented:
  • FA-03 (Accounts Payable): Vendor invoice matching, payment tracking
  • FA-04 (Purchase Orders): Auto-create POs from low stock alerts
Temporary Resolution:
  • FM publishes events; FA will consume when implemented
  • FM stores purchase_order_id and vendor_invoice_id as nullable foreign keys
  • No blocking dependencies; FM can operate independently

Event Publishing Pattern


7. Fleet Management Events (FM-13)

vehicle_registered

Published when: A new vehicle is registered in the fleet.
Consumers:
  • PF-10 (Notifications): Notify fleet manager of new vehicle
  • FM-05 (Asset Management): Link to asset record if created

vehicle_status_changed

Published when: Vehicle status changes (active → maintenance → retired → disposed).
Consumers:
  • PF-10 (Notifications): Alert fleet manager of status change
  • FM-05 (Asset Management): Update asset status

license_expiring

Published when: Driver license is within 90/60/30 days of expiration.
Consumers:
  • PF-10 (Notifications): Alert driver and fleet manager
  • GR (Governance): Track compliance status

registration_expiring

Published when: Vehicle registration is within 90/60/30 days of expiration.
Consumers:
  • PF-10 (Notifications): Alert fleet manager
  • GR (Governance): Track compliance status

fleet_maintenance_due

Published when: A fleet vehicle maintenance schedule is due.
Consumers:
  • PF-10 (Notifications): Alert fleet manager and assigned technician
  • FM-01 (Work Orders): Track associated work order

fleet_maintenance_overdue

Published when: A fleet vehicle maintenance schedule is overdue.
Consumers:
  • PF-10 (Notifications): Alert fleet manager with urgency
  • GR (Governance): Track maintenance compliance violations


8. Budgeting & Planning Events (FM-09)

budget_variance_alert

Published when: A facilities budget line item exceeds its threshold variance (default: >10% over budget for approved budgets).
Consumers:
  • PF-10 (Notifications): Alert facilities manager and finance manager
  • FA-08 (Budgeting & Forecasting): Sync variance to FA budget module (📝 Planned — FA-08 not yet implemented; event replays when available)

9. Capital Planning Events (FM-12)

capital_project_approved

Published when: A capital project status changes to approved.
Consumers:
  • FA-09 (Capital Projects): Create capital project record in FA (📝 Planned — FA-09 not yet implemented; event replays when available)
  • PF-10 (Notifications): Notify requesting user and finance manager of approval

10. Energy Management Events (FM-10)

energy_anomaly_detected

Published when: Automated anomaly detection identifies abnormal energy usage (spike, off-hours usage, baseline deviation). Requires FM-10-DEFERRED-EXPANSION Phase 2 (smart meter integration) to be implemented.
Consumers:
  • PF-10 (Notifications): Alert energy manager of anomaly
  • GR (Governance): Track compliance if anomaly indicates equipment regulatory issue

11. Space Management Events (FM-11)

space_occupancy_threshold

Published when: A space’s recorded occupancy exceeds its configured capacity threshold.
Consumers:
  • PF-10 (Notifications): Alert facilities manager
  • HR (Human Resources): Space occupancy data for headcount planning (📝 Planned)

12. Analytics Events (FM-07)

facilities_report_generated

Published when: A scheduled or on-demand facilities analytics report is generated and available for export.
Consumers:
  • PF-10 (Notifications): Notify requestor when report is ready

Consumer Verification Matrix

See: FM-CONSUMER-VERIFICATION.md (to be created as part of FM-14 implementation) for implementation status of each consumer.
Legend: ✅ Verified = subscription handler code exists and tested. 📝 Planned = listed as consumer in spec but handler not yet implemented.

FM↔FA Finance Interface Summary

See: FM-16: FM↔FA Finance Interface for full interface contract.
All FM→FA flows are non-blocking:
  • FM publishes events to pf_domain_events; FA subscribes when implemented
  • FM stores nullable FKs (purchase_order_id, vendor_invoice_id) for future FA reconciliation
  • FM-09 and FM-12 use FM-local cost data; FA integration is an enhancement layer
Temporary resolution: FM can operate fully without FA. No blocking dependencies on FA-03, FA-04, FA-08, or FA-09.