> For the complete documentation index, see [llms.txt](https://docs.kryptox.finance/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.kryptox.finance/about-kryptox/core-technical-architecture.md).

# Core Technical Architecture

Our system is designed to remove the usual tradeoff between performance and security in traditional DEXs. It gives market makers and high-frequency traders a low-latency order book experience comparable to top centralized exchanges (CEXs), while preserving self-custody and onchain composability.

***

### Architecture principles

KryptoX is built on three core architectural principles:

1. **Onchain settlement and custody for critical assets:** User funds, account ownership through NFTs, final PnL settlement, and fund transfers are all enforced by smart contracts. The backend cannot move funds or alter settlement outcomes unilaterally.
2. **Native DeFi composability:** Thanks to its modular contract design, KryptoX can route idle collateral into leading DeFi lending protocols such as Aave v3 and Compound v3. This improves capital efficiency and leaves room for more yield strategies through standardized integrations.
3. **A hybrid model for matching and risk control:** Compute-heavy tasks such as millisecond-level order matching, real-time mark price calculation, and high-frequency risk scans run in a high-performance engine. Their results are then synced onchain through cryptographic proofs or frequent batch settlement, where smart contracts perform final verification. This design avoids the high slippage, gas cost, and congestion of a fully onchain order book.

***

### System architecture diagram

<figure><img src="/files/BUacFa34sHb4XR0nWgR0" alt=""><figcaption></figcaption></figure>

***

### Core modules

Stable operation depends on tight coordination across three core modules:

#### 1. Smart contract layer

This is the core asset gateway and final settlement layer, deployed on high-performance L2s such as Arbitrum. It uses the EIP-2535 Diamond Pattern to keep contract functions modular and upgradeable.

* **NFT account layer:** Maps user ownership and trading state to onchain NFTs. This module handles account minting, permission checks, and full account transfers.
* **Vault:** A fully decentralized smart contract vault that receives, locks, and releases user collateral.
* **Onchain state and calculation modules:** Includes position management, interest calculation, and related logic. These modules maintain an immutable ledger and strictly verify margin health whenever a settlement instruction arrives.
* **External DeFi protocol gateway:** Routes idle collateral to protocols such as Aave and Compound under a defined safety policy, including buffer management, and settles yield in real time.
* **Governance and token distribution engine:** Records reward snapshots for $KFC holders and distributes 100% of protocol fee revenue in USDC to token holders.

#### 2. Backend trading system layer

This is the KryptoX performance engine. It is built for high concurrency and high-frequency data pipelines.

* **Order and matching engine:** Uses low-latency in-memory matching algorithms. It handles complex order book logic and ensures orders execute instantly at the best available price.
* **Market data and stream processing:** Ingests and normalizes multi-source oracle data from providers such as Pyth and Chainlink. It also powers internal high-precision candlestick data for TradingView and market depth views.
* **Margin calculation and liquidation risk control:** Monitors position changes and price movement in real time. It recalculates account equity and maintenance margin ratios at millisecond frequency. When an account approaches liquidation, it immediately triggers the liquidation instruction flow.
* **Settlement dispatch:** Packages matching results, mark price updates, funding deductions, and other critical events into validated instructions. These instructions are sent onchain at high frequency for final settlement by smart contracts.

#### 3. Frontend and API module

This is the access layer for users and liquidity providers.

* **Web UI:** Provides a fast, customizable trading terminal. Users can manage NFT accounts, review yield-bearing balances, and monitor deep market data from one interface.
* **Public API:** Offers robust REST and WebSocket APIs for quantitative traders, market makers, and developers. It supports low-latency automated trading as well as access to underlying onchain data.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.kryptox.finance/about-kryptox/core-technical-architecture.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
