> ## Documentation Index
> Fetch the complete documentation index at: https://betterdatainc.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Scm packages

# SCM packages

Supply Chain Management (**SCM**) modules share a common **runtime bootstrap** pattern and export **loop participant manifests** for the Loop Engine graph.

## Module interface (factory / runtime pattern)

### 1. Configure the runtime once

At application startup, call the package `configure*Runtime` with infrastructure dependencies (`getDb`, `outbox`, `readChannelMessages`).

```typescript theme={null}
import { configureInventoryRuntime } from "@betterdata/scm-inventory";
import type { ChannelReader, OutboxWriter } from "@betterdata/scm-contracts";

const outbox: OutboxWriter = {
  async write(entry, tx) {
    /* persist outbox row in same transaction as domain write */
  },
};

const readChannelMessages: ChannelReader = async (args) => {
  /* load channel messages for worker consumption */
};

configureInventoryRuntime({
  getDb: () => prisma,
  outbox,
  readChannelMessages,
});
```

Other SCM packages expose parallel entry points:

* `configureProcurementRuntime` — `@betterdata/scm-procurement`
* `configureExecutionRuntime` — `@betterdata/scm-execution`

Catalog-focused flows use adapter seams documented in each package README.

### 2. Call domain services

```typescript theme={null}
import { StockService } from "@betterdata/scm-inventory";

const result = await StockService.reserveStock({
  /* domain input — see package types */
});
```

## Loop participation

Every SCM module ships a **`*LoopParticipant`** manifest typed as `LoopParticipantManifest` from `@loop-engine/definitions`.

```typescript theme={null}
import { inventoryLoopParticipant } from "@betterdata/scm-inventory";
import { EventNames, LoopIds } from "@loop-engine/definitions";

// inventoryLoopParticipant.moduleId === "scm.inventory"
// Example handler binding:
// { event: EventNames.EXECUTION_GOODS_RECEIVED, loops: [LoopIds.SCM_PROCUREMENT, LoopIds.SCM_FULFILLMENT] }
```

`@loop-engine/actors` includes validation tests so participants only reference **known** `LoopIds` and `EventNames`.

## Package list

| Package                       | What it does                                                                    |
| ----------------------------- | ------------------------------------------------------------------------------- |
| `@betterdata/scm-contracts`   | Shared types, event envelopes, `OutboxWriter`, `ChannelReader`, runtime helpers |
| `@betterdata/scm-inventory`   | Stock, lots, reservations, QOH, availability                                    |
| `@betterdata/scm-procurement` | PO lifecycle, invoice alignment hooks                                           |
| `@betterdata/scm-execution`   | Shipments, pick/pack/ship/receive                                               |
| `@betterdata/scm-catalog`     | Product masters, marketplace search, normalizers                                |

<Tip>
  Event contracts are centralized in <a href="/oss/contracts">domain contracts</a>.
</Tip>

## Key exports (high level)

`@betterdata/scm-inventory` — `StockService`, reservation helpers, `LotService`, `inventoryLoopParticipant`, `configureInventoryRuntime`.

`@betterdata/scm-catalog` — product resolution, marketplace search services, `catalogLoopParticipant`, adapter interfaces for ranking and trust.

`@betterdata/scm-procurement` — procurement services, `loop-participation` / `preload-contribution`, `configureProcurementRuntime`.

`@betterdata/scm-execution` — shipment and warehouse engines, `configureExecutionRuntime`, execution loop participation.
