metacore Start a pilot

Showcase · Customer relationship management

A CRM, as one domain.

Accounts, contacts, deals and the log of every call and meeting. A discount beyond the policy waits for a sales manager, and a deal closes when a sales manager and finance both approve.

The domain, as its schema declares it

4 entities and 9 layers, 6 roles and 5 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
accountidentityglobalReleasedname, vat_number, website, segment
ownershipterritoryReleasedowner, tier
healthglobalOverlayscore, last_touch
contactmainglobalReleasedaccount, name, title, email, phone
consentglobalReleasedmarketing, agreed_on
dealmainglobalReleasedaccount, title, owner, source
termsglobalReleasedamount, currency, discount_percent, close_on
stageglobalReleasedstage, lost_reason
activityloggedglobalStated oncekind, day, deal, contact, note

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
salesaccount, contact, deal, activitycontact.main, deal.main, deal.terms, deal.stage, activity.loggedStarts closing.
sales manageraccount, contact, deal, activityaccount.ownershipApproves deal.terms. Rolls back deal.terms. Decides the stage approval of closing.
financeaccount, dealNothingDecides the stage approval of closing.
marketingaccount, contactcontact.consentNothing
stewardaccountaccount.identityNothing
scoringNothingaccount.healthNothing

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
discount_policyGate ruleJudges each change of deal.terms before it is live: pass, reject, or hold for a person.
close_dealHandlerChanges deal.stage. Emits deal_won.
handoverHandlerAsks erp through the engine.
log_replyHandlerChanges activity.logged.
import_accountsSourceBrings account.identity in from another system, a batch at a time.

What computes

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

  1. ProposedSales states the amount and the discount
  2. JudgedA gate rule holds a discount beyond the policy
  3. ApprovedA sales manager and finance decide together
  4. WonA handler closes the deal, and hands it to the ERP

A deal, 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
mailWebhookThe third party signs each notification. It starts log_reply.
after_wonTriggerAfter the event deal_won: it starts handover.
nightly_accountsTriggerOn a schedule, 0 2 * * * in UTC: it starts import_accounts.
deal_wonEventA handler emits it for a deal. Other domains and the event stream follow it.
erpThird 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 atoms5 in this domain, in your repository and in your language.
The screens of the sales teamAn app of yours on the public API: a board of deals, a page of an account.
Email and calendarYour mail provider. A webhook logs each answer of a customer.
Forecasts and reportsYour data warehouse. It follows the event stream, at its own pace.

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.

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

# The customers of a sales team: accounts, the people in them, deals and the
# log of what was done. A message of metacore.api.v1.Schema, in the text
# format of Protocol Buffers.
#
#   account   identity   global     what the company is
#             ownership  territory  who holds it in each territory
#             health     global     a score that another system writes live
#   contact   main       global     a person of an account
#             consent    global     what the person agreed to receive
#   deal      main       global     what is being sold, and to whom
#             terms      global     the amount and the discount
#             stage      global     where the deal stands
#   activity  logged     global     a call, a meeting or an email: stated once
#
# A gate rule judges the terms of a deal: it passes a discount within the
# policy, and holds a larger one for a sales manager. A deal closes through a
# workflow, where a sales manager and finance both approve it, and a deal
# that is won is handed over to the ERP. The mail provider tells through a
# webhook when a customer answers, and the answer is logged.
#
# The org declares the scope territory under global before the first
# deployment.

entities {
  name: "account"
  key { name: "code" type: FIELD_TYPE_TEXT }
  layers {
    name: "identity"
    scope: "global"
    fields { name: "name" type: FIELD_TYPE_TEXT required: true min_length: 2 max_length: 160 exposed: true }
    fields { name: "vat_number" type: FIELD_TYPE_TEXT max_length: 20 }
    fields { name: "website" type: FIELD_TYPE_TEXT max_length: 200 }
    fields { name: "segment" type: FIELD_TYPE_TEXT allowed_values: "enterprise" allowed_values: "mid_market" allowed_values: "small" }
    # One account for each VAT number.
    uniques { name: "vat_number" fields: "vat_number" scope: "global" ignore_case: true }
  }
  layers {
    name: "ownership"
    scope: "territory"
    fields { name: "owner" type: FIELD_TYPE_TEXT }
    fields { name: "tier" type: FIELD_TYPE_TEXT allowed_values: "key" allowed_values: "standard" allowed_values: "dormant" }
  }
  layers {
    name: "health"
    scope: "global"
    overlay: true
    fields { name: "score" type: FIELD_TYPE_INTEGER }
    fields { name: "last_touch" type: FIELD_TYPE_TIME }
  }
}

