# Data Model

## Overview
The system's primary building block is **Merchants**, which represent real-world businesses or companies. Transactions occur **between two merchants**, where one merchant sends funds to another. This can be done using either the **Payout API** or the **End-to-End API**.

## Core Entities
### **1. Merchants**
Merchants describe a **business or company** and act as the foundation of the system. Every transaction involves two merchants: the sender and the receiver.

### **2. Payout Accounts**
Each merchant has **Payout Accounts**, which store **bank account details** that allow the system to process payouts to the merchant.

### **3. Transactions**

#### **A. Payout / End-to-End Transactions**
Payout / End-to-End transactions involve the movement of funds **from a source merchant to a target merchant payout account**. The source merchant **deposits funds** (fiat or crypto), and the target merchant **receives the funds** in its payout account.

#### **B. Collections Transactions**
Collections transactions involve the movement of funds **from a target merchant to a source merchant payout account**. It's the opposite of the Payout / End-to-End transactions. The target merchant **deposits funds** (fiat only), and the source merchant **receives the funds** in its payout account.

## Data Model Diagram
Below is a diagram that illustrates the relationships between these entities.

### **A. Payout / End-to-End Transactions**

```mermaid
graph TD;
    MerchantA[Merchant A] -->|Sends Funds| Transaction[Transaction]
    Transaction -->|Received By| MerchantB[Merchant B]
    MerchantB -->|Has| ReceiverAccount[Payout Account]
    Transaction --> Uses{Uses}
    Uses -->|Crypto-to-Fiat| PayoutAPI([Payout API])
    Uses -->|Fiat-to-Fiat| EndToEndAPI([End-to-End API])
```

### **B. Collections Transactions**

```mermaid
graph TD;
    MerchantA[Merchant A] -->|Receives Funds| Transaction[Transaction]
    Transaction -->|Sent By| MerchantB[Merchant B]
    MerchantA -->|Has| ReceiverAccount[Payout Account]
    Transaction --> Uses{Uses}
    Uses -->|Fiat-to-Fiat| CollectionsAPI([Collections API])
```

## Transaction Flow

### **A. Payout / End-to-End Transactions**
1. **Merchant A initiates a transaction**, sending funds via the **Payout API** or **End-to-End API** to **Merchant B Payout Account**.
2. **Funds are deposited** by Merchant A (either fiat or crypto).
3. **Merchant B receives the funds** in its associated **Payout Account**.
4. The transaction is completed successfully.

### **B. Collections Transactions**
1. **Merchant A initiates a transaction**, receiving funds to its **Payout Account** via the **Collections API** from **Merchant B**.
2. **Funds are deposited** by Merchant B (fiat only).
3. **Merchant A receives the funds** in its associated **Payout Account**.
4. The transaction is completed successfully.

## Summary
- **Merchants** represent businesses conducting transactions.
- **Payout Accounts** store payout details for merchants.
- **Transactions** move funds between merchants to a target payout account.
- The **Payout API**, **End-to-End API** and **Collections API** facilitate transactions.



