Theme App Runtime Architecture
Current runtime model, contract, and operational boundaries for Theme Apps
Theme App Runtime Architecture
This document describes the Theme App runtime that exists in the current core codebase. It intentionally documents the current support boundary, not a future Kubernetes controller design.
Runtime Model
Theme Apps are executable storefront packages that the API service starts as local child processes.
Current behavior:
- Admin activates a theme whose type is
app - API reads
extensions/themes-app/{target}/{slug}/{version}/theme-app.json - API allocates a local port
- API spawns
node <runtime.entry>inside the installed Theme App directory - API performs health checks against the spawned app
- Shop/Admin traffic is proxied through
/theme-app/{target}/{slug}/*
Runtime Policy Flags
The API service exposes three runtime policy environment variables:
| Variable | Default | Meaning |
|---|---|---|
THEME_APP_RUNTIME_ENABLED | true | Master switch for local-process Theme App startup |
API_REPLICA_COUNT | unset | Replica count injected by deployment so the runtime can detect multi-pod mode |
THEME_APP_RUNTIME_ALLOW_UNSAFE_MULTI_POD | false | Escape hatch that bypasses the multi-pod guard at your own risk |
Core implementation:
apps/api/src/core/admin/theme-app-runtime/contract.tsapps/api/src/core/admin/theme-app-runtime/manager.tsapps/api/src/core/admin/theme-app-runtime/gateway.tsapps/api/src/core/admin/theme-management/service.ts
Supported Contract
Theme Apps must use theme-app.json as the manifest filename.
{
"schemaVersion": 1,
"type": "theme-app",
"slug": "yevbi",
"name": "Yevbi",
"version": "1.0.0",
"target": "shop",
"runtime": {
"kind": "next-standalone",
"entry": "server.js",
"healthPath": "/api/health"
},
"port": {
"preferred": 3100,
"range": { "min": 3100, "max": 3199 }
},
"healthCheck": {
"timeout": 5000,
"retries": 3,
"retryInterval": 2000
},
"env": {
"LOG_LEVEL": "info"
}
}Authoritative Rules
theme-app.jsonis the only supported Theme App manifest filenameruntime.kindmust benext-standaloneruntime.entryis required- Theme App packages must include built artifacts such as
.next/staticand/orpublic - Source files such as
.ts,.tsx,.jsx, shell scripts, binaries, and source maps are rejected at install time
Health Check Resolution
The runtime resolves health checks in this order:
healthCheck.pathif presentruntime.healthPathif present- default path
/api/health
The following defaults apply when the manifest does not override them:
- timeout:
5000 - retries:
3 - retry interval:
2000
Runtime State
Theme App runtime state is process-local and in-memory:
- running instances are stored in an in-memory map
- allocated ports are stored in an in-memory set
- proxy routing resolves only instances known to the current API process
That means the current runtime is suitable for:
- local development
- single-process deployments
- controlled internal environments where this constraint is acceptable
For Kubernetes deployments, the supported shape is:
services.api.replicaCount = 1, or- an explicit unsafe override via
THEME_APP_RUNTIME_ALLOW_UNSAFE_MULTI_POD=true
It is not a cluster-aware scheduler.
Operational Limitation
The current implementation does not:
- create Kubernetes Deployments or Services
- start external microservice Theme Apps
- coordinate runtime state across multiple API Pods
If you run multiple API replicas, Theme App activation and proxying are still pod-local. Treat Theme Apps as an advanced, restricted capability until a dedicated runtime controller exists.
Installation and Activation
Installation
Theme App ZIP installation validates:
theme-app.json- manifest schema
- target compatibility
- build artifacts
- prohibited file types
- optional package signature
Installer implementation:
apps/api/src/core/admin/extension-installer/theme-app-installer.ts
Activation
Activation is fail-safe:
- current active theme is read
- Theme App is started
- health check must pass
- only then is the active theme record switched
If start or health check fails, the active theme stays unchanged.
Recommended Usage
Use Theme Apps only when you truly need a standalone storefront runtime. For most theme customization, prefer Theme Packs plus plugin app block and app embed extensions.
Related docs: