metacore Start a pilot

Showcase · Online shop

An online shop, as one domain.

Products with prices by market and stock by warehouse, and orders that never change once placed. Two customers never buy the same last unit, and a wrong price list rolls back in one step.

The domain, as its schema declares it

3 entities and 8 layers, 7 roles and 4 atoms, in one file.

Model

Each entity, split by who changes it.

A layer is a group of fields that change together: it is the unit of a permission, of an approval and of a release. Its scope is the lowest level at which a value may differ.

EntityLayerScopeKindFields
productidentityglobalReleasedname, brand, status
textslanguageReleasedtitle, description, slug
medialanguageReleasedphotos
pricingmarketDatedprice, cost
stockwarehouseBalanceson_hand, reserved, sold, supplied
orderplacedglobalStated oncecustomer, email, total, currency, day
fulfilmentglobalReleasedstatus, carrier, tracking
order lineplacedglobalStated onceproduct, quantity, unit_price

The entities and their layers

A released layer publishes and rolls back. A dated one holds values by period, one stated once never changes, balances add up, and an overlay is written live by another system.

Roles

A role holds what a job needs, and no more.

A role names operations on layers. Where a person works is in the grant: one role serves every scope value, and a grant gives it on one.

RoleReadsChangesDecides, starts and calls
merchandiserproductproduct.identity, product.texts, product.mediaNothing
pricerproductproduct.pricingNothing
price keeperproductNothingApproves product.pricing. Rolls back product.pricing.
financeproduct, order, order lineproduct.pricingNothing
storefrontproductNothingCalls checkout.
warehouseproduct, order, order lineproduct.stock, order.fulfilmentNothing
serviceorder, order lineorder.fulfilmentNothing

Who does what

The engine checks each operation for every caller: a person, a system or an AI agent.

Flow

People decide, and your code acts.

The schema holds no formula and no condition. Whatever computes is an atom: your code, which the engine calls outside itself or in a sandbox.

AtomKindWhat it does
price_guardGate ruleJudges each change of product.pricing before it is live: pass, reject, or hold for a person.
checkoutHandlerChanges order.placed, order_line.placed and product.stock. Emits order_placed. A caller with the grant calls it.
intakeHandlerChanges order.fulfilment and product.stock.
confirmHandlerAsks mail through the engine.

What computes

An atom returns its effects as data, and the engine checks each one.

  1. CheckoutThe storefront calls one procedure
  2. PlacedThe order, its lines and the reserved units, in one step
  3. PaidThe payment provider tells through a webhook
  4. ShippedThe carrier tells through a webhook

An order, step by step

Each step is a run with its own audit entry.

Connections

What comes in, and what goes out.

A third party reaches the domain through a webhook, and a handler reaches a third party through the engine. A schema holds no address and no secret: an admin binds each one in each environment.

NameKindHow
paymentsWebhookThe secret is in the address. It starts intake.
carrierWebhookThe third party signs each notification. It starts intake.
after_orderTriggerAfter the event order_placed: it starts confirm.
order_placedEventA handler emits it for a order. Other domains and the event stream follow it.
mailThird partyA handler asks it through the engine, with a secret that your org keeps.

The connections of the domain

Every system meets the engine at one public API.

Boundaries

What the engine gives, and what you build.

metacore is not a product of this kind. It is the engine under one that you build: the guarantees come with it, and the rest is yours.

From the engineWhat you get
A public APITyped from the schema, for every entity. There is no private interface.
A back officeEvery record at every level, from the schema, with no code.
Access controlA role holds an operation, on a layer, at a scope value.
Approvals and releasesA change waits where a person must approve it, publishes in one step, and rolls back in one step.
An audit trailAn entry is written in the same step as the operation it records.
Search, events and MCPBuilt in, from the same schema.

With no code

The same for every domain.

Yours to buildHow it meets the engine
The schemaThis file. It is the whole model, and it changes only by deployment.
The atoms4 in this domain, in your repository and in your language.
The storefrontAn app of yours on the public API. It reads the products, and calls the checkout.
PaymentsYour payment provider. It tells through a webhook when a payment settles: no card enters the domain.
DeliveryYour carrier. It tells through a webhook where a parcel is.

In your code

A product of this kind brings its own screens. Here they are yours.

Schema

The whole domain, in one file.

Every table of this page is read from this file. The check of the CLI finds no problem in it.

commerce.txtpb
# proto-file: metacore/api/v1/schema.proto
# proto-message: metacore.api.v1.Schema

