Skip to content

Domain.Model reference

Source: packages/domain/src/Model.ts

The aggregates, views and policies you host together. layer(policies) builds them all on the Platform you provide, and provides each aggregate and view as a service.

import * as Domain from "@alchemy.run/domain";
import * as Layer from "effect/Layer";
import { Account } from "./Account.ts";
import { AccountSummary } from "./AccountSummary.ts";
import { Customer } from "./Customer.ts";
import { MainAccountProvisioning, MainAccountProvisioningLive } from "./MainAccountProvisioning.ts";
export class Bank extends Domain.Model("Bank", {
aggregates: [Account, Customer],
views: [AccountSummary],
policies: [MainAccountProvisioning],
}) {}
export const BankInMemory = Bank.layer(MainAccountProvisioningLive).pipe(
Layer.provide(Domain.InMemory),
);

The last argument is its annotations: data for what is built on the model, read back as X.annotations. Add your own keys by augmenting Domain.Annotations.

A model lists its declarations, so tooling can walk them and read each one’s annotations.

export class Bank extends Domain.Model(
"Bank",
{ aggregates: [Account], views: [AccountSummary] },
{ description: "Accounts and their balances." },
) {}
const glossary = Bank.commands.map((command) => `${command.tag}: ${command.annotations.description}`);