# Architecture

31Third provides a fully-fledged system based on three components. An API that uses on-chain and external data to prepare optimal rebalancings, a set of smart contracts enabling batched execution of token actions, such as trades, wrapping, and staking, and a frontend that allows the rebalancings of wallets, SetProtocol portfolio tokens or Enzyme vaults.

The usage of our frontend is optional. It is also possible to directly integrate our API and smart contracts into existing systems.

<figure><img src="/files/ZiAlyc76j3ILWdoRckZZ" alt=""><figcaption><p>31Third Stack</p></figcaption></figure>

## 31Third API

The 31Third API's primary purpose is to calculate rebalancings for wallets, SetProtocol tokens, Enzyme vaults, and other frameworks in the future.

Our algorithmic smart order router (ASOR) is the heart of our infrastructure. When you calculate a rebalancing, our algorithm finds the best prices and deepest liquidity not only across exchanges and market makers but also across each traded asset.

The algorithm fetches prices from different price sources for various DEXs and market makers. It analyses trade efficiency factors like depth of liquidity, slippage, price impact, multi-hop abilities, and more to calculate the optimal route from any base to any target allocation.

More on the 31Third API can be found below.

{% content-ref url="/pages/fa2iz2i85r9aBXYNLVZp" %}
[31Third API](/31third-api/overview.md)
{% endcontent-ref %}

## 31Third protocol

The 31Third protocol is a set of smart contracts allowing the execution of multiple token on-chain operations like trading, wrapping, staking, and others in one go, batched together in a single transaction.

More on the 31Third protocol can be found below.

{% content-ref url="/pages/SG4K5fjq88sRYe73NSip" %}
[Protocol](/protocol/overview.md)
{% endcontent-ref %}

## 31Third Frontend

We provide an easy-to-use UI for traders and asset managers to manage their portfolios. Just configure the desired target allocation, let our API calculate the optimal rebalancing, check if you are satisfied with the result, and execute the whole rebalancing within one transaction. This not only saves you time and nerves but also spares substantial gas fees. [Gas cost analysis](/protocol/statistics/gas-cost-analysis.md).

<figure><img src="/files/Uf0kzT2rCzpx8bYC4bOm" alt=""><figcaption><p>31Third portfolio rebalancing</p></figcaption></figure>

## External Integrator

Instructions on accessing our API and using the protocol can be found in the specific sections. If you have any questions, we are happy to assist. Reach out via mail or [Discord](https://discord.gg/TZ3GBBgnf9).

{% content-ref url="/pages/fa2iz2i85r9aBXYNLVZp" %}
[31Third API](/31third-api/overview.md)
{% endcontent-ref %}

{% content-ref url="/pages/SG4K5fjq88sRYe73NSip" %}
[Protocol](/protocol/overview.md)
{% endcontent-ref %}


---

# Agent Instructions: 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.31third.com/introduction/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.