entities {
  name: "contact"
  key { name: "id" type: FIELD_TYPE_TEXT }
  layers {
    name: "main"
    scope: "global"
    fields { name: "account" type: FIELD_TYPE_REFERENCE required: true reference { entity: "account" carries: "name" } }
    fields { name: "name" type: FIELD_TYPE_TEXT required: true }
    fields { name: "title" type: FIELD_TYPE_TEXT max_length: 120 }
    fields {
      name: "email"
      type: FIELD_TYPE_TEXT
      restricted { read_roles: "sales" read_roles: "sales_manager" read_roles: "marketing" write_roles: "sales" }
    }
    fields { name: "phone" type: FIELD_TYPE_TEXT restricted { read_roles: "sales" read_roles: "sales_manager" write_roles: "sales" } }
    uniques { name: "email" fields: "email" scope: "global" ignore_case: true }
  }
  layers {
    name: "consent"
    scope: "global"
    fields { name: "marketing" type: FIELD_TYPE_BOOLEAN }
    fields { name: "agreed_on" type: FIELD_TYPE_DATE }
  }
}

entities {
  name: "deal"
  key { name: "number" type: FIELD_TYPE_TEXT }
  layers {
    name: "main"
    scope: "global"
    fields { name: "account" type: FIELD_TYPE_REFERENCE required: true reference { entity: "account" carries: "name" } }
    fields { name: "title" type: FIELD_TYPE_TEXT required: true max_length: 160 }
    fields { name: "owner" type: FIELD_TYPE_TEXT }
    fields { name: "source" type: FIELD_TYPE_TEXT allowed_values: "inbound" allowed_values: "outbound" allowed_values: "partner" }
  }
  layers {
    name: "terms"
    scope: "global"
    fields { name: "amount" 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: "discount_percent" type: FIELD_TYPE_DECIMAL decimal_places: 2 least { decimal: "0" } greatest { decimal: "100" } }
    fields { name: "close_on" type: FIELD_TYPE_DATE }
  }
  layers {
    name: "stage"
    scope: "global"
    fields { name: "stage" type: FIELD_TYPE_TEXT allowed_values: "lead" allowed_values: "qualified" allowed_values: "proposal" allowed_values: "won" allowed_values: "lost" }
    fields { name: "lost_reason" type: FIELD_TYPE_TEXT max_length: 300 }
  }
}

# What was done is a document: an activity never changes once it is logged,
# and a correction is an activity of its own.
entities {
  name: "activity"
  key { name: "number" type: FIELD_TYPE_TEXT }
  layers {
    name: "logged"
    scope: "global"
    once: true
    fields { name: "kind" type: FIELD_TYPE_TEXT required: true allowed_values: "call" allowed_values: "meeting" allowed_values: "email" }
    fields { name: "day" type: FIELD_TYPE_DATE required: true }
    fields { name: "deal" type: FIELD_TYPE_REFERENCE reference { entity: "deal" } }
    fields { name: "contact" type: FIELD_TYPE_REFERENCE reference { entity: "contact" } }
    fields { name: "note" type: FIELD_TYPE_TEXT max_length: 2000 }
  }
}

roles {
  name: "sales"
  permissions { operation: OPERATION_READ entity: "account" }
  permissions { operation: OPERATION_READ entity: "contact" }
  permissions { operation: OPERATION_READ entity: "deal" }
  permissions { operation: OPERATION_READ entity: "activity" }
  permissions { operation: OPERATION_CHANGE entity: "contact" layer: "main" }
  permissions { operation: OPERATION_CHANGE entity: "deal" layer: "main" }
  permissions { operation: OPERATION_CHANGE entity: "deal" layer: "terms" }
  permissions { operation: OPERATION_CHANGE entity: "deal" layer: "stage" }
  permissions { operation: OPERATION_CHANGE entity: "activity" layer: "logged" }
  permissions { operation: OPERATION_START workflow: "closing" }
}