# An online shop: its products with their prices and their stock, and the
# orders that customers place. A message of metacore.api.v1.Schema, in the
# text format of Protocol Buffers.
#
#   product     identity    global     what the product is
#               texts       language   what a customer reads
#               media       language   what a customer sees
#               pricing     market     what it costs, by period
#               stock       warehouse  its units: balances that many orders add to
#   order       placed      global     the order as it was placed: stated once
#               fulfilment  global     where the order stands
#   order_line  placed      global     a line of an order: stated once
#
# The units of a product are conserved: a change set moves them between
# warehouses, or between on_hand, reserved and sold, and their sum stays the
# same. What a supplier delivers comes from supplied, the one balance with no
# least.
#
# The storefront calls the procedure checkout, which states the order with
# its lines and reserves the units in one change set: of two customers who
# take the last unit, one order publishes and the other fails whole. The
# payment provider and the carrier tell through webhooks what happened to an
# order, and a gate rule holds a change of prices that reaches too far.
#
# The org declares the scopes before the first deployment: language and
# market under global, and warehouse under market.

entities {
  name: "product"
  key { name: "sku" type: FIELD_TYPE_TEXT }
  layers {
    name: "identity"
    scope: "global"
    fields { name: "name" type: FIELD_TYPE_TEXT required: true min_length: 2 max_length: 120 exposed: true }
    fields { name: "brand" type: FIELD_TYPE_TEXT max_length: 60 }
    fields { name: "status" type: FIELD_TYPE_TEXT allowed_values: "draft" allowed_values: "active" allowed_values: "retired" }
  }
  layers {
    name: "texts"
    scope: "language"
    fields { name: "title" type: FIELD_TYPE_TEXT max_length: 200 }
    fields { name: "description" type: FIELD_TYPE_TEXT }
    fields { name: "slug" type: FIELD_TYPE_TEXT pattern: "[a-z0-9-]{1,80}" }
    uniques { name: "slug" fields: "slug" scope: "language" ignore_case: true }
  }
  layers {
    name: "media"
    scope: "language"
    fields {
      name: "photos"
      type: FIELD_TYPE_FILE
      list: true
      file {
        media_types: [FILE_MEDIA_TYPE_JPEG, FILE_MEDIA_TYPE_PNG, FILE_MEDIA_TYPE_WEBP]
        public: true
        widths: [320, 640, 1280]
        max_bytes: 20971520
        min_width: 800
        min_height: 800
      }
    }
  }
  # A price holds over a period that its change names: a price list from a
  # day, or a promotion of one week over it.
  layers {
    name: "pricing"
    scope: "market"
    dated: true
    fields { name: "price" type: FIELD_TYPE_DECIMAL decimal_places: 2 least { decimal: "0" } exposed: true }
    fields {
      name: "cost"
      type: FIELD_TYPE_DECIMAL
      decimal_places: 4
      least { decimal: "0" }
      restricted { read_roles: "finance" write_roles: "finance" }
    }
  }
  layers {
    name: "stock"
    scope: "warehouse"
    balances: true
    conserved { key: "sku" }
    fields { name: "on_hand" type: FIELD_TYPE_INTEGER least { integer: 0 } }
    fields { name: "reserved" type: FIELD_TYPE_INTEGER least { integer: 0 } }
    fields { name: "sold" type: FIELD_TYPE_INTEGER least { integer: 0 } }
    fields { name: "supplied" type: FIELD_TYPE_INTEGER }
  }
}

entities {
  name: "order"
  key { name: "number" type: FIELD_TYPE_TEXT }
  layers {
    name: "placed"
    scope: "global"
    once: true
    fields { name: "customer" type: FIELD_TYPE_TEXT required: true max_length: 120 }
    fields { name: "email" type: FIELD_TYPE_TEXT restricted { read_roles: "service" write_roles: "service" } }
    fields { name: "total" type: FIELD_TYPE_DECIMAL decimal_places: 2 least { decimal: "0" } }
    fields { name: "currency" type: FIELD_TYPE_TEXT allowed_values: "EUR" allowed_values: "USD" allowed_values: "GBP" }
    fields { name: "day" type: FIELD_TYPE_DATE required: true }
  }
  layers {
    name: "fulfilment"
    scope: "global"
    fields { name: "status" type: FIELD_TYPE_TEXT allowed_values: "paid" allowed_values: "picked" allowed_values: "shipped" allowed_values: "delivered" allowed_values: "returned" }
    fields { name: "carrier" type: FIELD_TYPE_TEXT max_length: 60 }
    fields { name: "tracking" type: FIELD_TYPE_TEXT max_length: 80 }
  }
}

