Facet
DeutschInstall
Team & product

Check with FACET whether your features are cut too fine or too coarse

Measure the shape of your 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 with one command, split a record that has grown into a whole area, and check that the split dropped nothing the old record said.

  • 11 min read
  • 6 steps
  • npmGit
  • Your coding agent

One team describes every button as its own feature and has hundreds of tiny entries nobody reads. Another team has one entry called "cart and checkout" with thirteen cases, and every change touches it. Both say they describe the product. Neither can say whether their way is the right one, and each single entry looks fine on its own.

FACET keeps a short, checkable description of each feature, called a record, next to your code and tells you when code and description DriftDrift is when code changes and the record describing it does not follow, so the two no longer match. facet drift lists the features whose anchored code changed since a chosen baseline.In the glossary apart. By the end of this guide you can measure how your product is cut into features with npx facet calibrate, split a record that has grown into a whole area, and check with npx facet split --check that the split lost nothing the old record said.

The commands below use the example shop from “One answer instead of three”. In your own project, run step 2 first and pick the record the measurement points at.

Step 1Start from one record that covers too much

In the example shop, a colleague described cart, shipping and ordering in one record. Recreate it. Create the folder:

sh
  • mkdir -p docs/facets/features/checkout/cart

Save this as docs/facets/features/checkout/cart/cart-and-checkout.yaml:

yaml
schema_version: "0.1"id: checkout/cart/cart-and-checkoutlifecycle: activeintent:  summary: A customer fills a cart, sees the total with shipping and places the order.contract:  scenarios:    - id: subtotal-in-cents      statement: |        Given two mugs at 12.90 EUR and a tea sampler at 24.50 EUR        When the customer looks at the cart        Then the subtotal is 50.30 EUR    - id: same-product-one-line      statement: |        Given a cart with one mug        When the customer adds another mug        Then the cart has one line with quantity 2    - id: zero-quantity-refused      statement: |        Given any cart        When the customer adds a product with quantity 0        Then the cart refuses it    - id: unknown-product-refused      statement: |        Given any cart        When a product id the catalogue does not know is added        Then the cart refuses it    - id: free-shipping-from-50      statement: |        Given a cart worth 59.00 EUR after discounts        When the customer places the order        Then shipping is free    - id: shipping-below-50      statement: |        Given a cart worth 12.90 EUR        When the customer places the order        Then shipping costs 4.90 EUR    - id: discount-counts-before-free-shipping      statement: |        Given a cart worth 52.00 EUR and a discount of 5.00 EUR        When the customer places the order        Then shipping costs 4.90 EUR, because 47.00 EUR is below the threshold    - id: legacy-checkout-always-charges-shipping      statement: |        Given the flag new_checkout_v2 is off        When the customer places an order worth 59.00 EUR        Then shipping costs 4.90 EUR    - id: empty-cart-refused      statement: |        Given an empty cart        When the customer places the order        Then the order is refused    - id: order-total      statement: |        Given a cart with a subtotal, a discount and shipping        When the customer places the order        Then the total is subtotal minus discount plus shipping    - id: order-keeps-payment-method      statement: |        Given a customer paying with a gift card        When the order is placed        Then the order records the gift card as payment method    - id: order-has-no-refunds-yet      statement: |        Given a new order        When it is placed        Then it has no refunds    - id: order-time-is-recorded      statement: |        Given a customer placing an order        When the order is placed        Then the order records the time it was placedverification:  unit_tests:    - id: tests/cart.test.ts      proves: [subtotal-in-cents, same-product-one-line, zero-quantity-refused]    - id: tests/checkout.test.ts      proves: [free-shipping-from-50, shipping-below-50, legacy-checkout-always-charges-shipping, empty-cart-refused]lineage:  owner:    team: checkout  created_at: "2026-11-22"  depends_on:    - checkout/discounts/redeem-code

depends_on says that this feature relies on discount codes: the free-shipping threshold counts after the discount.

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 it in src/checkout/checkout.ts, directly above placeOrder:

ts
// @facet: checkout/cart/cart-and-checkout// @facet-role: primaryexport function placeOrder(cart: Cart, paidWith: PaymentMethod, now = new Date()): Order {

Commit it, as the colleague did:

sh
  • git add docs src
  • git commit -m "Describe cart and checkout in one record"

Step 2Measure how the product is cut

sh
  • npx facet calibrate
Terminal output of npx facet calibrate: 2 records, 17 scenarios; scenarios per record median 8.5, band 2-9, 1 above, marked with an exclamation mark; records per capability median 1, band 2-12, 2 below, marked; capabilities per domain and records per anchored file inside their bands.Terminal output of npx facet calibrate: 2 records, 17 scenarios; scenarios per record median 8.5, band 2-9, 1 above, marked with an exclamation mark; records per capability median 1, band 2-12, 2 below, marked; capabilities per domain and records per anchored file inside their bands.
One record is above the band for 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, and each capability holds a single record.

calibrate looks at the whole list instead of one record. Each line compares a median with a band that usually fits, and ! marks a line with records outside it:

  • scenarios per record, 1 above: one record has more than nine scenarios. Thirteen cases usually means the record describes a whole area, not one feature. Below two, a record is usually a single case of a bigger feature.
  • records per capability, 2 below: each capability holds one record, so the middle level of the ids (cart, discounts) does not group anything yet.

npx facet lint says the same about the single record: declares 13 contract scenarios, as a warning.

Step 3Cut where the scenarios stop referring to each other

Read the thirteen scenarios and look for groups that never mention each other. Here there are three:

  • What is in the cart: subtotal-in-cents, same-product-one-line, zero-quantity-refused, unknown-product-refused
  • What shipping costs: free-shipping-from-50, shipping-below-50, discount-counts-before-free-shipping, legacy-checkout-always-charges-shipping
  • Placing the order: empty-cart-refused, order-total, order-keeps-payment-method, order-has-no-refunds-yet, order-time-is-recorded

Each group becomes a record in the same folder. Move the scenarios unchanged, keep their ids, and move each proves entry with its scenarios. Save the first group as docs/facets/features/checkout/cart/add-items.yaml:

yaml
schema_version: "0.1"id: checkout/cart/add-itemslifecycle: activeintent:  summary: A customer puts products into the cart and sees the subtotal.contract:  scenarios:    - id: subtotal-in-cents      statement: |        Given two mugs at 12.90 EUR and a tea sampler at 24.50 EUR        When the customer looks at the cart        Then the subtotal is 50.30 EUR    - id: same-product-one-line      statement: |        Given a cart with one mug        When the customer adds another mug        Then the cart has one line with quantity 2    - id: zero-quantity-refused      statement: |        Given any cart        When the customer adds a product with quantity 0        Then the cart refuses it    - id: unknown-product-refused      statement: |        Given any cart        When a product id the catalogue does not know is added        Then the cart refuses itverification:  unit_tests:    - id: tests/cart.test.ts      proves: [subtotal-in-cents, same-product-one-line, zero-quantity-refused]lineage:  owner:    team: checkout  created_at: "2026-11-22"

Save the second as shipping-fee.yaml with id: checkout/cart/shipping-fee, the summary "The order pays 4.90 EUR shipping unless it is worth 50 EUR or more after discounts.", the four shipping scenarios and tests/checkout.test.ts proving free-shipping-from-50, shipping-below-50 and legacy-checkout-always-charges-shipping.

Save the third as place-order.yaml with id: checkout/cart/place-order, the summary "A customer turns the cart into an order with its total, payment method and time.", the five ordering scenarios and tests/checkout.test.ts proving empty-cart-refused.

Then remove the old record:

sh
  • git rm docs/facets/features/checkout/cart/cart-and-checkout.yaml

Step 4Check what the split dropped

The old record is gone from your working tree, but still in the last commit. Compare it with the three new ones:

