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

# System Overview

ZDrive is built on a Cloudflare Worker that acts as the routing and trust boundary layer between the browser client and all backend services. It handles request routing, wallet identity verification, rate limiting, credit checks, and proxying to TEE inference and Arweave storage.

## Component diagram

```mermaid
graph TB
    subgraph Client["Browser"]
        UI[React SPA]
        AES["AES-256-GCM\nEncryption"]
        ONNX["ONNX Embeddings\n(all-MiniLM-L6-v2)"]
        WM["Base Wallet\n(ERC-1271)"]
    end

    subgraph CF["Cloudflare Edge"]
        W["CF Worker\nzdrive.io"]
        KV["KV Store\n(rate limits)"]
        ASSETS["CF Assets\n(app.zdrive.io SPA)"]
    end

    subgraph Inference["TEE Inference"]
        CHUTES["Chutes.ai\nIntel TDX TEE"]
    end

    subgraph Storage["Decentralized Storage"]
        IRYS["Irys node2"]
        ARWEAVE["Arweave\n(permanent)"]
    end

    subgraph Chain["Base Network"]
        CONTRACT["ZDriveXCreditsV2\n(UUPS Proxy)"]
    end

    UI -->|"Encrypted requests"| W
    WM -->|"ERC-1271 signature"| W
    W -->|"Rate check"| KV
    W -->|"Credit check / consume"| CONTRACT
    W -->|"Proxy inference (SSE)"| CHUTES
    W -->|"Signed DataItem"| IRYS
    IRYS --> ARWEAVE
    ASSETS -->|"SPA bundle"| UI
    AES -.->|"Ciphertext only"| W
    ONNX -.->|"Browser-side RAG"| UI
```

## Request routing

The CF Worker inspects the hostname and path to route every request:

```mermaid
flowchart TD
    REQ[Incoming Request] --> HOST{Hostname?}
    HOST -->|"app.* or stg-app.*"| SPA[Serve SPA from CF Assets]
    HOST -->|"zdrive.io / stg.zdrive.io"| PATH{Path?}
    PATH -->|"/v1/* or /vault/*"| API[API Handler]
    PATH -->|"/robots.txt"| ROBOTS[robots.txt]
    PATH -->|"/sitemap.xml"| SITEMAP[sitemap.xml]
    PATH -->|"/llms.txt"| LLMS[llms.txt]
    PATH -->|"*"| LANDING[Landing Page HTML]
    API --> AUTH{Auth valid?}
    AUTH -->|No| 401
    AUTH -->|Yes| TIER{Tier?}
    TIER -->|"Paid"| INFERENCE[Full model inference]
    TIER -->|"Free / Connected"| FREE[Qwen3-32B inference]
```

## Environments

| Environment | Domain                                | Notes                      |
| ----------- | ------------------------------------- | -------------------------- |
| Production  | `zdrive.io` / `app.zdrive.io`         | Base mainnet, live credits |
| Staging     | `stg.zdrive.io` / `stg-app.zdrive.io` | Base Sepolia testnet       |


---

# 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.zdrive.io/architecture/overview.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.
