← Back to scenarios
ScenarioCatalog DB

Account onboarding

Coordinate account creation, profile setup, email verification, and welcome messaging through one onboarding operation.

Problem

An application must onboard a user through several coordinated services while presenting callers with one stable entry point instead of exposing every onboarding subsystem.

Related patterns

Implementations

Facade

TypeScriptApplication

Facade in TypeScript

Provides one checkout operation that coordinates inventory, payment, and shipment subsystems without exposing their individual workflows to callers.

TypeScript
type OrderRequest = {
  orderId: string;
  sku: string;
  quantity: number;
  paymentToken: string;
};

class InventoryService {
  reserve(sku: string, quantity: number) {
    console.log(`Reserved ${quantity} of ${sku}`);
  }
}

class PaymentService {
  charge(paymentToken: string) {
    console.log(`Charged payment token ${paymentToken}`);
  }
}

class ShipmentService {
  createShipment(orderId: string) {
    console.log(`Created shipment for ${orderId}`);
  }
}

class CheckoutFacade {
  constructor(
    private readonly inventory: InventoryService,
    private readonly payments: PaymentService,
    private readonly shipments: ShipmentService,
  ) {}

  placeOrder(request: OrderRequest) {
    this.inventory.reserve(request.sku, request.quantity);
    this.payments.charge(request.paymentToken);
    this.shipments.createShipment(request.orderId);
  }
}

const checkout = new CheckoutFacade(
  new InventoryService(),
  new PaymentService(),
  new ShipmentService(),
);

checkout.placeOrder({
  orderId: "order-123",
  sku: "keyboard",
  quantity: 1,
  paymentToken: "token_abc",
});

Associated technologies