roles {
  name: "sales_manager"
  permissions { operation: OPERATION_READ entity: "account" }
  permissions { operation: OPERATION_READ entity: "contact" }
  permissions { operation: OPERATION_READ entity: "deal" }
  permissions { operation: OPERATION_READ entity: "activity" }
  permissions { operation: OPERATION_CHANGE entity: "account" layer: "ownership" }
  permissions { operation: OPERATION_DECIDE entity: "deal" layer: "terms" }
  permissions { operation: OPERATION_GO_BACK entity: "deal" layer: "terms" }
}

roles {
  name: "finance"
  permissions { operation: OPERATION_READ entity: "account" }
  permissions { operation: OPERATION_READ entity: "deal" }
}

roles {
  name: "marketing"
  permissions { operation: OPERATION_READ entity: "account" }
  permissions { operation: OPERATION_READ entity: "contact" }
  permissions { operation: OPERATION_CHANGE entity: "contact" layer: "consent" }
}

roles {
  name: "steward"
  permissions { operation: OPERATION_READ entity: "account" }
  permissions { operation: OPERATION_CHANGE entity: "account" layer: "identity" }
}

roles {
  name: "scoring"
  permissions { operation: OPERATION_CHANGE entity: "account" layer: "health" }
}

atoms {
  name: "discount_policy"
  connection: "sales_rules"
  timeout { seconds: 5 }
  gate_rule { layer { entity: "deal" layer: "terms" } }
}

atoms {
  name: "close_deal"
  connection: "sales_rules"
  timeout { seconds: 30 }
  handler {
    inputs { name: "number" type: FIELD_TYPE_TEXT required: true }
    outcomes: "won"
    outcomes: "lost"
    changes { entity: "deal" layer: "stage" }
    events: "deal_won"
  }
}

# A deal that is won goes to the ERP: the handler asks it through the engine,
# with a secret that the org keeps.
atoms {
  name: "handover"
  connection: "integrations"
  timeout { seconds: 30 }
  handler {
    outcomes: "handed_over"
    outcomes: "refused"
    asks: "erp"
  }
}

atoms {
  name: "log_reply"
  connection: "integrations"
  timeout { seconds: 15 }
  handler {
    outcomes: "logged"
    outcomes: "ignored"
    changes { entity: "activity" layer: "logged" }
  }
}

atoms {
  name: "import_accounts"
  connection: "integrations"
  timeout { seconds: 60 }
  source { changes { entity: "account" layer: "identity" } }
}

events {
  name: "deal_won"
  entity: "deal"
  exposed: true
}

triggers {
  name: "after_won"
  event { event: "deal_won" }
  atom: "handover"
}

triggers {
  name: "nightly_accounts"
  schedule { cron: "0 2 * * *" time_zone: "UTC" }
  atom: "import_accounts"
}

# A sales manager and finance approve the closing of a deal together: one of
# them can decline it, and only both move it on.
workflows {
  name: "closing"
  inputs { name: "number" type: FIELD_TYPE_TEXT required: true }
  first_stage: "approval"
  stages {
    name: "approval"
    person {
      roles { role: "sales_manager" }
      roles { role: "finance" }
      timeout { seconds: 432000 }
      outcomes: "approved"
      outcomes: "declined"
      agreed_outcome: "approved"
      second_person: true
    }
    transitions { outcome: "approved" next_stage: "close" }
    transitions { outcome: "declined" }
  }
  stages {
    name: "close"
    handler: "close_deal"
    transitions { outcome: "won" }
    transitions { outcome: "lost" }
  }
}

# The mail provider signs the body, and writes the signature in hex.
webhooks {
  name: "mail"
  handler: "log_reply"
  proof: WEBHOOK_PROOF_SIGNATURE
  proof_header: "X-Mail-Signature"
  signature_encoding: SIGNATURE_ENCODING_HEX
  id_header: "X-Mail-Event-Id"
}

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