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

# Midaz events

> Domain events emitted by the Midaz ledger and CRM.

Midaz emits domain events as **CloudEvents 1.0** messages in binary content mode over Kafka, published through `lib-streaming`. Every event travels in the [shared envelope](/en/reference/events/overview): `ce-type` names the event as `studio.lerian.<resource>.<event>`, `ce-subject` carries the aggregate id, `ce-tenantid` the owning tenant (absent in single-tenant scope), and `ce-schemaversion` the payload version — `1.0.0` for every event below.

`ce-source` is deployment-configured through the `STREAMING_CLOUDEVENTS_SOURCE` environment variable. The ledger defaults to `lerian.midaz.ledger` and the CRM capability to `lerian.midaz.crm`. Money amounts — balances, transaction and operation amounts — cross the wire as decimal **strings**, never floats.

## Ledger events

Facts the ledger emits as organizations, accounts, balances, and transactions change.

### Organization

| Event (`ce-type`)                    | Topic                                   | Fires when                               | Key payload                                                                                    |
| ------------------------------------ | --------------------------------------- | ---------------------------------------- | ---------------------------------------------------------------------------------------------- |
| `studio.lerian.organization.created` | `lerian.streaming.organization.created` | An organization is created.              | `id`, `legalName`, `doingBusinessAs`, `legalDocument`, `address`, `status`, `createdAt`        |
| `studio.lerian.organization.updated` | `lerian.streaming.organization.updated` | An organization's mutable fields change. | `id`, `parentOrganizationId`, `legalName`, `doingBusinessAs`, `address`, `status`, `updatedAt` |
| `studio.lerian.organization.deleted` | `lerian.streaming.organization.deleted` | An organization is deleted.              | `id`, `deletedAt`                                                                              |

### Ledger

| Event (`ce-type`)              | Topic                             | Fires when                                  | Key payload                                           |
| ------------------------------ | --------------------------------- | ------------------------------------------- | ----------------------------------------------------- |
| `studio.lerian.ledger.created` | `lerian.streaming.ledger.created` | A ledger is created within an organization. | `id`, `organizationId`, `name`, `status`, `createdAt` |
| `studio.lerian.ledger.updated` | `lerian.streaming.ledger.updated` | A ledger's name or status changes.          | `id`, `organizationId`, `name`, `status`, `updatedAt` |
| `studio.lerian.ledger.deleted` | `lerian.streaming.ledger.deleted` | A ledger is deleted.                        | `id`, `organizationId`, `deletedAt`                   |

### Account

| Event (`ce-type`)               | Topic                              | Fires when                          | Key payload                                                                                                                 |
| ------------------------------- | ---------------------------------- | ----------------------------------- | --------------------------------------------------------------------------------------------------------------------------- |
| `studio.lerian.account.created` | `lerian.streaming.account.created` | An account is opened in a ledger.   | `id`, `organizationId`, `ledgerId`, `name`, `assetCode`, `type`, `alias`, `portfolioId`, `segmentId`, `status`, `createdAt` |
| `studio.lerian.account.updated` | `lerian.streaming.account.updated` | An account's mutable fields change. | `id`, `organizationId`, `ledgerId`, `name`, `segmentId`, `entityId`, `status`, `blocked`, `updatedAt`                       |
| `studio.lerian.account.deleted` | `lerian.streaming.account.deleted` | An account is deleted.              | `id`, `organizationId`, `ledgerId`, `portfolioId`, `deletedAt`                                                              |

### Asset

| Event (`ce-type`)             | Topic                            | Fires when                          | Key payload                                                                       |
| ----------------------------- | -------------------------------- | ----------------------------------- | --------------------------------------------------------------------------------- |
| `studio.lerian.asset.created` | `lerian.streaming.asset.created` | An asset is registered in a ledger. | `id`, `organizationId`, `ledgerId`, `name`, `type`, `code`, `status`, `createdAt` |
| `studio.lerian.asset.updated` | `lerian.streaming.asset.updated` | An asset's mutable fields change.   | `id`, `organizationId`, `ledgerId`, `name`, `type`, `code`, `status`, `updatedAt` |
| `studio.lerian.asset.deleted` | `lerian.streaming.asset.deleted` | An asset is deleted.                | `id`, `organizationId`, `ledgerId`, `deletedAt`                                   |

### Portfolio

