> ## Documentation Index
> Fetch the complete documentation index at: https://docs.lexq.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Domain Templates

> Jump-start with curated fact catalogs and sample rules for your industry. Apply a template to create a ready-to-publish policy group in seconds.

## What is a Domain Template?

A **Domain Template** is a curated bundle of fact definitions and sample rules tailored to a specific industry. Applying a template creates:

* A pre-defined set of facts (e.g., `purchase_subtotal_usd`, `loyalty_tier`) registered for your tenant.
* A new policy group with sample rules, ready to publish or customize.
* An entry in your group list — same as if you had built it manually.

Use templates to skip the blank-page problem when starting a new policy domain.

<Tip>
  Templates are **opt-in**. They only run when you click **Apply** in the Console or call the `apply` endpoint. Your existing facts and policy groups are never modified.
</Tip>

## Available Templates

<CardGroup cols={1}>
  <Card title="E-Commerce" icon="cart-shopping">
    Loyalty tier discounts, first-purchase bonus, free shipping for high-LTV customers, and promo code handling for online retail.

    **8 facts** · **5 sample rules**
  </Card>
</CardGroup>

More templates (Fintech, SaaS) are coming soon.

## E-Commerce Template

### Facts (8)

| Key                     | Type         | Required | Description                                   |
| ----------------------- | ------------ | :------: | --------------------------------------------- |
| `purchase_subtotal_usd` | NUMBER       |     ✅    | Cart subtotal before discounts, in USD        |
| `purchase_currency`     | STRING       |          | ISO 4217 currency code (e.g., USD, EUR, KRW)  |
| `cart_category_tags`    | LIST\_STRING |          | Category tags of items in the cart            |
| `customer_ltv_usd`      | NUMBER       |          | Customer lifetime value, in USD               |
| `loyalty_tier`          | STRING       |          | PLATINUM / GOLD / SILVER / BRONZE / NONE      |
| `applied_promo_code`    | STRING       |          | Promotion code entered at checkout            |
| `is_first_purchase`     | BOOLEAN      |          | Whether this is the customer's first purchase |
| `loyalty_credit_usd`    | NUMBER       |          | Redeemable store credit balance, in USD       |

### Sample Rules (5)

| Priority | Name                    | Trigger                                        | Effect                                   |
| -------: | ----------------------- | ---------------------------------------------- | ---------------------------------------- |
|        1 | Platinum Tier — 20% Off | `loyalty_tier=PLATINUM` and subtotal ≥ USD 100 | 20% off subtotal (mutex: `vip_discount`) |
|        2 | Gold Tier — 15% Off     | `loyalty_tier=GOLD` and subtotal ≥ USD 100     | 15% off subtotal (mutex: `vip_discount`) |
|        3 | Silver Tier — 10% Off   | `loyalty_tier=SILVER` and subtotal ≥ USD 100   | 10% off subtotal (mutex: `vip_discount`) |
|        4 | First-Purchase Bonus    | `is_first_purchase=true`                       | USD 10 off subtotal                      |
|        5 | High-LTV Free Shipping  | `customer_ltv_usd ≥ 1000`                      | Add tag `free_shipping`                  |

The three tier discount rules share a mutex group (`vip_discount`) with `EXCLUSIVE / HIGHEST_PRIORITY` — only the highest-priority matching rule fires. First-purchase bonus and free shipping run independently.

## Applying a Template

1. Go to **Settings → Domain Templates**.
2. Click **Preview** on a template card to inspect the facts and rules before committing.
3. Click **Apply** to create the policy group.
4. Optionally provide a custom group name. If left blank, a default name is generated (with a date suffix if the name already exists).

After apply, you're navigated to the new policy group where you can edit rules, set effective dates, and publish.

## What Happens on Apply

| Resource            | Behavior                                                                                                 |
| ------------------- | -------------------------------------------------------------------------------------------------------- |
| Facts               | Created **only if missing**. Existing facts with the same key are kept as-is (your edits are preserved). |
| Policy Group        | New group, `status=ACTIVE`.                                                                              |
| Policy Version      | New version, `status=DRAFT`. Edit rules before publishing.                                               |
| Rules               | All 5 sample rules created.                                                                              |
| Application history | Recorded for audit.                                                                                      |

The entire operation is transactional — if any step fails, nothing is created.

<Warning>
  The created policy version starts as `DRAFT`. To make it live, publish it from the policy group page or via the deployment API.
</Warning>

## Customizing After Apply

Templates are starting points. After applying, you can freely:

* Edit any rule (condition, action, priority, mutex).
* Add or remove rules in the version.
* Delete facts you don't need (they're regular custom facts, not protected).
* Rename the policy group.
* Adjust the version's effective dates before publishing.

## FAQ

**Can I apply the same template twice?**

Yes. Each apply creates a new policy group. Existing facts are reused (not duplicated). If the default group name is taken, a date suffix is appended automatically.

**Can I delete a template's facts later?**

Yes. Template-applied facts are regular tenant facts — no special protection. Be aware that deleting a fact in use will cause rules referencing it to evaluate that condition as `false`.

**Can I roll back an apply?**

Not as a single operation. To undo, archive the policy group manually (or delete the version) and delete the facts you don't need. The application history record remains for audit.

## Next Steps

<CardGroup cols={2}>
  <Card title="Policy Groups" icon="layer-group" href="/guides/policy-groups">
    Learn how policy groups and versions work.
  </Card>

  <Card title="Fact Definitions" icon="database" href="/guides/fact-definitions">
    Understand the fact model in depth.
  </Card>
</CardGroup>
