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

# Architecture

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

## 4Mica MVP Call Flow

### Participants

* **Client (C)**
* **Server (S)**
* **Facilitator (4Mica Core Service) (F)**
* **Vault (4Mica Core Contract) (B)**

***

### 1. Deposit

1. Client deposits `val` to Vault (`B`).
2. Vault emits `"deposit"` event to Facilitator (`F`).
3. The facilitator adds collateral for the client.

Vault at the alpha release is the core contract of 4Mica, and in later releases, would be a capital-efficient vault.&#x20;

***

### 2. Transaction Phase

#### 0th Request

* Client requests service from Server.
* Server responds with `402 Payment Required` and a `tab_id`.
* Client records `start_ts`.

#### ith Request

1. Client sends service request with a signed promise.
2. Server verifies promise via Facilitator.
   * If promise is invalid → decline.
   * If insufficient funds → decline.
   * Else:
     * Facilitator aggregates and locks promise.
     * Server executes the service request.
     * Client receives answer.

***

### 3. Settlement (Client Pays Server)

1. Client pays server on-chain (`val`, `tid`, `req_id`).
2. Facilitator monitors blockchain for transactions.
3. If transaction matches promise:
   * Record payment, update collateral lock.
   * Notify Vault to register payment.
4. Vault updates status.

***

### 4. Remuneration (If Client Fails to Pay)

1. Server triggers timeout and requests remuneration from Vault.
2. Vault verifies request:
   * Invalid → error.
   * Valid → pays server from client deposit.
3. Facilitator unlocks the locked collateral that was used to back the line of credit for the tab.
4. Vault emits `"remunerated"` event.

***

### 5. Withdrawal

1. Client requests withdrawal from Vault.
   * If `val > deposit` → error.
   * Otherwise, Facilitator reserves funds.
2. After `WITHDRAWAL_LATENCY`:
   * Client executes withdrawal:
     * If valid → transfer funds and update deposit/collateral.
     * If invalid → error.
   * Client may cancel withdrawal request:
     * Vault and Facilitator remove reservation.


---

# 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, and the optional `goal` query parameter:

```
GET https://docs.4mica.xyz/architecture.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