| Event (`ce-type`)                 | Topic                                | Fires when                           | Key payload                                                                   |
| --------------------------------- | ------------------------------------ | ------------------------------------ | ----------------------------------------------------------------------------- |
| `studio.lerian.portfolio.created` | `lerian.streaming.portfolio.created` | A portfolio is created.              | `id`, `organizationId`, `ledgerId`, `name`, `entityId`, `status`, `createdAt` |
| `studio.lerian.portfolio.updated` | `lerian.streaming.portfolio.updated` | A portfolio's mutable fields change. | `id`, `organizationId`, `ledgerId`, `name`, `entityId`, `status`, `updatedAt` |
| `studio.lerian.portfolio.deleted` | `lerian.streaming.portfolio.deleted` | A portfolio is deleted.              | `id`, `organizationId`, `ledgerId`, `deletedAt`                               |

### Segment

| Event (`ce-type`)               | Topic                              | Fires when                         | Key payload                                                       |
| ------------------------------- | ---------------------------------- | ---------------------------------- | ----------------------------------------------------------------- |
| `studio.lerian.segment.created` | `lerian.streaming.segment.created` | A segment is created.              | `id`, `organizationId`, `ledgerId`, `name`, `status`, `createdAt` |
| `studio.lerian.segment.updated` | `lerian.streaming.segment.updated` | A segment's mutable fields change. | `id`, `organizationId`, `ledgerId`, `name`, `status`, `updatedAt` |
| `studio.lerian.segment.deleted` | `lerian.streaming.segment.deleted` | A segment is deleted.              | `id`, `organizationId`, `ledgerId`, `deletedAt`                   |

### Operation route

| Event (`ce-type`)                       | Topic                                      | Fires when                                  | Key payload                                                                                                       |
| --------------------------------------- | ------------------------------------------ | ------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
| `studio.lerian.operation-route.created` | `lerian.streaming.operation-route.created` | An operation route is created.              | `id`, `organizationId`, `ledgerId`, `title`, `code`, `operationType`, `account`, `accountingEntries`, `createdAt` |
| `studio.lerian.operation-route.updated` | `lerian.streaming.operation-route.updated` | An operation route's mutable fields change. | `id`, `organizationId`, `ledgerId`, `title`, `code`, `operationType`, `account`, `accountingEntries`, `updatedAt` |
| `studio.lerian.operation-route.deleted` | `lerian.streaming.operation-route.deleted` | An operation route is deleted.              | `id`, `organizationId`, `ledgerId`, `deletedAt`                                                                   |

### Transaction route

| Event (`ce-type`)                         | Topic                                        | Fires when                                   | Key payload                                                                   |
| ----------------------------------------- | -------------------------------------------- | -------------------------------------------- | ----------------------------------------------------------------------------- |
| `studio.lerian.transaction-route.created` | `lerian.streaming.transaction-route.created` | A transaction route is created.              | `id`, `organizationId`, `ledgerId`, `title`, `operationRouteIds`, `createdAt` |
| `studio.lerian.transaction-route.updated` | `lerian.streaming.transaction-route.updated` | A transaction route's mutable fields change. | `id`, `organizationId`, `ledgerId`, `title`, `operationRouteIds`, `updatedAt` |
| `studio.lerian.transaction-route.deleted` | `lerian.streaming.transaction-route.deleted` | A transaction route is deleted.              | `id`, `organizationId`, `ledgerId`, `deletedAt`                               |

### Balance

| Event (`ce-type`)                         | Topic                                        | Fires when                                                                                                                                                     | Key payload                                                                                                                                                                          |
| ----------------------------------------- | -------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `studio.lerian.balance.created`           | `lerian.streaming.balance.created`           | A balance is created during account setup.                                                                                                                     | `id`, `organizationId`, `ledgerId`, `accountId`, `alias`, `key`, `assetCode`, `accountType`, `available`, `onHold`, `allowSending`, `allowReceiving`, `createdAt`                    |
| `studio.lerian.balance.changed`           | `lerian.streaming.balance.changed`           | A committed transaction moves a balance — one event per balance-affecting operation; values reflect the state after the operation.                             | `organizationId`, `ledgerId`, `accountId`, `balanceId`, `assetCode`, `available`, `onHold`, `version`, `reason`, `direction`, `amount`, `transactionId`, `operationId`, `occurredAt` |
| `studio.lerian.balance.config-changed`    | `lerian.streaming.balance.config-changed`    | A balance's settings change, or overdraft is enabled (companion balance materialized). `changeType` discriminates `settings_updated` from `overdraft_enabled`. | `id`, `organizationId`, `ledgerId`, `accountId`, `allowSending`, `allowReceiving`, `direction`, `settings`, `changeType`, `updatedAt`                                                |
| `studio.lerian.balance.deleted`           | `lerian.streaming.balance.deleted`           | A balance is deleted.                                                                                                                                          | `id`, `organizationId`, `ledgerId`, `accountId`, `deletedAt`                                                                                                                         |
| `studio.lerian.balance.overdraft-drawn`   | `lerian.streaming.balance.overdraft-drawn`   | A debit consumes overdraft beyond available funds (`action` = `drawn`).                                                                                        | `balanceId`, `accountId`, `organizationId`, `ledgerId`, `assetCode`, `transactionId`, `operationId`, `action`, `amount`, `overdraftBalance`, `overdraftLimit`, `occurredAt`          |
| `studio.lerian.balance.overdraft-repaid`  | `lerian.streaming.balance.overdraft-repaid`  | Overdraft usage decreases but is not fully cleared (`action` = `repaid`).                                                                                      | `balanceId`, `accountId`, `organizationId`, `ledgerId`, `assetCode`, `transactionId`, `operationId`, `action`, `amount`, `overdraftBalance`, `overdraftLimit`, `occurredAt`          |
| `studio.lerian.balance.overdraft-cleared` | `lerian.streaming.balance.overdraft-cleared` | Overdraft is fully repaid — terminal signal (`action` = `cleared`).                                                                                            | `balanceId`, `accountId`, `organizationId`, `ledgerId`, `assetCode`, `transactionId`, `operationId`, `action`, `amount`, `overdraftBalance`, `overdraftLimit`, `occurredAt`          |

