LeafhavenDocs
System Architecture

Medusa v2 & Twenty CRM Deep Surgery

Transactional Outbox Pattern, B2B Trade DML Modules, and Enterprise ERP Integration

Medusa.js v2 & Twenty CRM Deep Surgery

The Transactional Outbox Pattern

To eliminate dual-write race conditions, when an RFQ is received, Medusa v2 writes the Draft Order and an Outbox event within a single ACID transaction in PostgreSQL:

CREATE TABLE commerce_outbox (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    tenant_id UUID NOT NULL,
    event_name VARCHAR(64) NOT NULL,
    aggregate_type VARCHAR(64) NOT NULL,
    aggregate_id VARCHAR(64) NOT NULL,
    payload JSONB NOT NULL,
    status VARCHAR(32) DEFAULT 'PENDING',
    created_at TIMESTAMPTZ DEFAULT NOW()
);

An asynchronous sync daemon polls pending outbox entries and publishes them to Redis BullMQ. Once confirmed, status is updated to PUBLISHED, ensuring At-Least-Once Delivery.


Twenty CRM Maritime GraphQL Extensions

Twenty CRM is extended with maritime trade specifications:

  • Incoterm: FOB, CFR, CIF, EXW, DDP.
  • PortOfLoading: e.g. "Tanjung Priok, IDJKT".
  • PortOfDestination: e.g. "Port of Hamburg, DEHAM".
  • ContainerAllocation: e.g. {"40ft_hc": 2}.
  • PaymentTerm: e.g. "T/T 30/70" or "L/C at Sight".