A new colleague asks in the team chat what happens when a customer enters a discount code that expired yesterday. The backend developer says the shop refuses it. Support says it still works until midnight. The product manager remembers a grace period from a planning meeting. All three are sure, and none of them can point to where it is written down.
FACET is a command-line tool that keeps a short, checkable description of each feature 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 that answer is written down once, next to the code: a FACET record, a small YAML file with plain GherkinGherkin is a widely used format for describing behaviour as Given/When/Then steps. FACET writes a record's scenarios in this style.Read more here 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 a comment in the source, called an 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, that connects the two. facet lint then checks on your machine and in every pull request that the record and the code still point at each other.
The commands below use the shop from the FACET examples. Copy it into a project of its own:
git clone --depth 1 https://github.com/facet-framework/examples.gitcp -r examples/shop shop && cd shopgit init && git add -A && git commit -m "Example shop"
Branch guide/write-down-what-a-feature-does holds the result. In your own project, pick one feature that people describe differently and use its files instead.
Step 1Add FACET to the project
FACET is a command-line tool distributed through npm. Install the release candidate as a development dependency in the root of your project, so everyone on the team gets the same version from the lockfile:
npm install --save-dev facet-framework
Check that the project's copy runs:
npx facet version
The first line starts with facet core. If npm instead asks to install a package called facet, you are in a directory without the dependency from the first command. Answer no, then change into the project root.
Step 2Create the record layout
Preview what FACET will add. Nothing is written yet:
npx facet init -n
Then create the files:
npx facet init
=== Done — 22 file(s) written, 0 kept ===Still to do (these need judgement, not copying):
init keeps every file the project already has, so running it twice is safe. It leaves two things to you: the first record, which is the rest of this guide, and .facetignore, which lists what the anchor scan never needs to open. Add the LintLint is FACET's check that records and code still point at each other: every record matches its schema, every anchor names an existing record, and every active record has an anchor. It runs locally and in CI on every pull request.In the glossary suite that init just wrote, so its own self-test is not reported as a test file without a record:
printf 'tools/facet-lint/\n' >> .facetignore
Add media, fonts and build output of your project the same way, one pattern per line, as in .gitignore.
Step 3Find out what the code really does
Before writing anything down, read the code that decides. In the example shop it is src/checkout/discount.ts:
// The expiry day ends in UTC for every customer. Comparing against local// midnight made codes expire a day early west of UTC (fixed in 2026-08).function isExpired(code: DiscountCode, now: Date): boolean { return now.getTime() > Date.parse(`${code.expiresOn}T23:59:59.999Z`);}
So all three were partly right. The shop refuses an expired code with error E2002. The last day counts until 23:59:59 UTC, not until local midnight. There is no grace period.
Write down what the code does today. If the team wants different behaviour, change the code and the record together, in one pull request.
Step 4Write the answer down as a record
A record is a YAML file under docs/facets/features/. Its path follows its id, which has three parts: DomainA domain is the first part of a feature id: a product area such as checkout, never a team or a service.In the glossary, capability, feature. Create the folder:
mkdir -p docs/facets/features/checkout/discounts
Save this as docs/facets/features/checkout/discounts/redeem-code.yaml:
schema_version: "0.1"id: checkout/discounts/redeem-codelifecycle: activeintent: summary: A customer enters a discount code in the cart and gets its discount, or a reason why not.contract: scenarios: - id: expired-code-is-refused statement: | Given the code SPRING5, whose last day is 2026-05-31 When a customer redeems it after 23:59:59 UTC on that day Then the shop refuses it with E2002 and the cart keeps its price - id: last-day-ends-in-utc statement: | Given a code whose last day is today When a customer redeems it at 23:30 UTC, in any time zone Then the discount is applied - id: minimum-order-value statement: | Given a code with a minimum order value When the cart subtotal is below that value Then the shop refuses the code with E2003 - id: one-code-per-order statement: | Given a cart that already has a code When the customer enters a second code Then the shop refuses it with E2004verification: unit_tests: - id: tests/discount.test.ts proves: [expired-code-is-refused, last-day-ends-in-utc, minimum-order-value, one-code-per-order]lineage: owner: team: checkout created_at: "2026-11-22"
lifecycle: activesays the feature exists in the code today. FACET then expects to find that code.contract.scenariosare the answers to the colleague's question, one case each, in words that support and product can read.verificationnames the test file that checks these cases. List a scenario underprovesonly after reading the test body: FACET checks that the scenario ids exist, not what the test does.lineagesays which team answers questions about the feature and since when the record exists. Use today's date.
Step 5Let the check find the missing link
Run the check:
npx facet lint
error: docs/facets/features/checkout/discounts/redeem-code.yaml: active record "checkout/discounts/redeem-code" has no @facet: anchor in sourcewarning: tests: 2 test file(s) in tests are named by no record: invoice.test.ts, refund.test.ts1 record(s), 0 anchor(s) checked — 1 error(s), 1 warning(s) (unclaimed-tests 1)
The error is expected. The record says the feature is active, and no source file claims to implement it yet. The command exits with status 1, which is what fails a pull request later.
Step 6Connect the record to the code
In src/checkout/discount.ts, add two comment lines directly above redeemDiscountCode, the function that redeems a code:
// @facet: checkout/discounts/redeem-code// @facet-role: primary/** Redeems a code on a cart. Returns the new cart; throws a ShopError and leaves the cart unchanged otherwise. */export function redeemDiscountCode(cart: Cart, input: string, now = new Date()): Cart {
@facet: names the record. @facet-role: primary marks this as the main place the feature lives; other files can carry the same id without that line. Run the check again:
npx facet lint
1 record(s), 1 anchor(s) checked — 0 error(s), 1 warning(s) (unclaimed-tests 1)The remaining warning lists test files that no record claims yet. Warnings never fail the check. Each of those files is a candidate for the next record.
Step 7Commit it and let every pull request check it
Commit the record, the anchor and what init wrote:
git add .facetignore .github docs tools package.json package-lock.json src/checkout/discount.tsgit commit -m "Describe discount-code redemption in a FACET record"
init also wrote .github/workflows/facet-lint.yml. On GitHub it runs facet lint on every pull request, with the FACET version pinned in tools/facet-lint/facet. If someone renames the function's file and drops the comment, or deletes the record, that pull request fails with the same error you saw in step 5.
Next time the question comes up in the chat, the answer is a link to docs/facets/features/checkout/discounts/redeem-code.yaml.
Step 8If the check says something else
@facet: tag references "…", which has no record: the id in the comment and theid:in the record differ. Copy the id from the record into the comment.has no @facet: anchor in source, although you added the comment: check that the file is not excluded by a pattern in.facetignoreor.gitignore. FACET does not scan ignored files.lineage: missing property 'created_at', or another field name: the record does not match the schemainitwrote todocs/facets/schema/. Compare it with the example in step 4.is anchored to …, which is reachable only from tests: the anchored function is called only from test files. Put the anchor on the code the product actually runs, or setlifecycle: plannedwhile the feature is still being built.- npm asks to install
facet: run the command from the project root, where step 1 installedfacet-framework.
For more on why teams keep feature behaviour next to the code, read “It’s done.” Does it do what we wanted?.