sh
  • npx facet split --check checkout/cart/cart-and-checkout checkout/cart/add-items checkout/cart/shipping-fee checkout/cart/place-order
Terminal output of npx facet split --check: checkout/cart/cart-and-checkout read from HEAD, split into add-items, place-order and shipping-fee; 1 thing the parent carried and no child does: lineage depends_on checkout/discounts/redeem-code.Terminal output of npx facet split --check: checkout/cart/cart-and-checkout read from HEAD, split into add-items, place-order and shipping-fee; 1 thing the parent carried and no child does: lineage depends_on checkout/discounts/redeem-code.
The split dropped the link to discount codes.

The scenarios all arrived, because you moved them. What fell through is the relationship nobody thinks about when copying cases: lineage: depends_on — checkout/discounts/redeem-code. Shipping is the part that relies on the discount, so add it to shipping-fee.yaml. Its lineage block then reads:

yaml
lineage:  owner:    team: checkout  created_at: "2026-11-22"  depends_on:    - checkout/discounts/redeem-code

Run the check again:

sh
  • npx facet split --check checkout/cart/cart-and-checkout checkout/cart/add-items checkout/cart/shipping-fee checkout/cart/place-order
console
  • npx facet split --check checkout/cart/cart-and-checkout checkout/cart/add-items checkout/cart/shipping-fee checkout/cart/place-order
  • checkout/cart/cart-and-checkout (read from HEAD:docs/facets/features/checkout/cart/cart-and-checkout.yaml)
  • split into checkout/cart/add-items, checkout/cart/place-order, checkout/cart/shipping-fee
  • Nothing the parent carried is missing from all of the children.

Step 5Move the anchors and measure again

npx facet lint now reports four errors: the comment in src/checkout/checkout.ts still names checkout/cart/cart-and-checkout, and the three new records have no anchor. Point each record at its code:

  • In src/checkout/checkout.ts, change // @facet: checkout/cart/cart-and-checkout above placeOrder to // @facet: checkout/cart/place-order.
  • In the same file, add // @facet: checkout/cart/shipping-fee and // @facet-role: primary above function shippingFor.
  • In src/checkout/cart.ts, add // @facet: checkout/cart/add-items and // @facet-role: primary above export function addItem.
sh
  • npx facet lint
  • npx facet calibrate

lint ends with 4 record(s), 4 anchor(s) checked — 0 error(s). The measurement looks like this:

Terminal output of npx facet calibrate: 4 records, 17 scenarios; scenarios per record median 4 inside band 2-9; records per capability median 2, band 2-12, 1 below, marked; the other lines inside their bands.Terminal output of npx facet calibrate: 4 records, 17 scenarios; scenarios per record median 4 inside band 2-9; records per capability median 2, band 2-12, 1 below, marked; the other lines inside their bands.
Scenarios per record are inside the band; one capability still holds a single record.

Scenarios per record are inside the band now. records per capability still shows 1 below: discount codes are the only record in their capability. That is fine for a shop this size; it becomes a question once the capability should hold more.

Commit the split in one change, so the history shows where each scenario went:

sh
  • git add docs src
  • git commit -m "Split cart-and-checkout into add-items, shipping-fee and place-order"

Step 6If the check says something else

  • is active with a single contract scenario: the opposite problem. A record with one behaviour is usually a scenario of the record above it. Fold it in, or write the cases it is missing.
  • declares 13 contract scenarios (or another number above twelve): the record describes an area. Split it as in steps 3 to 5.
  • neither HEAD:… nor the working tree has checkout/cart/cart-and-checkout: the split is already committed, so HEAD no longer has the old record. Pass the commit before it, for example --from HEAD~1.
  • @facet: tag references "…", which has no record after the split: a comment in the code still names the old id. Change it to one of the new ids.

For more on keeping a growing product understandable, read Nobody wants to touch the pricing logic. And everyone has to, eventually.

Sources