### Transaction

The four lifecycle events share one payload; only the routing type differs.

| Event (`ce-type`)                     | Topic                                    | Fires when                                                                                         | Key payload                                                                                                                                   |
| ------------------------------------- | ---------------------------------------- | -------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| `studio.lerian.transaction.posted`    | `lerian.streaming.transaction.posted`    | A newly created transaction is committed to storage with all its operations persisted (no parent). | `id`, `organizationId`, `ledgerId`, `status`, `amount`, `assetCode`, `source`, `destination`, `route`, `operations`, `metadata`, `createdAt`  |
| `studio.lerian.transaction.committed` | `lerian.streaming.transaction.committed` | A pending transaction transitions from `PENDING` to `APPROVED`.                                    | `id`, `organizationId`, `ledgerId`, `status`, `amount`, `assetCode`, `source`, `destination`, `operations`, `metadata`                        |
| `studio.lerian.transaction.canceled`  | `lerian.streaming.transaction.canceled`  | A pending transaction transitions from `PENDING` to `CANCELED`.                                    | `id`, `organizationId`, `ledgerId`, `status`, `amount`, `assetCode`, `source`, `destination`, `operations`, `metadata`                        |
| `studio.lerian.transaction.reverted`  | `lerian.streaming.transaction.reverted`  | A revert flow creates a child transaction; `parentTransactionId` correlates it to the original.    | `id`, `parentTransactionId`, `organizationId`, `ledgerId`, `status`, `amount`, `assetCode`, `source`, `destination`, `operations`, `metadata` |

## CRM events

Midaz's CRM capability manages account holders and their aliases. These events are emitted on the CRM source (`lerian.midaz.crm` by default), separate from the ledger, but follow the same envelope and versioning.

### Holder

| Event (`ce-type`)              | Topic                             | Fires when                        | Key payload                                               |
| ------------------------------ | --------------------------------- | --------------------------------- | --------------------------------------------------------- |
| `studio.lerian.holder.created` | `lerian.streaming.holder.created` | A holder is created.              | `id`, `organizationId`, `type`, `externalId`, `createdAt` |
| `studio.lerian.holder.updated` | `lerian.streaming.holder.updated` | A holder's mutable fields change. | `id`, `organizationId`, `type`, `externalId`, `updatedAt` |
| `studio.lerian.holder.deleted` | `lerian.streaming.holder.deleted` | A holder is deleted.              | `id`, `organizationId`, `deletionType`, `deletedAt`       |

### Alias

| Event (`ce-type`)                           | Topic                                          | Fires when                                       | Key payload                                                                                        |
| ------------------------------------------- | ---------------------------------------------- | ------------------------------------------------ | -------------------------------------------------------------------------------------------------- |
| `studio.lerian.alias.created`               | `lerian.streaming.alias.created`               | An alias is created for a holder and account.    | `id`, `holderId`, `organizationId`, `ledgerId`, `accountId`, `type`, `relatedParties`, `createdAt` |
| `studio.lerian.alias.updated`               | `lerian.streaming.alias.updated`               | An alias's mutable fields change.                | `id`, `holderId`, `organizationId`, `ledgerId`, `accountId`, `type`, `relatedParties`, `updatedAt` |
| `studio.lerian.alias.deleted`               | `lerian.streaming.alias.deleted`               | An alias is deleted.                             | `id`, `holderId`, `organizationId`, `deletionType`, `deletedAt`                                    |
| `studio.lerian.alias.related-party-deleted` | `lerian.streaming.alias.related-party-deleted` | A single related party is removed from an alias. | `aliasId`, `holderId`, `organizationId`, `relatedPartyId`, `deletedAt`                             |