entities {
  name: "order_line"
  key { name: "order" type: FIELD_TYPE_TEXT }
  key { name: "position" type: FIELD_TYPE_INTEGER }
  layers {
    name: "placed"
    scope: "global"
    once: true
    fields { name: "product" type: FIELD_TYPE_REFERENCE required: true reference { entity: "product" carries: "name" } }
    fields { name: "quantity" type: FIELD_TYPE_INTEGER least { integer: 1 } }
    fields { name: "unit_price" type: FIELD_TYPE_DECIMAL decimal_places: 2 least { decimal: "0" } }
  }
}

roles {
  name: "merchandiser"
  permissions { operation: OPERATION_READ entity: "product" }
  permissions { operation: OPERATION_CHANGE entity: "product" layer: "identity" }
  permissions { operation: OPERATION_CHANGE entity: "product" layer: "texts" }
  permissions { operation: OPERATION_CHANGE entity: "product" layer: "media" }
}

roles {
  name: "pricer"
  permissions { operation: OPERATION_READ entity: "product" }
  permissions { operation: OPERATION_CHANGE entity: "product" layer: "pricing" }
}

roles {
  name: "price_keeper"
  permissions { operation: OPERATION_READ entity: "product" }
  permissions { operation: OPERATION_DECIDE entity: "product" layer: "pricing" }
  permissions { operation: OPERATION_GO_BACK entity: "product" layer: "pricing" }
}

roles {
  name: "finance"
  permissions { operation: OPERATION_READ entity: "product" }
  permissions { operation: OPERATION_READ entity: "order" }
  permissions { operation: OPERATION_READ entity: "order_line" }
  permissions { operation: OPERATION_CHANGE entity: "product" layer: "pricing" }
}

roles {
  name: "storefront"
  permissions { operation: OPERATION_READ entity: "product" }
  permissions { operation: OPERATION_CALL procedure: "checkout" }
}

roles {
  name: "warehouse"
  permissions { operation: OPERATION_READ entity: "product" }
  permissions { operation: OPERATION_READ entity: "order" }
  permissions { operation: OPERATION_READ entity: "order_line" }
  permissions { operation: OPERATION_CHANGE entity: "product" layer: "stock" }
  permissions { operation: OPERATION_CHANGE entity: "order" layer: "fulfilment" }
}

roles {
  name: "service"
  permissions { operation: OPERATION_READ entity: "order" }
  permissions { operation: OPERATION_READ entity: "order_line" }
  permissions { operation: OPERATION_CHANGE entity: "order" layer: "fulfilment" }
}

atoms {
  name: "price_guard"
  connection: "pricing"
  timeout { seconds: 5 }
  gate_rule { layer { entity: "product" layer: "pricing" } }
}

atoms {
  name: "checkout"
  connection: "shop"
  timeout { seconds: 15 }
  handler {
    inputs { name: "cart" type: FIELD_TYPE_TEXT required: true }
    outcomes: "placed"
    outcomes: "refused"
    changes { entity: "order" layer: "placed" }
    changes { entity: "order_line" layer: "placed" }
    changes { entity: "product" layer: "stock" }
    events: "order_placed"
    exposed: true
  }
}

# One handler takes what the payment provider and the carrier tell, and
# states where the order stands.
atoms {
  name: "intake"
  connection: "shop"
  timeout { seconds: 30 }
  handler {
    outcomes: "taken"
    outcomes: "ignored"
    outcomes: "refused"
    changes { entity: "order" layer: "fulfilment" }
    changes { entity: "product" layer: "stock" }
  }
}

atoms {
  name: "confirm"
  connection: "shop"
  timeout { seconds: 30 }
  handler {
    outcomes: "sent"
    outcomes: "failed"
    asks: "mail"
  }
}

events {
  name: "order_placed"
  entity: "order"
  exposed: true
}

triggers {
  name: "after_order"
  event { event: "order_placed" }
  atom: "confirm"
}

# The payment provider signs a timestamp with the body, which no schema
# declares: its secret is in the address, and the handler checks the
# signature from the header that it receives.
webhooks {
  name: "payments"
  handler: "intake"
  proof: WEBHOOK_PROOF_ADDRESS
  headers: "Payment-Signature"
  id_header: "Payment-Event-Id"
}

# The carrier signs the body, and writes the signature in hex after a prefix.
webhooks {
  name: "carrier"
  handler: "intake"
  proof: WEBHOOK_PROOF_SIGNATURE
  proof_header: "X-Carrier-Signature"
  proof_prefix: "sha256="
  signature_encoding: SIGNATURE_ENCODING_HEX
  id_header: "X-Carrier-Delivery"
}

The schema of the domain

A message of the public contract, in the text format of Protocol Buffers.

See also

Build your domain.

Declare its schema, and take it to production, self-hosted or in a managed region.

Briefing