---
phase: rules
kind: level
level: link
---

# Level 3 — LINK

> Connect each elaborated rule to the **use cases** that reference it, via the
> `## Cas d'usage liés` line. The link names the UC code, the stage, and
> optionally the step. After this level the rule set is complete: a vibecoder
> can pull a UC + its linked rules + the rules' examples and generate the full
> implementation in one shot. Persist by re-Writing the scope's
> `règles-métier.md` (see `SKILL.md`).

## Why linking matters
A use case says **what** the actor wants; a rule says **what constraint** holds;
the link says **where** in the workflow the constraint kicks in — so code
generation knows "at step 3 of UC-…, enforce BR-001", and end-to-end tests can be
generated (UC scenario + rule failure path).

## Stage values

| Stage | When the rule fires |
|-------|---------------------|
| `precondition` | BEFORE the main flow. If it fails, the UC cannot start. |
| `mainflow` | DURING the main flow, at a specific step. Failure aborts that step. |
| `postcondition` | AFTER the main flow. Verifies the resulting state is consistent. |
| `exception` | Triggered by an exception flow rather than the main flow. |

Default to `precondition` for validations, `mainflow` for calculations / state
transitions. Provide the **step number** for `mainflow` whenever you can (it
pinpoints the generated code); leave it off for `precondition`/`postcondition`.

## Workflow
For each rule:
1. Read its `Condition` + description.
2. **Grep the scope's `use-case.md`** for UCs that touch the same entity, field
   or actor concern. (Rules derived from a UC at Level 1 already hint at their UC.)
3. For each match, decide the stage (+ step) and add it to `## Cas d'usage liés`.

A rule can link to **multiple UCs**; a UC can have **multiple rules**. Use the
cross-reference freely. Reference each UC by its exact `UC-…` code copied verbatim
from `use-case.md` — never invent or recompose a code.

Doc form:

```markdown
- **Cas d'usage liés** : UC-CRM-PIPELINE-OPPORTUNITES-001 (précondition) ;
  UC-CRM-PIPELINE-OPPORTUNITES-014 (mainflow, étape 3)
```

## Rules without UC links — perfectly valid
An empty `## Cas d'usage liés` (write `—`) is **not** a defect — it reflects the
BABOK principle that rules exist independently of use cases. Legitimately
unlinked: application-level rules ("all modules comply with GDPR"), module-level
access rules ("access to Recruitment requires the HR role"), data validation
("email unique"), integrity ("no reference to a soft-deleted customer"), domain
constraints ("stock ≥ 0"), policies ("personal data anonymisable"), and
cross-cutting concerns ("all mutations logged"). Application/module-level rules
having 0 links is the **expected default** — never force-link to remove an
"unlinked" indicator.

When a rule genuinely applies to ALL UCs touching an entity, prefer linking the
2–3 most representative UCs and noting "s'applique à tout le CRUD de {entité}" in
the rule's wording, rather than enumerating every UC. Cross-cutting rules: link
0–3 representative UCs at `mainflow`/`postcondition`, document the breadth in the
description.

## Ask the user only when ambiguous
Most links infer from context. Ask (one AskUserQuestion, 2–4 closed options) only
when two UCs equally fit and only one should win, when a `mainflow` step is
ambiguous, or when a rule has no obvious UC and you must decide between "stays
unlinked" and "link to UC-… as a postcondition".

## After linking
Re-Write the scope's `règles-métier.md` with the **complete** rule set including
`## Cas d'usage liés` (the overwrite replaces the file, so re-list every rule that
must survive). Then summarise to the user (N rules, M UC links) and hand off to
`/ba-create-rbac` per the fixed order.

## Quality checks before writing
For every rule: `## Cas d'usage liés` is present (may be `—`); each link
references a `UC-…` code that exists in `use-case.md`; the stage is one of the
four allowed values; step numbers are set for `mainflow` where possible and
omitted for pre/postconditions; no duplicate (UC, stage, step) on the same rule.
