Domain
alchemy/Domain models your business in its own terms. Commands ask for changes, aggregates decide them, and events record what happened. Views, projections and policies then answer questions, feed your own stores, and apply the business’s rules about what to do next.
The same model runs in memory for tests and on Cloudflare Durable Objects in production, with one ordered partition per key.
A taste
Section titled “A taste”A command declares what it asks for and every way it can end:
export class MoneyDeposited extends Domain.Event("MoneyDeposited", { amount: Schema.Int, balanceAfter: Schema.Int,}) {}
export class DepositMoney extends Domain.Command("DepositMoney", { target: AccountId, input: { amount: Schema.Int }, events: [MoneyDeposited], rejects: [NotOpen], reply: { balance: Schema.Int },}) {}The account aggregate decides it against its current state:
DepositMoney: (s, cmd) => s._tag !== "Open" ? new NotOpen() : [new MoneyDeposited({ amount: cmd.amount, balanceAfter: s.balance + cmd.amount })],And a story tests it in memory, in the business’s own words: given this history, when this command, then these events.
it.effect("deposits into an open account and replies with the balance", () => story( Story.given(account, new AccountOpened({ owner: "sam" })), Story.when(account, new DepositMoney({ amount: 100 })), Story.then(account, new MoneyDeposited({ amount: 100, balanceAfter: 100 })), Story.replied({ balance: 100 }), ),);Build it with your coding agent
Section titled “Build it with your coding agent”The alchemy-domain skill teaches a coding agent how to turn requirements into a model, lay out the project, test it with stories, host it on Cloudflare and drive it from foldkit.
Ship it with your dependencies, so the skill always matches the alchemy version you have installed:
bun add -d skills-npmbunx skills-npm setupsetup adds a prepare script. Every install then links the skills your packages ship into each coding agent’s skills folder.
Or install it from GitHub, for any agent:
npx skills add alchemy-run/alchemy --skill alchemy-domainIn Claude Code, it’s also a plugin:
/plugin install alchemy --marketplace alchemy-run/alchemyA skill installed from GitHub follows the repository’s main branch, so update it when you upgrade alchemy.
Where to start
Section titled “Where to start”New to domain-driven design? What is Domain-Driven Design? introduces the ideas one at a time, with the bank as the example.
Want to build one? The tutorial builds a bank step by step, from a single account on your machine to an Api deployed on Cloudflare with a browser app.
Know the ideas and want the API? Domain Model shows how a model runs, and each building block has its own page: Command, Event, Aggregate, View, Projection, Stream, Policy and Api.