[package]
name = "heliosdb-proxy"
version = "0.4.2"
edition = "2021"
rust-version = "1.75"
description = "HeliosProxy - Intelligent connection router and failover manager for HeliosDB and PostgreSQL"
license = "Apache-2.0"
authors = ["HeliosDB Team"]
repository = "https://github.com/dimensigon/HDB-HeliosDB-Proxy"
homepage = "https://www.heliosdb.com/heliosproxy.html"
documentation = "https://docs.rs/heliosdb-proxy"
keywords = ["database", "proxy", "failover", "load-balancer", "connection-pool"]
categories = ["database", "network-programming"]
readme = "README.md"
exclude = [
    "demos/",
    "docs/",
    "operator/",
    "terraform/",
    "docker/",
    "scripts/",
    ".github/",
    "*.png",
    "*.jpg",
]

[package.metadata.docs.rs]
all-features = true
rustdoc-args = ["--cfg", "docsrs"]

[features]
default = ["pool-modes"]

# ── Core features ────────────────────────────────────────────────────

# Connection pooling modes (Session/Transaction/Statement)
pool-modes = []

# Transaction Replay (TR) - failover replay, cursor restore, session migrate
ha-tr = []

# ── Topology providers ──────────────────────────────────────────────

# PostgreSQL-based topology discovery (pg_is_in_recovery polling)
postgres-topology = []

# HeliosDB internal topology (requires HeliosDB-Lite workspace)
heliosdb-topology = []

# ── Proxy feature modules ───────────────────────────────────────────

# Query caching (L1 hot / L2 warm / L3 semantic)
query-cache = []

# Query routing hints (/*+ route=primary */)
routing-hints = []

# Replica lag-aware routing with read-your-writes
lag-routing = []

# Rate limiting (token bucket, sliding window, concurrency)
rate-limiting = []

# Circuit breaker pattern (adaptive thresholds)
circuit-breaker = []

# Query analytics, slow query log, N+1 detection
query-analytics = []

# Multi-tenancy (tenant isolation, per-tenant pools)
multi-tenancy = []

# Authentication proxy (JWT, OAuth, API keys)
auth-proxy = []

# SQL query rewriting (rules engine)
query-rewriting = []

# WASM plugin system (hot-reload, sandboxed) — requires wasmtime.
wasm-plugins = ["dep:wasmtime"]

# GraphQL-to-SQL gateway
graphql-gateway = []

# Schema-aware routing (data temperature, workload classification)
schema-routing = []

# Distributed intelligent caching (DistribCache)
distribcache = []

# Anomaly detection (rate spikes, credential stuffing, SQL injection
# heuristics, novel query shapes). In-process sliding windows; no
# external data store.
anomaly-detection = []

# Edge / geo proxy mode — cache-first request handling, last-write-
# wins TTL coherence, pull-on-miss + invalidation push.
edge-proxy = []

# ── Observability ────────────────────────────────────────────────────

# Full observability (metrics, tracing)
observability = ["dep:prometheus", "dep:opentelemetry"]

# ── Bundle features ─────────────────────────────────────────────────

# All proxy features (no topology provider — choose one separately)
all-features = [
    "pool-modes", "ha-tr",
    "query-cache", "routing-hints", "lag-routing",
    "rate-limiting", "circuit-breaker", "query-analytics",
    "multi-tenancy", "auth-proxy", "query-rewriting",
    "wasm-plugins", "graphql-gateway", "schema-routing",
    "distribcache", "anomaly-detection", "edge-proxy",
]

[dependencies]
# Async runtime
tokio = { version = "1", features = ["full"] }

# Networking
tokio-util = { version = "0.7", features = ["codec"] }
bytes = "1"

# Serialization
serde = { version = "1", features = ["derive"] }
serde_json = "1"

# Error handling
thiserror = "1"
anyhow = "1"

# Logging
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter", "json"] }

# Time
chrono = { version = "0.4", features = ["serde"] }

# UUID
uuid = { version = "1", features = ["v4", "serde"] }

# Concurrent data structures
dashmap = "5"
parking_lot = "0.12"

# Configuration
config = "0.14"
clap = { version = "4", features = ["derive"] }
toml = "0.8"

# Regex (used by analytics, routing, rewriter)
regex = "1"
once_cell = "1"

# Encoding (used by auth, distribcache)
base64 = "0.21"
bincode = "1"

# Random (used by rate_limit, circuit_breaker)
rand = "0.8"

# HTTP (used by auth OAuth, optional)
reqwest = { version = "0.11", features = ["json"], default-features = false }

# Compression (used by distribcache tiers)
zstd = "0.13"

# Backend PG client (src/backend/) — auth + TLS + text-format I/O.
# Kept lightweight: ring for crypto, no BoringSSL, no tokio-postgres.
rustls = { version = "0.23", default-features = false, features = ["ring", "std", "tls12", "logging"] }
tokio-rustls = { version = "0.26", default-features = false, features = ["ring", "tls12", "logging"] }
rustls-pki-types = "1"
webpki-roots = "0.26"
sha2 = "0.10"
hmac = "0.12"
md-5 = "0.10"
# Ed25519 signature verification for the plugin loader's trust-root
# checks (FU-23). The dalek crate is the standard pure-Rust impl;
# `default-features = false` strips std-allocator-only paths we don't
# use and keeps the dep set tight.
ed25519-dalek = { version = "2", default-features = false, features = ["alloc", "fast"] }
# Plugin OCI artefact (.tar.gz with manifest.json + plugin.wasm +
# plugin.sig) ingestion. Optional — only pulled in when the plugin
# loader sees a .tar.gz extension.
tar    = "0.4"
flate2 = "1"

# Embed the .claude/skills/ bundle into the binary so `cargo install`
# users (no git clone) can deploy the skills via
# `heliosdb-proxy install skills`. The bundle path is resolved at
# compile time — keep `.claude/` out of `Cargo.toml`'s exclude list.
include_dir = "0.7"

# WASM plugin runtime — wasmtime is feature-gated on wasm-plugins so
# default builds don't pay the (~3 MB compiled) cost. The cranelift
# backend is the JIT; we strip wasi/component-model since the plugin
# ABI is bare extern "C" exports against linear memory.
wasmtime = { version = "26", default-features = false, features = ["cranelift", "runtime", "parallel-compilation"], optional = true }

# Optional: Metrics
prometheus = { version = "0.13", optional = true }
opentelemetry = { version = "0.21", optional = true }

[dev-dependencies]
tokio-test = "0.4"
criterion = { version = "0.5", features = ["html_reports", "async_tokio"] }
# Inline-WASM (.wat → .wasm) for plugin runtime tests so we don't have
# to ship binary fixtures.
wat = "1"
# Temp directories for the plugin signature-verifier tests (FU-23) so
# trust-root scaffolding stays inside cargo test's tempdir without
# polluting the workspace.
tempfile = "3"

[[bin]]
name = "heliosdb-proxy"
path = "src/main.rs"

[lib]
name = "heliosdb_proxy"
path = "src/lib.rs"

[[bench]]
name = "pooling"
harness = false

[[bench]]
name = "routing"
harness = false

[[test]]
name = "integration"
path = "tests/integration/mod.rs"
