Busflow Docs

Internal documentation portal

Skip to content

Cross-Context Event Contracts: Backoffice → Commerce, Operations

Formal event contracts for events emitted by the Backoffice bounded context. For the pricing-specific events (PriceMatrixPublished, BookingConfirmed), see event-contracts-pricing.md. For the broader domain events catalog, see domain-driven-design.md §4.


Event Catalog

EventEmitterConsumer(s)Purpose
TripPublishedBackoffice (TourDeparture.statusPUBLISHED)Commerce (TourOffering creation, boarding points + ancillaries sync), Operations (ServiceLeg creation)Signals a departure is ready for sale and dispatch
TripCancelledBackoffice (TourDeparture.statusCANCELLED)Commerce (TourOffering.status → CANCELLED)Stops sales immediately

Payload Schemas

TripPublished

The most cross-cutting Backoffice event. Each consumer reads the fields it needs; the payload carries the full departure context to avoid follow-up queries.

FieldTypeDescription
event_idUUIDIdempotency key
tenant_idUUIDOwning operator
tour_departure_idUUIDThe published departure
tour_template_idUUIDSource template
start_dateDATEDeparture date
end_dateDATEReturn date
capacityINTMax passengers (from capacity_rules)
max_door_pickupsINTDoor pickup limit (from tour_templates.max_door_pickups)
deposit_configJSONBResolved deposit config (template override or tenant default)
cancellation_policyJSONBResolved cancellation policy
boarding_pointsTripPublishedBoardingPoint[]Resolved boarding point catalog (library defaults + template overrides + is_origin surcharge zeroing). See boarding-points.md §Commerce Projection.
ancillariesTripPublishedAncillary[]Resolved ancillary catalog (catalog defaults + template overrides). See ancillary-catalog.md §Commerce Projection.
legsTripLegDefinition[]Itinerary structure for ServiceLeg creation. See schema-operations.md §service_legs for the Operations consumer handler.
published_atTIMESTAMPTZPublication timestamp

TripPublishedBoardingPoint fields: boarding_point_id, name, address, geo_coordinates, zone_label, surcharge, is_origin, door_pickup_available, door_pickup_surcharge, door_pickup_radius_km, passenger_instructions, display_order.

TripPublishedAncillary fields: catalog_item_id, type, label, description, cover_image_key, price, currency, is_per_passenger, max_quantity, included_by_default, sort_order.

TripLegDefinition fields: sequence_order, leg_type, scheduled_start, scheduled_end, waypoints[] (each: geo_coordinates, sequence_order, label, waypoint_type).

Consumer handler logic:

  • Commerce: Creates/updates tour_offerings row. Denormalizes boarding_pointsavailable_boarding_points JSONB, ancillariesavailable_ancillaries JSONB, max_door_pickups, deposit_config, cancellation_policy. Idempotent on re-publish (upsert on tour_departure_id).
  • Operations: Creates service_legs + route_waypoints from legs[]. Uses UPSERT ON CONFLICT (tour_departure_id, sequence_order). Skips legs in ACTIVE/COMPLETED/CANCELLED status. See schema-operations.md §service_legs for the full handler contract.

TripCancelled

FieldTypeDescription
event_idUUIDIdempotency key
tenant_idUUIDOwning operator
tour_departure_idUUIDThe cancelled departure
tour_template_idUUIDSource template
cancelled_atTIMESTAMPTZCancellation timestamp

Consumer handler logic:

  • Commerce: Sets tour_offerings.status → CANCELLED for the matching tour_departure_id. The booking widget immediately stops selling this departure. Existing bookings are unaffected (operator contacts passengers manually at V0.1; automated notifications via Communications arrive at [v0.2]).

Delivery Contracts

EventMechanismTriggerIdempotency
TripPublishedHasura Event Trigger (async, post-commit)backoffice.tour_departures.statusPUBLISHEDevent_id (UUID). Commerce: upsert on tour_departure_id. Operations: upsert on (tour_departure_id, sequence_order).
TripCancelledHasura Event Trigger (async, post-commit)backoffice.tour_departures.statusCANCELLEDevent_id (UUID). Commerce: idempotent status set (already CANCELLED = no-op).

All consumers implement at-least-once processing with event_id-based deduplication.

Internal documentation — Busflow