# NATUVISIO Circle — APX Machine State & Zero-Dependency Rust Architecture (`apx.md`)

## 1. Sovereign Runtime & Entity Ground Truth
- **Entity**: `NATUVISIO GIDA TAKVİYELERİ VE TİCARET LİMİTED ŞİRKETİ` (`Pendik V.D.`, VKN `6301390185`, İstanbul, Türkiye)
- **Canonical Origin**: `https://circle.natuvisio.com` (with `/api/circle` prefix-stripped mirror)
- **Runtime Engine**: `backend/rust/circle-site` (`std`-only Rust HTTP/1.1 + API + MCP + Wire-Compression Engine, `0` external crates, linked with `circle-core` and `nv-core`).
- **Cryptographic Primitives**:
  - **SHA-256 & HMAC-SHA256** (`nv_core::crypto`): Constant-time verification (`ct_eq`), ledger hash-chaining, webhook signatures (`NV-Signature: t=<sec>,v1=<hex>`), `HS256` JWT Bearer auth (mandatory `sub` + `exp`), and signed 60-day attribution cookies (`nv_ref` & `nv_circle_ref`).
  - **BLAKE3** (`circle_core::blake3`): Tree-hashing state proof (`circle_b3 == ops_b3`) across `/v1/state`, `/v1/reconcile/a2a`, `/v1/graph`, and `/healthz`.
  - **Crockford Base32 ULID** (`nv_core::uid`): Monotonic sortable 26-char IDs (`clk_...`, `evt_...`, `bat_...`, `tel_...`).

## 2. Five-Plug Integration Map & V3 Native Surface
1. **PLUG 1 — First-Click & WKWebView Attribution (`GET /p/{code}`, `GET /c/{code}`)**:
   - ASCII-safe partner code normalization (`circle_core::normalize_code`), bot/link-preview filtering (`classify_ua`), CGNAT-safe 1-hour click deduplication, and 60-day `HttpOnly; SameSite=Lax` cookies (`nv_ref` + `nv_circle_ref`).
   - `/c/{code}` detects Instagram/TikTok in-app `WKWebView` browsers and emits `X-Circle-WKWebView: 1`.
   - `POST /v1/attribution/resolve` computes 70% Closer / 30% Discovery multi-touch splits with Hamilton largest-remainder kuruş conservation and SHA-256 `merkle_root`.
2. **PLUG 2 — Store Checkout & Signed Order Webhooks (`GET /checkout`, `POST /v1/webhooks/orders`)**:
   - Integer kuruş math (`floor((base_minor * rate_bp + 5000) / 10000)`), multi-signal `G_SELF` self-referral hold, out-of-order parked refunds (`202 Accepted`), and proportional partial/full clawbacks.
3. **PLUG 3 — Partner App Live API (`/v1/me`, `/v1/me/profile`, `/v1/me/payout-account`, `/v1/me/ledger`, `/v1/telemetry`)**:
   - Deterministic KYC ladder (`K0` verified email → `K1` profile+affiliation → `K2` TR IBAN mod-97 + TCKN/VKN checksum + holder match + social → `K3` verified venue lead).
   - PII encrypted at rest (`enc1:...`), exposing only `last4`.
4. **PLUG 4 & 5 — Ops Control Plane, `2.500 TL` Payout Threshold & 3-Way A2A Reconciliation**:
   - `/v1/ops/payouts/draft` enforces the `2.500 TL` (`250_000` kuruş) minimum payout threshold and carries sub-threshold balances forward (`below_min_payout`).
   - `/v1/ops/payouts/{id}/approve` enforces four-eyes separation (`approver != drafter`).
   - `/v1/reconcile/a2a` verifies `orders_net_minor == gateway_net_minor == ledger_net_minor` (`0` kuruş drift → `200 MATCH`, any drift → `503 DRIFT`).
5. **Sovereign Search, Graph & MCP `2025-06-18` (`GET /v1/search`, `GET /v1/graph`, `GET|POST /mcp`)**:
   - `GET /v1/search`: Weighted multi-field Okapi BM25 (`k1=1.4`, `b=0.65`) over `191` indexed Turkish documents (`155` public HTML routes + `36` Z–A glossary terms), 52-suffix Turkish agglutinative stemmer, bidirectional domain synonyms, and pre-ranking TGK 2013/49 & Reklam Kurulu 23/A abstention gate.
   - `GET /v1/graph`: Merges `/site-graph.json` (`155` nodes, `2703` internal directed edges) with live `ledger_b3` and wire telemetry.
   - `GET|POST /mcp`: Streamable HTTP JSON-RPC 2.0 MCP server (`natuvisio-circle-partner-mcp` v4.5.0) exposing `circle_search`, `circle_calc_income`, `circle_calc_tax`, `circle_lint_copy`, and `circle_reconcile_a2a`.

## 3. Agentic Markdown Negotiation & Wire Compression
- Sending `Accept: text/markdown` to static content routes returns clean UTF-8 Markdown with `X-Markdown-Tokens` and `Content-Signal: search=yes, ai-train=no, ai-input=yes`.
- All static assets negotiate fresh Zstandard (`.zst`), Brotli (`.br`), and Gzip (`.gz`) payloads with `Vary: Accept, Accept-Encoding`.
