Architecture
The licensed Gostly product ships as a Docker Compose stack. In the generated Full stack, the proxy, web and inference containers mount gostly-data at /data; Postgres has separate storage. A Rust proxy handles selected application requests, the API and dashboard manage workflows, and the optional inference service handles retrieval and response-generation work. This page is the technical version of the marketing architecture overview — env-var names, ports, and endpoints included.
The containers
A licensed Full deployment is five long-running containers, plus a one-shot ghost-migrate that applies the database schema before the API starts and, while the demo profile is on (a fresh .env turns it on), the bundled demo upstream. Lite leaves out the two AI containers, ghost-inference and ghost-llamacpp. The web container runs the API and dashboard as separate processes. Generated Compose publishes the proxy and web interfaces; PostgreSQL and inference are not published to the host. The inference service joins both the default network and llama-isolated; the model container joins only llama-isolated, which is declared internal: true. This network membership does not isolate the entire stack from external contacts.
ghost-proxy
Rust · :8080 / :8443The component that receives and serves proxied requests. Records traffic during LEARN, serves the library during MOCK, forwards transparently during PASSTHROUGH. Plain HTTP on :8080; the TLS-MITM listener binds :8443 only when ENABLE_TLS_INTERCEPTION is set. The supplied Compose files publish only :8080. The Full file passes ENABLE_TLS_INTERCEPTION from .env; the Lite file does not. To turn interception on, publish 8443 and set the variable, as the TLS guide shows.
ghost-web
Python + Next.js · :8000 / :3000One container running two services under supervisord — the FastAPI control plane on :8000 (mocks, services, traffic, transitions, drift, repair, webhooks, resources, auth/RBAC) and the Next.js operator dashboard on :3000. Reads the proxy's append-only JSONL captures and reconciles them into Postgres.
ghost-postgres
Postgres 16 · internalThe managed store: the mock library, drift events, repair proposals, training sessions, statechart overrides, an audit log that the application only appends to, and the user workspace. Not published to the host by generated Compose.
ghost-inference
Python · :5000 · Full stackRuns RAG retrieval, sends response generation to ghost-llamacpp, and runs local adapter training as a CPU worker process. Builds its retrieval index in memory from the shared mock library on /data. It joins both the default and llama-isolated networks.
ghost-llamacpp
Full stack · isolatedThe local llama.cpp response-generation backend behind ghost-inference. Of gostly-data, it mounts only the adapter subdirectory read-only at /models/adapters. Its sole network is llama-isolated, declared internal:true; ghost-inference also joins that network.
Distribution
# Published to the host by the generated Compose ghost-proxy :8080 selected HTTP traffic ghost-web :3000 operator dashboard ghost-web :8000 control-plane API (bound to 127.0.0.1) # Opt-in: add ENABLE_TLS_INTERCEPTION and the 8443 port mapping yourself ghost-proxy :8443 TLS-MITM listener # Not published to the host by generated Compose ghost-postgres canonical state ghost-inference :5000 retrieval + background generation
Operating modes
A service-specific override takes precedence over the global mode; changing the global mode does not clear overrides. At startup, the proxy reads a valid saved mode first, then a valid INITIAL_MODE, then falls back to LEARN. Generated Compose supplies LEARN and the saved-mode path /data/mode.txt. Writes of concrete global modes are best-effort; TRANSITIONING is not saved. Confirm the mode again after restart when persistence matters.
LEARN
Forwards eligible traffic to the configured upstream and captures supported exchanges. Capture is conditional and bounded; an upstream response does not prove that every recording or resource-state write succeeded.
MOCK
Selects eligible loaded responses and configured behavior. An ordinary HTTP miss returns a configured local response rather than automatically calling the upstream. Admission, faults and episode rules can answer or refuse before ordinary source selection.
PASSTHROUGH
Forwards eligible traffic without building the ordinary recorded library. Use it when the case requires current upstream behavior.
TRANSITIONING
An internal state during library processing. Its ordinary HTTP branch returns 503 with Retry-After: 5. Wait for completion and check actual service mode before treating the library as ready.
Request the global mode through the control plane; callers can select LEARN, MOCK or PASSTHROUGH, not TRANSITIONING:
curl -X POST 'http://localhost:8000/v1/mode' \
-H "X-API-Key: $GHOST_API_KEY" \
-H 'Content-Type: application/json' \
-d '{"mode": "MOCK"}'Read GET /v1/mode with authentication to inspect the configured agent's global health mode. Also check service overrides in service configuration; that readback does not report every service's effective mode. A successful POST response does not establish that the mode file was durably written.
The match cascade
The rows below summarize ordinary MOCK HTTP source selection, in order where eligible. Routing, admission, configured faults and episode-specific behavior can answer or refuse earlier. A serving source and any background model work are separate observations.
Session-verbatim
Eligible active-session replay precedes loaded exact entries. Its memory store retains admitted response bodies and session headers for replay to callers; it is distinct from durable replay copies.
Exact library entry
Matches service, method, path/query and request body against the loaded library. The selected stored fields are served subject to applicable header and response behavior; a library entry may be recorded or imported.
Resource and chart behavior
A GET can read an existing scoped resource by collection and ID. Supported action requests can advance its bound chart. Unhandled actions fall through or reject according to chart policy; earlier recorded matches can answer before mutable state.
Smart swap
With the effective smart_swap capability, a structurally matching recorded entry can answer a changed path parameter. Inspect the returned identity and fields rather than assuming every substitution is suitable for the client.
Eligible generated cache
After smart swap, eligible cached responses can serve subject to authority, confidence and media checks. Episode requests skip this volatile cache. A missing entry may queue background generation without supplying the current response.
Prepared generalized response or miss
A separately admitted pinned generalized-response store can answer before the miss tail. If no eligible source answers, X-Ghost-Miss marks the configured status/body; the default is 404 with a generic no-mock-found body.
Serving and background work
Statecharts, resources, and drift
Captured resource state and authored lifecycle rules are separate inputs. Eligible successful LEARN POST/PUT responses with a JSON resource identity can populate the resource store on a best-effort basis. The bundled lifecycles — charge, customer, invoice, order and subscription — are off by default, and a workspace can enable their binding for subsequently captured resources. Authored charts bind separately. Supported PATCH action requests or POST action paths can advance a bound chart; ordinary GET and collection POST are not chart action transitions. Unhandled actions depend on chart policy. Ordinary POST replay does not create arbitrary resources; episode creation is separate, explicitly opted-in behavior.
The control plane's drift detector compares fresh upstream shapes against the recorded library, emitting drift events plus a 0–100 freshness score and a sparkline trend so operators can see at a glance which services have decayed.
Cold-start seeding
POST /v1/seed/har, POST /v1/seed/postman, or POST /v1/seed/openapi.AI mock-repair is an operator-assist surface: the control plane can propose fixes for stale mocks that an operator approves or rejects. The auto-proposer loop is off by default behind ENABLE_AI_MOCK_REPAIR; manual approve/reject works either way.
The inference server
Full Compose routes response generation from ghost-inference to the local ghost-llamacpp sidecar. Retrieval and generation use the following configuration:
ENABLE_RAGon by default
Builds a per-service semantic index from your mock library and matches incoming requests by similarity. Retrieval grounds the edge of the cascade in your own recorded data.
LLAMACPP_ENDPOINTset by the Full stack
Routes generation through the isolated ghost-llamacpp sidecar, the only generation backend. The older ENABLE_GENERATION flag is retired: a leftover true value is ignored with a startup warning.
Generated responses are cached; LoRA adapters are model files loaded by the generation backend. The live-mock training selector requires processing markers and other eligibility checks. A marker does not prove that every sensitive value was removed. Separately configured API convention analysis can use OpenAI, Azure OpenAI or Bedrock; those providers are distinct from the local llama.cpp response-generation path.
State, redaction, and where data lives
LEARN capture can retain an active-session memory copy and separate durable local history/replay files. The control plane processes captured traffic into managed PostgreSQL rows; it does not rewrite every local serving copy into those processed rows. Retained content revisions also contain content. Representative generated-Compose paths are:
/data/
mocks/ mock_{service}.jsonl local replay index
traffic/ traffic_{service}.jsonl captured interactions
webhooks/ {service}.jsonl captured inbound webhooks
mode.txt saved global mode
models/adapters/{service}/{session}/ per-service LoRA adaptersCapture and import boundaries
Transition processing applies body/header rules before writing database rows and processing markers. Imports and snapshot archives have separate processing paths, and export filters differ by operation and option. A processing marker does not guarantee complete sensitive-data removal. Review the selected data and retained copies before sharing; the security model describes the detailed boundaries.
Gostly is single-tenant per deployment: the tenant id comes from GOSTLY_TENANT_ID, which setup writes into .env (default is only the last fallback), and every query is tenant-scoped in application code. Postgres Row-Level Security sits underneath as defense in depth enforced by the database: the API's request path connects as the non-owner gostly_app role, which cannot bypass RLS, binds the tenant for each transaction, and every tenant-scoped table with a tenant policy has FORCE ROW LEVEL SECURITY, so a query that omits its tenant filter still sees only its own tenant's rows. Background jobs that work across the store connect as a separate gostly_service role that bypasses RLS.
Auth, RBAC, and licensing
Authentication lives in the web container's auth layer. Beyond password login, every license ships SAML and OIDC SSO, a four-role RBAC model — viewer < member < admin < owner — and an auth audit log that the application only appends to. Auth mode is set via GOSTLY_AUTH_MODE (e.g. password,saml).
Team organization governance has separate entitlements from deployment SAML/OIDC sign-in, deployment roles and deployment authentication audit. The deployment mechanisms above use the self-hosted auth configuration.
Licensed capabilities are checked at the surfaces that implement them. The deployment API checks effective license values on gated operations; the proxy checks its signed runtime capabilities on serving paths. Dashboard locks explain availability, while server-side checks authorize operations. The deployment API uses tier defaults only for missing feature values; explicit values in a verified license take precedence. Each operation's authentication, role, tenant/resource scope and applicable seat checks remain separate authorization conditions.
In an already-running trial or subscription deployment using online key validation, the proxy can retain verified capabilities through a transient licensing outage only within its signed proof and entitlement deadlines. Expired authority or a definitive license rejection locks customer traffic until fresh valid authority restores access. Starting those deployments requires live validation; a cached token is not a restart guarantee.
For online key validation, proxy revalidation defaults to five minutes. Its verified-proof ceiling is the earliest of token expiry, 24 hours after signed issuance, and 24 hours after local verification; an entitlement deadline can close access sooner. The API has a separate cache: five minutes fresh and up to four hours stale from successful validation by default, shortened by the applicable authority deadline. These are separate bounds, not a fixed period measured from the start of an outage.
Enterprise can instead use a signed license file on supported standard images. The proxy and API verify that file locally and use its signed expiry rather than the online validation cache bounds. Keep the existing license key for tenant identity unless the tenant is explicitly pinned. First installation requires a proxy restart; renewal is checked after traffic locks at the old expiry, with retries over a nominal 30 seconds. Traffic stays locked until a valid later-expiring, unexpired file is adopted. Telemetry remains a separate setting. See Enterprise signed license setup for the procedure and expiry access limits.
Protocols and TLS
Gostly records and replays HTTP and HTTPS — HTTP/1.1 and HTTP/2 over TLS. WebSocket frame capture is off by default. When explicitly enabled, it follows the service traffic capture switch and retains observability data, without frame-body scrubbing or conversation replay. There is no gRPC, async-messaging, or database mocking today (roadmap).
TLS is a tri-state knob. ENABLE_TLS_INTERCEPTION defaults off; true / lax enables the MITM listener with a log-and-continue posture, and strict exits the process on a TLS failure. When interception is on, the proxy mints per-host leaf certs from an embedded CA, and GET /ca.crt on the proxy serves that CA for the trust-install flow (it returns 503 while interception is off).
Outbound TLS-fingerprint impersonation — presenting a genuine Chrome, Firefox, or Safari fingerprint to the upstream — is off unless a service is configured for it.
Webhooks
Inbound webhook capture follows each active service's webhook capture switch — the proxy writes one append-only JSONL file per service. Replay is operator-triggered through the control plane (POST /v1/webhooks/{service_id}/{webhook_id}/replay); the agent does not auto-replay captured webhooks. Scheduled fan-out and re-signing are roadmap, not shipped.
Observability
The proxy exposes a Prometheus scrape endpoint at /metrics. Scrape it with the deployment's service key in X-API-Key to get every series below: an unauthenticated scrape withholds each sample that carries a customer-identity label (such as the service or the endpoint) and reports gostly_metrics_detail_redacted 1. The core series:
ghost_requests_total{match_type}Counter, one increment per match-path outcome (exact, smart_swap, session_verbatim, resource_store, miss, learn, …) — the cascade in metric form.
ghost_mock_library_sizeGauge of the current mock-library size.
ghost_io_errors_total{operation}Disk-sink open/write failures, by operation.
axum_http_requests_total / _duration_secondsHTTP request rate and latency, emitted by the Axum Prometheus layer.
gostly_tls_*The TLS-MITM subsystem family — ALPN negotiation, cert-cache hit/miss/eviction, and listener state.
Next steps
How It Works →
The LEARN → MOCK pipeline and the match cascade, walked through end to end.
Proxy Setup →
Multiple services, TLS interception vs. Caddy-fronting, CI integration, chaos injection.
Configuration Reference →
Every environment variable, the redaction floor, scrub rules, and the tier feature matrix.
API Reference →
Mode, transition, seed, drift, statechart, and webhook endpoints.