Facet
DeutschInstall
Integrations & setup

Keep two products in one monorepo apart with FACET

Give each product in a monorepo its own set of FACET recordA FACET record is a short, checkable description of one feature, kept as a YAML file next to the code. It states why the feature exists, the behaviour it promises as scenarios, and the tests that check it.In the glossary, a RegistryThe registry is the set of FACET records of one product, which FACET indexes, checks and serves to tools. A monorepo can declare several registries in .facetrc.yaml, each with its own source folders.In the glossary, write each product's rule under a shared Feature idA feature id is the stable name of a feature in three parts, domain/capability/feature, for example checkout/pricing/discount-code-redemption. It does not change after creation.In the glossary, and ask before every commit which product's rule a change touches.

  • 9 min read
  • 7 steps
  • npmGit
  • Your coding agent

Support asks for a longer refund window. A developer searches the repository for "refund", finds REFUND_WINDOW_DAYS = 30, changes it to 45 and opens a pull request. The request was about the back office, the internal tool where support staff refund orders. The constant belongs to the customer shop, which lives in the same repository. Two products, one word, and nobody in the review noticed which product the change hit.

FACET keeps a short, checkable description of each feature, called a record, next to your code and checks that the two still match. By the end of this guide each product has its own set of records, and FACET tells you which product's rule a change touches before you commit it. The FACET feature behind it is registries: a registry is one product's set of records, declared in .facetrc.yaml, FACET's configuration file, and each registry owns its own source folders.

The commands below use a small example shop written in TypeScript, set up as in “One answer instead of three”. Its repository holds a second product: a back office for the support team in apps/admin/. In your own monorepo, use your apps' folders instead.

Step 1Check that you really have two products

Ask one question about a feature: "does this exist over there yet?" If the question makes sense, you have one product built twice, such as a web app and a native app, or an old system and its rewrite. That is a different case; FACET calls it VariantA variant is an independently deployable place where a feature can exist or not, such as a web app and an iOS app. One record then has its own lifecycle state per variant.In the glossary. If the question makes no sense, because nobody asks whether the back office has the shop's checkout, you have two products. Then each product gets its own registry.

In the example, the shop has a cart, discount codes and checkout. The back office has staff refunds and, planned, discount-code management. Both have something called refunds, with different rules.

Step 2Declare one registry per product

Create .facetrc.yaml in the repository root:

yaml
registries:  shop:    records: docs/facets    sources: [src, tests]    description: the customer-facing web shop  admin:    records: apps/admin/docs/facets    sources: [apps/admin]    schema: docs/facets/schema    description: the internal back office for the support team
  • records is where the product's records live. The shop keeps the folder it already has.
  • sources lists the folders that belong to the product. Code there is checked against this registry's records only.
  • schema points the back office at the schemas facet init already wrote, so its records are validated too.
  • description says in a few words what the product is, for people and coding agents reading the configuration.

Create the back office's record folders:

sh
  • mkdir -p apps/admin/docs/facets/features/orders/refunds apps/admin/docs/facets/features/checkout/discounts

Step 3Write down each product's rule under the same id

The refund feature exists in both products, so it gets the same id in both: orders/refunds/refund-order. Ids are shared across registries. Each product writes its own record for it.

Save the shop's rule as docs/facets/features/orders/refunds/refund-order.yaml (create the folder with mkdir -p docs/facets/features/orders/refunds):

yaml
schema_version: "0.1"id: orders/refunds/refund-orderlifecycle: activeintent:  summary: A customer asks for a full or partial refund within 30 days of delivery and gets the money back the way they paid.contract:  scenarios:    - id: within-30-days      statement: |        Given an order delivered 20 days ago        When the customer asks for a refund        Then the refund is accepted    - id: after-30-days-is-refused      statement: |        Given an order delivered 31 days ago        When the customer asks for a refund        Then the shop refuses it with E3001    - id: gift-card-as-store-credit      statement: |        Given an order paid with a gift card        When the customer gets a refund        Then the money comes back as store creditlineage:  owner:    team: checkout  created_at: "2026-11-22"

Save the back office's rule as apps/admin/docs/facets/features/orders/refunds/refund-order.yaml:

yaml
schema_version: "0.1"id: orders/refunds/refund-orderlifecycle: activeintent:  summary: Support staff refund an order at any time, with a reason, up to the amount the customer paid.contract:  scenarios:    - id: late-refund-with-reason      statement: |        Given an order delivered 45 days ago        When a staff member refunds it and gives a reason        Then the refund is recorded with the reason and the staff member's name    - id: reason-is-required      statement: |        Given any order        When a staff member refunds it without a reason        Then no refund is recorded    - id: never-more-than-paid      statement: |        Given an order with refunds that already add up to the amount paid        When a staff member refunds any further amount        Then no refund is recordedlineage:  owner:    team: support-tools  created_at: "2026-11-22"

Add what the back office does not have yet as a planned record, apps/admin/docs/facets/features/checkout/discounts/create-code.yaml:

yaml
schema_version: "0.1"id: checkout/discounts/create-codelifecycle: plannedintent:  summary: Marketing staff create a discount code with a value, a last day and an optional minimum order value.contract:  scenarios:    - id: code-names-are-unique      statement: |        Given a discount code SPRING5 exists        When a staff member creates another code named spring5        Then the back office refuses itlineage:  owner:    team: support-tools  created_at: "2026-11-22"

