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.
The image
Section titled “The image”- linux/amd64, running as a non-root user.
- A read-only root filesystem; only
/tmpis 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 fullIntllocale data and format Persian numbers and dates wrongly without any error.
The process
Section titled “The process”The platform sets these variables:
| Variable | |
|---|---|
PORT | The port to listen on. Never hard-code it. |
KALADAN_INTERNAL | The base address of the context endpoint and the signing keys. |
KALADAN_THEME_ID, KALADAN_THEME_VERSION | This build’s id and version. |
KALADAN_ENV | production or preview. |
And the process must:
- listen on
0.0.0.0:$PORTwithin 10 seconds of starting; - answer
GET /_kaladan/healthwith200while it is alive, andGET /_kaladan/readywith200only when it can serve; - on
SIGTERM, stop accepting connections, finish what is in flight and exit, withinruntime.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 request
Section titled “The request”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-Context | A signed JWT: the shop, the locale and direction, the route, the settings version. |
X-Kaladan-Storefront-Token | A short-lived Storefront API key for this shop. |
X-Kaladan-Request-Id | Put it in your logs: it ties a support request to a trace. |
traceparent | W3C trace context. Pass it on to the calls you make. |
Verify the context
Section titled “Verify the context”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.
Fetch the render context
Section titled “Fetch the render context”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.
Getting data
Section titled “Getting data”- 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
checkoutUrland Kaladan’s hosted checkout takes it from there.
The response
Section titled “The response”Status, headers and body pass through, except that:
Cache-Controlis honoured, per shop and per settings version. That is where nearly all of a storefront’s speed comes from. A response with noCache-Controlis not cached at all, and a cart, account, order or checkout page is never cached, whatever it says.- A
Set-Cookiefor 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.
Assets
Section titled “Assets”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.
Network
Section titled “Network”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.Resources
Section titled “Resources”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 }Rules worth repeating
Section titled “Rules worth repeating”- 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.