Core Concepts

How It Works

Gostly is a transparent HTTP proxy with four operating modes: LEARN, MOCK, PASSTHROUGH, and TRANSITIONING. Understanding the pipeline between them is the key to getting the most out of the tool.

The pipeline

1. LEARN

The proxy forwards every request to your upstream and records the verbatim response. Your app sees no difference.

2. TRANSITION

Recorded traffic is scrubbed, pattern-extracted, and written to the mock library. A brief interstitial mode returns 503 + Retry-After.

3. MOCK

All requests are served from the mock library. No upstream required. Unmatched requests fall through to AI generation if enabled.

LEARN mode — recording traffic

In LEARN mode the proxy is a transparent pass-through. Every inbound request is forwarded to the configured upstream URL. The response is returned to the caller and simultaneously written to a local JSONL file on disk:

# Each line in traffic/{service}.jsonl is one recorded interaction
{
  "timestamp": "2026-04-23T09:14:22Z",
  "method": "GET",
  "uri": "/users/42",
  "request_headers": { "accept": "application/json" },
  "request_body": null,
  "status": 200,
  "response_headers": { "content-type": "application/json" },
  "response_body": { "id": 42, "name": "Jane Smith", "role": "admin" }
}

On sensitive headers

In recorded traffic, authorization tokens, cookies, API keys, and a floor of enterprise security headers are redacted by default on every sink that touches disk or leaves the box. Imported files keep the headers they were supplied with in the local replay library. The in-memory active-session store keeps them verbatim for replay fidelity but never leaves the box. See the header redaction reference for the full list.

JSONL files live on the customer's machine and are never transmitted anywhere. The verbatim format preserves full fidelity — tests that pattern-match on specific field values work correctly because the recorded data is production-accurate.

Transition — building the mock library

When you trigger a transition, the API reads the raw JSONL, runs it through a scrub pipeline, and writes the results to the Postgres-backed mock library:

Scrub

Request/response bodies are scanned for credentials, PII patterns, and any field paths you've configured. Matched values are replaced with [REDACTED]. The scrubbed_at timestamp is set; AI training and default exports read only rows that carry it.

Pattern extraction

URI paths are normalised to templates (e.g. /users/42 → /users/{id}). The extracted patterns drive AI training and smart-swap matching.

Mock library write

Scrubbed entries are inserted into the mock_library table. The proxy is signalled to reload — it reads the library and serves from it on the next request.

During transition the proxy enters TRANSITIONING mode and returns 503 Service Unavailable with a Retry-After header. This is intentional — it prevents partial-library matches during the write.

Start a transition for one service via the API (or use the dashboard at localhost:3000). The request names the service; GET /v1/services lists the ids:

curl -X POST http://localhost:8000/v1/transition/start \
  -H "X-API-Key: $GHOST_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"service_id": "<service_id>"}'
# Returns 202: { "job_id": "...", "status": "queued" }

# Poll the job until its state is completed or failed
curl http://localhost:8000/v1/transition/{job_id}/status \
  -H "X-API-Key: $GHOST_API_KEY"

MOCK mode — serving responses

A completed transition switches that service to MOCK. To switch a service yourself, use the dashboard or the API:

curl -X PUT http://localhost:8000/v1/services/{service_id} \
  -H "X-API-Key: $GHOST_API_KEY" \
  -H 'Content-Type: application/json' \
  -d '{"mode": "MOCK"}'

In MOCK mode the proxy matches each inbound request against the library using a tiered strategy. Earlier tiers are cheaper; later tiers are more capable:

Exact match

Deterministic

Method + URI + request body hash matches a recorded entry exactly. Instant — O(1) hash lookup.

Session verbatim

Deterministic

If the request was seen during the active LEARN session, the in-memory capture replays it byte-for-byte (bodies and headers, served with X-Ghost-Mock: session-verbatim). This buffer is RAM-only — it never leaves the box and resets on restart or a new LEARN window.

Statechart / resource

Deterministic

A Harel statechart models resource lifecycles, so a POST /charges followed by GET /charges/{id} returns the created resource instead of a 404. PATCH/POST transitions rewrite the status field and tag the response with X-Ghost-Transition. The engine runs in every installation; the bundled lifecycles are opt-in, and you can author your own charts.

Smart swap

Deterministic

URI path parameters are normalised to templates (/users/{id}) and matched structurally. A recording of /users/42 will serve a request to /users/99.

AI generation

When AI is enabled

Last resort. With no recorded, session, statechart, or structural match, a fine-tuned model (or retrieval-augmented generation) generates a realistic response based on recorded patterns for this service. With AI off, the cascade stops at smart swap.

Chaos injection

Any tier can be wrapped with chaos config — injecting random latency, error rates, or specific status codes to simulate degraded upstream behaviour.

AI pipeline (when enabled)

When a request has no recorded match, Gostly routes it to the inference server. Two settings on the inference server decide how it answers; the Full stack sets both:

ENABLE_RAG=true

Loads the all-MiniLM-L6-v2 sentence encoder and builds a per-service semantic index from your mock library. Incoming requests are matched by cosine similarity — above 0.92 the recorded response is replayed directly; above 0.75 it becomes a grounded generation template; below that, pure generation. This is the recommended first step.

LLAMACPP_ENDPOINT

Routes generation through the isolated ghost-llamacpp sidecar, the only generation backend. The sidecar serves the base model and any per-service LoRA adapters you train locally. The older ENABLE_GENERATION flag is retired: a leftover true value is ignored with a startup warning.

The AI pipeline is local by default — the inference server runs inside your Docker stack, so no request bodies or response contents leave the box. An optional BYO-key cloud-LLM backend (OpenAI, Azure, or Bedrock) exists but is off unless you explicitly configure it.

Next steps