> 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 by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.zdrive.io/architecture/overview.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
