# Document where your web and iOS apps behave differently, with FACET

> Describe one feature once for every app that has it, mark where an app behaves differently, and let a check confirm that each app the record names really has code for it.

Source: https://facet-framework.com/en/guides/web-and-ios-do-it-differently/  
Last updated: 2026-11-25T20:26:42+01:00

A customer writes to support: the discount code worked in the iPhone app at ten in the evening, on its last day, but the web shop refused it at the same moment. Support asks the web team, who say the code expires at the end of its last day in UTC, fixed in August. The iOS team says the code expires at midnight, as it always has. Both teams are right about their own app, and nobody wrote down that the two differ.

FACET keeps a short, checkable description of each feature, called a record, next to your code and tells you when code and description drift apart. By the end of this guide one record describes discount codes for both apps, says where they behave differently, and marks the iOS behaviour as a known deviation. `facet lint` then checks that each app the record names really has code for the feature. The FACET feature behind it is variants: one record, its own lifecycle state per app, such as active or planned, and scenarios that apply to only one of them.

The commands below use a small example shop written in TypeScript, set up as in [“One answer instead of three”](https://facet-framework.com/en/guides/write-down-what-a-feature-does/). Its repository also holds an iPhone app in `ios/`. In your own project, use the folders of your clients, or of an old system and its rewrite.

## Find the difference in the code

Put the two places next to each other. The web shop:

```sh
grep -n -A2 'expiresOn}T23' src/checkout/discount.ts
```

```console
$ grep -n -A2 'expiresOn}T23' src/checkout/discount.ts
20:  return now.getTime() > Date.parse(`${code.expiresOn}T23:59:59.999Z`);
21-}
22-
```

The iPhone app:

```sh
grep -n 'midnight\|timeZone\|endOfLastDay' ios/Shop/Checkout/DiscountCode.swift
```

```console
$ grep -n 'midnight\|timeZone\|endOfLastDay' ios/Shop/Checkout/DiscountCode.swift
18:    // The last day ends at midnight on the phone's own clock.
21:    formatter.timeZone = .current
23:          let endOfLastDay = Calendar.current.date(byAdding: .day, value: 1, to: lastDay) else { throw RedeemError.expired }
24:    if now >= endOfLastDay { throw RedeemError.expired }
```

The web shop ends the last day at 23:59:59 UTC. The app ends it at midnight in the phone's time zone. For a customer in New York that is four or five hours later. Same feature, same intent, different rule.

## Tell FACET which folder is which app

Save this as `docs/facets/variants.yaml`:

```yaml
schema_version: "0.1"
variants:
  web:
    paths: ["src/**"]
    description: The web shop and its API.
  ios:
    paths: ["ios/**"]
    description: The iPhone app.
```

Each variant is a place where a feature can exist or not exist. `paths` decides which files belong to it. Code that several apps share goes under a `shared:` block with its own `paths`; the example has none.

Run the check:

```sh
npx facet lint
```

Nothing changes yet: `0 error(s)`. The record still has a single `lifecycle`, and the only anchor sits in `src/`.

## Describe the feature once, for both apps

A second record for the iPhone app would copy the intent and every scenario, and the two copies would drift apart. Instead, change the existing record `docs/facets/features/checkout/discounts/redeem-code.yaml`:

```yaml
schema_version: "0.1"
id: checkout/discounts/redeem-code
variants:
  web:
    lifecycle: active
  ios:
    lifecycle: active
intent:
  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
      variants: [web]
      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
      variants: [web]
      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: last-day-ends-at-local-midnight
      variants: [ios]
      statement: |
        Given a code whose last day is 2026-05-31
        When a customer in New York redeems it in the app at 22:00 local time on that day
        Then the app applies the discount, although it is already 02:00 UTC on 2026-06-01
      deviation:
        reason: ios/Shop/Checkout/DiscountCode.swift ends the last day at midnight in the phone's time zone; the web shop ends it at 23:59:59 UTC since the fix of 2026-08.
        confirmed_by: code-review
        tracked_as: null
    - id: minimum-order-value
      variants: [web]
      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
      variants: [web]
      statement: |
        Given a cart that already has a code
        When the customer enters a second code
        Then the shop refuses it with E2004
verification:
  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"
```

- **`variants`** replaces `lifecycle`: the feature is `active` in both apps. A record has one or the other, never both. An app that does not have the feature is left out.
- **`variants: [web]`** on a scenario says it holds only in the web shop. A scenario without it holds in every app the feature exists in.
- **`deviation`** marks the iOS scenario as behaviour nobody intends, with the evidence. The scenario says what the app does today, so nobody mistakes it for the rule. Set `tracked_as` to the ticket once one exists.

## Let the check ask for the iOS code

```sh
npx facet lint
```

![Terminal output of npx facet lint: an error says checkout/discounts/redeem-code is active on ios with no anchor there, anchor the implementing file under an ios path or set that variant's lifecycle to planned; summary: 1 error, 2 warnings.](https://facet-framework.com/guides/web-and-ios-do-it-differently/lint-ios-unanchored-light.png)

*The record says the iPhone app has the feature; the check wants to see where.*

The anchor in `src/` proves the web shop has the feature. It proves nothing about the app. Add the anchor to the Swift file, directly above the function's comment in `ios/Shop/Checkout/DiscountCode.swift`:

```swift
// @facet: checkout/discounts/redeem-code
// @facet-role: primary
/// Checks a code in the app before the cart is sent, so the customer sees the
/// discount without a round trip.
func redeemDiscountCode(_ input: String, from codes: [DiscountCode], now: Date = Date()) throws -> DiscountCode {
```

The comment is the same in every language that uses `//`. FACET knows which app the file belongs to from its path, not from the comment.

## Check both apps and commit

```sh
npx facet lint
```

![Terminal output of npx facet lint: 1 record and 2 anchors checked, 0 errors; warnings say the scenario last-day-ends-at-local-midnight has no verification proof and two test files, invoice.test.ts and refund.test.ts, are named by no record.](https://facet-framework.com/guides/web-and-ios-do-it-differently/lint-both-variants-light.png)

*One record, two anchors, one in each app: 0 errors.*

The warning about `last-day-ends-at-local-midnight` is honest: no test checks the iOS behaviour yet. Commit the map, the record and the anchor:

```sh
git add docs/facets/variants.yaml docs/facets/features/checkout/discounts/redeem-code.yaml ios/Shop/Checkout/DiscountCode.swift
git commit -m "Describe discount codes on web and iOS, with the iOS difference"
```

The next time support asks why the app accepted a code, the answer is one scenario in one file. When the iOS team aligns the app with the web shop, they remove `variants: [web]` from `last-day-ends-in-utc` and delete the deviation scenario in the same pull request.

> **What this does not do**
>
> FACET does not compare the Swift code with the TypeScript code. You find a difference like this one by reading both;
> the record keeps it written down, and `facet lint` checks only that each app the record names has anchored code. If an
> app changes its behaviour without touching the record, lint stays green; `facet drift` lists the change for review.

## If the check says something else

- **`anchored file belongs to no declared variant and no shared path`:** a new folder carries an anchor, for example a new Android app. Add it to `variants.yaml` as its own variant, or under `shared:` if several apps use it.
- **`record declares variant "iphone", which is not in the variant map`:** the record uses a name that `variants.yaml` does not declare. Use the names from the map exactly.
- **`is anchored on variant "ios", which the record does not declare`:** an app has code for the feature, but the record does not list that app. Add it under `variants` with its lifecycle.
- **`(document root): 'not' failed`:** the record has both `lifecycle` and `variants`. Delete the top-level `lifecycle` line.
- **`is active on "ios" with no anchor there`:** no file under an `ios` path carries the anchor. Put it in code only that app has, or set that variant to `planned` while the app does not have the feature yet.

For more on teams that build the same product in different places, read [Your release was green. Ours is broken now.](https://facet-framework.com/en/solutions/distributed-teams/)

### Sources

- [FACET variants guide](https://github.com/facet-framework/core/blob/main/docs/VARIANTS-GUIDE.md)
- [FACET specification: deviation (§3.2.2)](https://github.com/facet-framework/core/blob/main/docs/framework/FACET.md#322-deviation)
- [Where each language puts its `@facet:` anchor](https://github.com/facet-framework/core/blob/main/docs/ANCHOR-GUIDE.md)
