> For the complete documentation index, see [llms.txt](https://refkit.gitbook.io/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://refkit.gitbook.io/docs/getting-started/how-refkit-works.md).

# How RefKit works

RefKit provides the tracking and ledger infrastructure behind a SaaS affiliate Program. Your App keeps its customer and billing flow. RefKit connects an affiliate link to the Customer, their payments, and the Affiliate's commission.

## The flow

1. An affiliate shares a first-party link such as `https://yourapp.com?via=alex`.
2. Your backend sends `via` to `POST /v1/capture` and stores the returned `click_id`.
3. When the customer signs up, your backend sends the `click_id` to `POST /v1/identify`.
4. RefKit creates the Customer and Referral.
5. Stripe sends payment events to RefKit, or your backend reports them through the API.
6. RefKit creates commissions. The developer pays the affiliate outside RefKit and marks the payout paid.

## Core rules

* Attribution uses the last valid click before the first Referral is created.
* The attribution window is 30 days.
* A Customer can have one Affiliate per Program and is not reattributed later.
* Test activity is isolated from live metrics and is never payable.
* Each App uses one revenue source: Stripe or provider-neutral API reporting for payments, refunds, and disputes.
* Refunds create reversing commission entries. Existing money records are not edited.

## Main entities

| Entity     | Meaning                                                    |
| ---------- | ---------------------------------------------------------- |
| App        | The software product using RefKit                          |
| Program    | Its affiliate offer, terms, links, and payout settings     |
| Affiliate  | A person, company, tool, or agent promoting the App        |
| Click      | A visit recorded from an affiliate link                    |
| Referral   | The attribution between a Customer, Program, and Affiliate |
| Commission | The amount earned from an attributed payment               |
| Payout     | A payment the developer made to an Affiliate               |
