Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Server Overview

System Components

Tiders-x402-Server Components

The server sits between clients and a database. Clients submit SQL queries over HTTP. If a table requires payment, the server process the request, calculate the cost, coordinates with an external x402 facilitator to verify and settle the payment before returning data as Arrow IPC.

Module Structure

The server is organized into the following modules:

ModulePurpose
root_handlerGET / — returns server metadata and available tables
query_handlerPOST /query — main handler for query execution and payment flow
sqp_parserParses and validates SQL, rejecting unsafe operations
sql_[database]Converts analyzed queries to Database-compatible SQL
databaseImplement the database trait to execute queries, get schemas and serializes results to Arrow IPC
pricePricing model: PricingModel (per-row or fixed), PriceTag, and TablePaymentOffers data structures
payment_configDetermines pricing for a query and generates x402 V2 payment requirements
payment_processingTranslates between V2 types and the facilitator’s wire format
facilitator_clientHTTP client for the remote x402 facilitator

Request Lifecycle

  1. Axum receives the HTTP request and routes it to the appropriate handler.
  2. sqp_parser parses and validates the SQL (rejects unsafe operations).
  3. duckdb_reader converts the analyzed query to a DuckDB-compatible SQL string.
  4. payment_config determines whether the table is free or paid, and calculates pricing based on the estimated row count.
  5. If payment is required, payment_processing and facilitator_client handle verification and settlement with the remote facilitator.
  6. database executes the query and serializes results to Arrow IPC.