# Protocol Architecture 📊

HFDX follows a modular design with separation-of-concerns, ensuring each protocol component is auditable, maintainable, and upgradable without compromising system integrity.

**Core components:**

| Component          | Function                                         |
| ------------------ | ------------------------------------------------ |
| User Wallet        | Asset custody, transaction signing               |
| HFDX Router        | Centralized execution gateway for all trades     |
| Margin Engine      | Risk, leverage, and margin computation           |
| Liquidity Pool     | Capital provisioning and loss absorption         |
| Funding Module     | Funding rate computation and periodic settlement |
| Oracle System      | Provides external price indices                  |
| Liquidation Module | Force closes positions under margin breach       |
| LLN Manager        | Lifecycle management of Liquidity Loan Notes     |

**System Architecture Flow:**

```
                    ┌─────────────┐
                    │ User Wallet │
                    └──────┬──────┘
                           │
                           ▼
                    ┌─────────────┐
                    │   Router    │
                    └──────┬──────┘
                           │
            ┌──────────────┴──────────────┐
            │                             │
            ▼                             ▼
    ┌───────────────┐            ┌─────────────┐
    │ Margin Engine │            │ LLN Manager │
    └───────┬───────┘            └──────┬──────┘
            │                           │
            ▼                           ▼
    ┌───────────────────────────────────────────┐
    │          Liquidity Pool                   │
    │              ◄──────►                     │
    │          Funding Module                   │
    └───────────────────┬───────────────────────┘
                        │
                        ▼
              ┌──────────────────┐
              │ Liquidation Module│
              └──────────────────┘
```

This architecture ensures clear separation between:

* **User interaction** — Router & Wallet
* **Risk calculation and margin enforcement** — Margin Engine
* **Capital management** — Liquidity Pool & LLN Manager
* **External data integration** — Oracle System
* **Position resolution** — Liquidation Module

The modularity allows for incremental upgrades while preserving immutable core logic.
