Examples
Real domain specifications and all seven artifact types Moment generates from them. Every output is deterministic — the same input always produces the same result.
context "Ordering" [Core]
aggregate "Order"
identity orderId: UUID
command PlaceOrder
input customerId: UUID, items: OrderItem[]
precondition orderNotPlaced: "Order has not already been placed"
emits OrderPlaced
command CancelOrder
input orderId: UUID, reason: string
precondition orderNotShipped: "Order must not have been shipped"
emits OrderCancelled
event OrderPlaced
orderId: UUID
customerId: UUID
items: OrderItem[]
placedAt: DateTime
event OrderCancelled
orderId: UUID
reason: string
cancelledAt: DateTime
value-object OrderItem
productId: UUID
quantity: number
unitPrice: Money
invariant ORD-01 "Order must contain at least one item"
scope Order
context "Fulfillment" [Supporting]
aggregate "FulfillmentRequest"
identity fulfillmentId: UUID
command InitiateFulfillment
input orderId: UUID, items: OrderItem[]
emits FulfillmentInitiated
event FulfillmentInitiated
fulfillmentId: UUID
orderId: UUID
items: OrderItem[]
initiatedAt: DateTime
value-object OrderItem
productId: UUID
quantity: number
unitPrice: Money
flow "order-placed"
description "Order submission triggers fulfillment"
lane ordering "Ordering" [Core]
lane fulfillment "Fulfillment" [Supporting]
moment "Order submission"
ordering: PlaceOrder
ordering: OrderPlaced crosses-to fulfillment via CustomerSupplier
contract
orderId: UUID [required]
items: OrderItem[] [required]
moment "Fulfillment initiation"
fulfillment: InitiateFulfillment
triggered-by OrderPlaced
fulfillment: FulfillmentInitiated// Generated by @mmmnt/emit-ts
// ── Ordering Context ──
export type OrderEvent =
| OrderPlaced
| OrderCancelled;
export interface OrderPlaced {
readonly _tag: 'OrderPlaced';
readonly orderId: UUID;
readonly customerId: UUID;
readonly items: readonly OrderItem[];
readonly placedAt: DateTime;
}
export interface OrderCancelled {
readonly _tag: 'OrderCancelled';
readonly orderId: UUID;
readonly reason: string;
readonly cancelledAt: DateTime;
}
export interface OrderItem {
readonly productId: UUID;
readonly quantity: number;
readonly unitPrice: Money;
}
export interface PlaceOrderInput {
readonly customerId: UUID;
readonly items: readonly OrderItem[];
}
/** @precondition orderNotPlaced — Order has not already been placed */
export interface OrderAggregate {
placeOrder(input: PlaceOrderInput): OrderPlaced;
cancelOrder(input: CancelOrderInput): OrderCancelled;
}
// ── Fulfillment Context ──
export type FulfillmentRequestEvent =
| FulfillmentInitiated;
export interface FulfillmentInitiated {
readonly _tag: 'FulfillmentInitiated';
readonly fulfillmentId: UUID;
readonly orderId: UUID;
readonly items: readonly OrderItem[];
readonly initiatedAt: DateTime;
}// Generated by @mmmnt/emit-ts — Test Scaffold
import { describe, it, beforeEach } from 'vitest';
describe('Flow: order-placed', () => {
describe('Order submission', () => {
it('should execute PlaceOrder in Ordering', () => {
// Setup: precondition "orderNotPlaced" must hold
// Assert: OrderPlaced is emitted
// TODO: implement command execution
});
it('should verify OrderPlaced crosses from Ordering to Fulfillment', () => {
// Crossing: Ordering → Fulfillment via CustomerSupplier
// Contract fields:
// orderId: UUID (required)
// items: OrderItem[] (required)
// TODO: assert contract compliance
});
});
describe('Fulfillment initiation', () => {
beforeEach(() => {
// triggered-by: OrderPlaced
// Ensure OrderPlaced has been emitted
});
it('should execute InitiateFulfillment triggered by OrderPlaced', () => {
// Assert: FulfillmentInitiated is emitted
// TODO: implement command execution
});
});
});
describe('Ordering / Order aggregate', () => {
it('should enforce invariant ORD-01: Order must contain at least one item', () => {
// Reject PlaceOrder when items is empty
// TODO: implement invariant assertion
});
});# Generated by @mmmnt/generate
@flow:order-placed
Feature: Order submission triggers fulfillment
@context:Ordering @classification:Core
Rule: Ordering [Core]
Background:
Given precondition "orderNotPlaced" holds:
| Order has not already been placed |
@happy-path
Scenario: Order submission
When Ordering executes PlaceOrder with:
| customerId | <UUID> |
| items | <OrderItem[]> |
Then Ordering emits OrderPlaced
@crossing
Scenario: OrderPlaced crosses to Fulfillment
Given Ordering has emitted OrderPlaced
Then OrderPlaced crosses to Fulfillment via CustomerSupplier
And the crossing contract contains:
| orderId | UUID | required |
| items | OrderItem[] | required |
@context:Fulfillment @classification:Supporting
Rule: Fulfillment [Supporting]
Scenario: Fulfillment initiation
Given OrderPlaced has been received
When Fulfillment executes InitiateFulfillment
triggered-by OrderPlaced
Then Fulfillment emits FulfillmentInitiated
@invariant
Scenario: Invariant ORD-01 — Order must contain at least one item
When Ordering executes PlaceOrder with:
| items | [] |
Then the command is rejected
And invariant ORD-01 is violatedOrder Placement — Specification Document
Generated by @mmmnt/generate
At a Glance
| Context | Classification | Aggregates | Commands | Events |
|---|---|---|---|---|
| Ordering | Core | 1 | 2 | 2 |
| Fulfillment | Supporting | 1 | 1 | 1 |
Context Map
graph LR
Ordering["Ordering\n[Core]"]
Fulfillment["Fulfillment\n[Supporting]"]
Ordering -->|CustomerSupplier| Fulfillment
Flow: order-placed
Order submission triggers fulfillment
sequenceDiagram
participant O as Ordering [Core]
participant F as Fulfillment [Supporting]
Note over O: Order submission
O->>O: PlaceOrder
O->>F: OrderPlaced (CustomerSupplier)
Note over O,F: contract: orderId, items
Note over F: Fulfillment initiation
F->>F: InitiateFulfillment (triggered-by OrderPlaced)
F->>F: FulfillmentInitiated
Context Boundaries
| Source | Target | Event | Relationship | Required Fields |
|---|---|---|---|---|
| Ordering | Fulfillment | OrderPlaced | CustomerSupplier | orderId, items |
Domain Model
Ordering [Core]
Order (identity: orderId)
- PlaceOrder → OrderPlaced
- CancelOrder → OrderCancelled
- Invariant ORD-01: Order must contain at least one item
Fulfillment [Supporting]
FulfillmentRequest (identity: fulfillmentId)
- InitiateFulfillment → FulfillmentInitiated
# Generated by @mmmnt/generate
asyncapi: '3.0.0'
info:
title: Order Placement
version: '1.0.0'
description: >-
Event-driven contract for the order-placed flow.
Ordering emits OrderPlaced; Fulfillment consumes it.
channels:
order-placed:
address: ordering.order-placed
messages:
OrderPlaced:
$ref: ' 1
operations:
publishOrderPlaced:
action: send
channel:
$ref: '#/channels/order-placed'
summary: Ordering publishes OrderPlaced on order submission
components:
messages:
OrderPlaced:
name: OrderPlaced
title: Order Placed Event
summary: Emitted when a new order is placed
payload:
type: object
required:
- orderId
- items
properties:
orderId:
type: string
format: uuid
customerId:
type: string
format: uuid
items:
type: array
items:
$ref: '#/components/schemas/OrderItem'
placedAt:
type: string
format: date-time
schemas:
OrderItem:
type: object
properties:
productId:
type: string
format: uuid
quantity:
type: number
unitPrice:
type: number// Generated by @mmmnt/derive — Facet Simulation Scenario
{
"scenarioId": "order-placed-happy-path",
"scenarioLabel": "Order Placement — Happy Path",
"description": "Order submission triggers fulfillment",
"given": "An order is ready to be placed",
"when": "PlaceOrder is executed in Ordering",
"then": "OrderPlaced crosses to Fulfillment and InitiateFulfillment is triggered",
"expectedPath": [
"moment:order-submission",
"moment:fulfillment-initiation"
],
"activeBranches": [],
"events": [
{
"eventId": "evt-001",
"eventType": "OrderPlaced",
"productSource": "moment",
"causationEventIds": [],
"correlationId": "corr-order-placed-001",
"timestamp": "2026-01-15T10:00:00.000Z",
"version": "1.0.0",
"payload": {
"orderId": "ord-abc-123",
"customerId": "cust-def-456",
"items": [
{ "productId": "prod-001", "quantity": 2, "unitPrice": 29.99 }
],
"placedAt": "2026-01-15T10:00:00.000Z"
}
},
{
"eventId": "evt-002",
"eventType": "FulfillmentInitiated",
"productSource": "moment",
"causationEventIds": ["evt-001"],
"correlationId": "corr-order-placed-001",
"timestamp": "2026-01-15T10:00:01.000Z",
"version": "1.0.0",
"payload": {
"fulfillmentId": "ful-ghi-789",
"orderId": "ord-abc-123",
"items": [
{ "productId": "prod-001", "quantity": 2, "unitPrice": 29.99 }
],
"initiatedAt": "2026-01-15T10:00:01.000Z"
}
}
]
}Understanding the outputs
The domain specification you write — contexts, aggregates, flows, crossings, sagas, policies, and branches.
Generated interfaces with discriminated unions, readonly fields, aggregate contracts, and barrel exports.
Pre-populated Vitest files with crossing assertions, branch coverage stubs, and saga/policy test cases.
BDD scenarios with crossing contracts, branch paths, saga lifecycle, policy chains, and invariant violations.
Markdown with Mermaid context maps, sequence diagrams, domain model reference, and crossing boundary tables.
Event-driven API contracts for crossing events in AsyncAPI 3.0 format with typed payload schemas.
Facet-compatible simulation scenarios with synthetic events, causation chains, correlation tracking, and branch path resolution.