Anchor each product's code to its record. In src/orders/refund.ts, directly above export function requestRefund, and in apps/admin/src/refunds.ts, directly above the comment of staffRefund, add:

ts
// @facet: orders/refunds/refund-order// @facet-role: primary

The comment is identical in both files. Which record it belongs to follows from the folder: src/ is the shop's, apps/admin/ is the back office's.

Step 4See both products side by side

sh
  • npx facet registries
Terminal output of npx facet registries: a table with the columns FEATURE, admin and shop. checkout/discounts/create-code is planned in admin and missing in shop; checkout/discounts/redeem-code is missing in admin and active in shop; orders/refunds/refund-order is active in both. Summary: 3 features across 2 registries, 1 documented by more than one.Terminal output of npx facet registries: a table with the columns FEATURE, admin and shop. checkout/discounts/create-code is planned in admin and missing in shop; checkout/discounts/redeem-code is missing in admin and active in shop; orders/refunds/refund-order is active in both. Summary: 3 features across 2 registries, 1 documented by more than one.
One row per feature, one column per product.

The refund row says both products have the feature, each with its own record and its own rule. npx facet registries --gaps shows only the rows where a product is missing a feature.

Check both registries:

sh
  • npx facet lint

The summary reads 4 record(s), 3 anchor(s) checked across 2 registries (admin, shop) — 0 error(s). Every message in the output starts with the registry it belongs to, [shop] or [admin].

Commit the setup:

sh
  • git add .facetrc.yaml docs apps src
  • git commit -m "Describe the shop and the back office in two registries"

Step 5Ask which product a change touches, before you commit

Back to the support request. Change the constant the search found, in src/orders/refund.ts:

ts
export const REFUND_WINDOW_DAYS = 45;

Then ask FACET which records your uncommitted change touches:

sh
  • npx facet drift
Terminal output of npx facet drift: baseline HEAD; drift: shop:orders/refunds/refund-order, changed: src/orders/refund.ts; 1 drifted anchor.Terminal output of npx facet drift: baseline HEAD; drift: shop:orders/refunds/refund-order, changed: src/orders/refund.ts; 1 drifted anchor.
The change touches the shop's refund rule, not the back office's.

shop:orders/refunds/refund-order is the answer: this edit changes what customers get, and the shop's record still says 30 days. The support request was about the back office. Undo the change:

sh
  • git checkout src/orders/refund.ts

Make the change in apps/admin/src/refunds.ts instead and run npx facet drift again. It reports admin:orders/refunds/refund-order. Update that record's ScenarioA scenario is one behaviour a feature promises, written in a record as Given/When/Then steps. Each scenario has an id that tests and other records can refer to.Read more here in the same commit. facet drift reports and never fails a run, so it fits before every commit and into review.

Step 6Let the check catch code that claims the other product's feature

Code gets copied between apps. Say someone builds discount-code management in the back office and copies the shop's expiry check into apps/admin/src/codes.ts, AnchorAn anchor is a comment in the source code, starting with @facet:, that names the record the code belongs to. FACET reads these comments to know where each feature is implemented.In the glossary included:

ts
// @facet: checkout/discounts/redeem-code// The expiry day ends in UTC for every customer.export function isExpired(expiresOn: string, now: Date): boolean {  return now.getTime() > Date.parse(`${expiresOn}T23:59:59.999Z`);}

Check the back office alone:

sh
  • npx facet lint --registry admin
Terminal output of npx facet lint --registry admin: an error in apps/admin/src/codes.ts says the tag references checkout/discounts/redeem-code, which has no record; another registry has this feature, but this code belongs to admin alone. Summary: 1 error, 2 warnings.Terminal output of npx facet lint --registry admin: an error in apps/admin/src/codes.ts says the tag references checkout/discounts/redeem-code, which has no record; another registry has this feature, but this code belongs to admin alone. Summary: 1 error, 2 warnings.
The shop has this feature, the back office does not: an error.

The shop has a record with that id, but apps/admin/ belongs to the back office alone. The error offers both fixes: give the back office its own record for the feature, or move the code into a folder both registries list in sources. Here the right id is the planned checkout/discounts/create-code; change the anchor to it, or remove it until the feature is built.

Step 7If the check says something else

  • registry "admin" points at "apps/admin/docs/facets", which does not exist: create the records folder from step 2, or fix the path under records.
  • declares both top-level records/schema/sources/runners and a registries block: move the top-level records: line into one of the registries. A file with registries has no top-level layout.
  • registry name "Admin" must be lowercase letters, digits and hyphens: registry names appear in front of ids, as in admin:orders/refunds/refund-order. Use lower case.
  • @facet: tag names registry "backoffice", which is not declared: an anchor uses a prefix that .facetrc.yaml does not declare. Use a declared name, or the bare id.
  • no schema directory at apps/admin/docs/facets/schema — schema validation skipped: add schema: docs/facets/schema to that registry.

For more on keeping teams that share a repository from breaking each other's features, read Your release was green. Ours is broken now.

Sources