Skip to content
Select theme
Light
Dark
Auto
Select language
English
فارسی

Running a theme

A theme is an HTTP server in a container image. Kaladan runs one container per theme version and sends it every buyer request for every shop on that version. This page is the contract between the two.

  • linux/amd64, running as a non-root user.
  • A read-only root filesystem; only /tmp is writable. All capabilities are dropped.
  • Under 300 MB compressed.
  • Prefer a Debian-based Node image (node:22-bookworm-slim) over Alpine: some Alpine builds lack the full Intl locale data and format Persian numbers and dates wrongly without any error.

The platform sets these variables:

Variable
PORTThe port to listen on. Never hard-code it.
KALADAN_INTERNALThe base address of the context endpoint and the signing keys.
KALADAN_THEME_ID, KALADAN_THEME_VERSIONThis build’s id and version.
KALADAN_ENVproduction or preview.

And the process must:

  • listen on 0.0.0.0:$PORT within 10 seconds of starting;
  • answer GET /_kaladan/health with 200 while it is alive, and GET /_kaladan/ready with 200 only when it can serve;
  • on SIGTERM, stop accepting connections, finish what is in flight and exit, within runtime.drainSeconds (20 by default, at most 60);
  • log JSON to stdout. Logs go to you, the publisher, never to the merchant.

Nothing else may be served under /_kaladan/.

The buyer’s path, method, query and body arrive unchanged. Their headers are stripped to a safe set (accept, accept-language, user-agent, referer, if-none-match, if-modified-since), cookies included, and Kaladan adds:

Header
X-Kaladan-ContextA signed JWT: the shop, the locale and direction, the route, the settings version.
X-Kaladan-Storefront-TokenA short-lived Storefront API key for this shop.
X-Kaladan-Request-IdPut it in your logs: it ties a support request to a trace.
traceparentW3C trace context. Pass it on to the calls you make.

The JWT is signed with EdDSA, and the public keys are at {KALADAN_INTERNAL}/.well-known/jwks.json. Check the signature, that aud is your theme’s id, and exp, before trusting any claim.

{
"iss": "kaladan", "aud": "golnar", "exp": 1789000000,
"shop": { "id": "shp_7f3a", "handle": "golnar", "domain": "golnar.ir" },
"locale": "fa-IR", "direction": "rtl", "currency": "IRR", "calendar": "JALALI",
"settingsVersion": "01JQ8Z3M", "themeVersion": "1.0.0",
"route": { "type": "PRODUCT", "handle": "lalejin-jar" },
"preview": false,
"contextId": "ctx_9a2f…"
}

The platform has already resolved the route. Do not re-parse the path to work out what page this is: the URL structure belongs to the platform and may change without breaking this contract.

GET {KALADAN_INTERNAL}/theme/v1/context/{contextId}
Authorization: Bearer {the X-Kaladan-Context JWT}

The answer is the render context: the shop (name, domain, locale, direction, calendar, how to present money, brand colours), the route, the merchant’s settings for this page, and the Storefront API endpoint, key and version to use. It is in-cluster and fast. A contextId belongs to exactly one shop and expires with the JWT.

  • The catalogue, content and cart: the Storefront API on the shop’s own domain, server-side, with the key you were given.
  • A signed-in buyer: the Customer Account API, from the browser only. A theme never calls it from the server and never handles a buyer’s token.
  • Payment: never. Link to the cart’s checkoutUrl and Kaladan’s hosted checkout takes it from there.

Status, headers and body pass through, except that:

  • Cache-Control is honoured, per shop and per settings version. That is where nearly all of a storefront’s speed comes from. A response with no Cache-Control is not cached at all, and a cart, account, order or checkout page is never cached, whatever it says.
  • A Set-Cookie for a Kaladan or buyer-session cookie is stripped.
  • A response slower than runtime.timeoutSeconds (10 by default, at most 30) is cut, and the platform serves its own error page.

A sensible catalogue page sends something like public, max-age=0, s-maxage=300, stale-while-revalidate=3600.

The order page is different: its route carries a token that is a credential for one buyer’s order. Serve it with caching disabled, and never log the token or send it anywhere else.

Files under assets/ are served from your container at /_theme/{themeId}/{version}/…, and the edge caches them as immutable: a new version is a new path.

Fonts must be bundled with their licence. Persian faces under an open licence, such as Vazirmatn, are the safe default.

Outbound traffic is denied by default. A theme can reach the platform’s own endpoints, the shop’s Storefront API, and the hosts it declares in network.egress, each with a reason a reviewer can read:

network:
egress:
- host: maps.example.ir
reason: Draws the store-pickup map on the contact page.
runtime:
timeoutSeconds: 10 # at most 30
drainSeconds: 20 # at most 60
concurrency: 40 # requests per container, at most 500
minReplicas: 0 # at most 10
resources: { memory: 512Mi, cpu: 500m }
  • Verify the context JWT on every request.
  • Never render a buyer’s data on the server, and never cache it.
  • Never forward or log the order token.
  • In preview (preview: true): no analytics, no tracking pixels, no writes.
  • Pass search terms to the API exactly as the buyer typed them; the platform normalizes Persian.
  • Format money with the shop’s divisor and numeral system, and dates with its calendar, at the moment of render.