> ## Documentation Index
> Fetch the complete documentation index at: https://docs.isofold.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Architecture Overview

> Understand how Isofold processes and optimizes your queries.

## How Isofold Works

Isofold is a drop-in SQL proxy that optimizes queries before they reach your data warehouse. It’s designed to be transparent, verifiable, and performant.

At a high level:

```text theme={null}
Client → Isofold Proxy → Data Warehouse
```

Isofold rewrites queries in-flight and ensures that results remain unchanged. It supports dry-run pricing, query diffing, and output equivalence verification.

***

## Core Components

### 1. Proxy Layer

The proxy receives SQL queries over HTTP, JDBC, or native Postgres wire protocol. It handles:

* Protocol translation (if needed)
* Authentication passthrough
* Routing to the appropriate backend engine

### 2. Rewrite Engine

The rewrite engine is responsible for transforming SQL into semantically equivalent forms that are cheaper to execute.

It performs optimizations such as:

* Projection pruning
* Join simplification
* Subquery flattening
* Predicate pushdown

You can configure aggressiveness levels per warehouse or per team.

### 3. Cost Model

For supported warehouses like BigQuery, Isofold runs a **dry-run** of both the original and optimized queries to compare estimated costs.

### 4. Verification Engine (Optional)

When enabled, Isofold will:

1. Execute both the original and rewritten queries
2. Compare result sets for equality
3. Log any divergence or mismatch for audit purposes

```bash theme={null}
export ISOFOLD_VERIFY_MODE=true
```

***

## Example Rewrite

Original query:

```sql theme={null}
SELECT * FROM users WHERE created_at >= '2023-01-01'
```

Rewritten query:

```sql theme={null}
SELECT id, email, created_at FROM users WHERE created_at >= '2023-01-01'
```

Assuming only those columns are ever referenced, the rewrite saves scan costs.

***

## Deployment Options

Isofold can be:

* Used as a **hosted service** with team-specific proxy URLs
* Deployed **inside your cloud/VPC**
* Run at the **edge** via Fly.io

See [Cloud Setup](/setup/cloud) or [Self-Hosted Setup](/setup/self-hosted) to choose what works best for you.

***

Next: Dive deeper into the [Rewrite Engine](/architecture/rewrite-engine).
