The layer has two programs that never call each other. An admin console decides what should be on a client's page. A Worker at the edge puts it there. Between them is a key-value store, and the shape of what is written into it is the whole interface.

The system on one page

Three columns. Admin side: MongoDB holding sites, pages, proposals, decisions, the apply log and locks; an admin console on Next.js with the review inbox, site settings and sync jobs; and the Cafe24 Admin API for product description and SEO fields through a throttled client. Shared: Workers KV, with site keys for config per host, page keys for payload per URL and special keys for llms.txt and robots.txt; and Analytics Engine, holding bot visits and AI-referred visitors per host. Edge: a visitor or AI crawler, receiving the same response for both; an edge Worker that reads KV on every request and rewrites HTML in a stream; and the client origin, fetched once and never retried. The console writes to KV with a sync labelled plan, then apply. KV is read per request by the Worker. The Worker records to Analytics Engine, which the console reads back.
Figure 1. System architecture. The console writes to Workers KV through a sync job. The Worker reads KV on every request and rewrites the origin's HTML. Observation flows back through Analytics Engine.
ComponentTechnologyResponsibility
Admin consoleNext.js, TypeScript, server actionsReview inbox, per-site policy and kill switch, sync jobs, history
Core libraryTypeScript packageProposal generation, policy rules, KV key and payload planning, the Cafe24 client
DatabaseMongoDB replica set through PrismaSites, tokens, pages with proposals and decisions, jobs, the apply log, locks, measurements
Edge WorkerCloudflare Workers, HTMLRewriterRoutes each request, fetches the origin once, merges the payload into HTML
Edge storeWorkers KVPer-host site config, per-URL page payloads, llms.txt and robots.txt
ObservationWorkers Analytics EngineBot visits and AI-referred visitors, by host and path
Platform clientCafe24 Admin API over OAuthProduct reads and writes for shops on that platform
CIGitHub ActionsLint with zero warnings, type-check, tests against a real MongoDB replica set, a build with no database URL

KV is the contract

The Worker reads KV through a binding. The console writes KV through Cloudflare’s REST API. Neither imports the other’s code and neither makes a network call to the other.

Key familyValueRead by the Worker
site:<hostname>Whether injection is enabled, how to reach the origin, paths to bypass, which query parameters identify a pageOn every request
page:<hostname>:<path> plus selected parametersThe payload for that URL: structured data to merge, and an optional visible summary that is off by defaultOn every HTML response that passes the guard
special:<hostname>The text of llms.txt and robots.txtOn requests for those two paths

Two details of the key design carry weight.

A page key uses only the query parameters the site declares. A product page identified by ?product_no=12 gets its own key. A visit that arrives with advertising and analytics parameters appended still finds it, because undeclared parameters are dropped and the declared ones are sorted before the key is built.

The key format exists in two codebases. The Worker bundle does not import the core library, because every kilobyte in the bundle is latency on a client’s traffic. The format is therefore written twice, and a test in the core library pins it as a literal string, so a change on the console side is caught before a sync writes keys the Worker will never read.

Sync

Approving a proposal changes the database. Getting it to the edge is a separate job with its own rules.

A row of five boxes: pending, where a proposal waits for a person; taken, adopted as an apply target while the page is unchanged; sync plan, showing what would be written and deleted first; apply, where KV is written first and the database is marked after it succeeds; and on the page, where the Worker reads it on the next request. From pending a dashed arrow leads down to skipped, passed over and not proposed again. From taken an arrow leads down to applied, for work a web team ships, where a person records the date. From apply an arrow leads down to the apply log, holding before and after values, who decided and which scope. Notes: a site's write scope starts at off, which makes zero writes whatever is approved; a kill switch per site turns the Worker into a plain pass-through; a decision can be returned to pending; and turning the scope off recalls what was already shipped.
Figure 2. From a pending proposal to the page. Approval and shipping are separate steps, and the apply step writes the edge store before it marks the database.
  1. Plan by default. The job runs as a plan first. It prints the keys it would write and the keys it would delete, and writes nothing. A person reads it, then runs it again with apply. The console’s button does the same in two steps. A button is easier to press than a command line, so the plan is the one defence against shipping by reflex.
  2. Write before delete. When a page moves to a new URL, its new key is written before its old key is removed. A crawler arriving in between finds content at one of them.
  3. The database is marked after KV succeeds. A page is recorded as synced, with a hash of what was sent, only once the KV write has returned. A failed write leaves no false record of having shipped.
  4. Everything is logged. Each write produces an apply-log row with the value read from KV before the write, the value after, who decided, and the site’s write scope at the time. Failures and recalls are logged too.
  5. Turning the scope off recalls. Setting a site’s write scope to off deletes the page keys that were shipped and keeps the site key with injection disabled, so the origin and bypass settings survive. A lock that leaves yesterday’s content visible is not a lock.

Data

MongoDB runs as a replica set because Prisma needs transactions.

CollectionHolds
SitesThe channel type, platform and proxy settings, the write policy, the kill switch
TokensPlatform credentials, encrypted, in their own collection so that a screen listing sites cannot leak one
PagesA URL with its extracted facts, its proposals, the decision on them, the payload, and what was last synced
JobsSync and diagnosis jobs with the plan output a person read before applying
Apply logOne row per write: target, channel, before, after, decided by, scope, result
LocksNamed locks with an owner and an expiry
Measurements, signalsResults of visibility checks and daily counts read back from the edge

Observation

The Worker counts two things: visits by known crawlers, and people who arrive from an AI assistant’s answer. Ordinary visitors are not counted by the Worker. Separately, a site that has agreed to it can have an analytics tag added to its pages, which is off unless configured.

The first version kept daily counters in KV. KV reads are cached at each edge location for about a minute, so two visits inside that window each read the same old count and one increment was lost. A controlled check lost 20 to 42 percent of sequential visits. Counting moved to Analytics Engine, which appends events and has no read step.

Platform limits the design absorbs

LimitWhat the code does
KV reads are cached for about a minuteThe kill switch takes up to a minute to take effect, which is documented. Counting moved off KV
A KV key is limited to 512 bytes, and one Korean character in a URL is nine bytes once encodedKeys are measured before sync, and a page whose key is too long is reported instead of failing the batch
A streaming rewrite changes the body lengthThe content-length header is removed from rewritten responses
Overriding the Host header for an arbitrary origin is an enterprise featureAn explicit-origin mode rewrites the request URL, and a second mode passes the request through for origins that route by Host
Proxying a bare domain is an enterprise featureOnly the www host is proxied, and the client makes it the canonical address

Deployment

The admin console deploys on a push to the main branch: the quality gate, a build, a copy to the server, then an activation script that takes a hard-link snapshot, syncs the schema, reloads the process and checks health. A failed health check restores the snapshot. The health check queries the database, because a check that skips the database reports healthy when the application cannot serve a single page.

The Worker is deployed by hand. Client traffic passes through it, and a pipeline for it waits on an approval gate.

Decisions

1. Change the response on the server. Asking a client to paste one line of JavaScript is the easy integration. AI crawlers do not execute JavaScript, so content added that way is visible to people and invisible to the readers it was written for.

2. The relay is the last channel to reach for. A DNS change is the largest thing to ask of a client, the relay becomes a point of failure, and its cost grows with the client’s traffic. Platform API first, source second, relay when neither is available.

3. Payloads are computed ahead of time. No model is called while a request is being served. A model call in the request path adds its latency to every page view, turns a model outage into a site outage, and makes cost proportional to traffic.

4. Fail open. Any exception returns the origin’s response. This is what decides whether a relay can be offered to a client at all.

5. Never retry the origin. A second fetch would fail on a body that has already been read, would submit a POST twice, and would double the load on an origin that is already struggling. A dead origin is answered with a 502.

6. A malformed safety setting disables the site. If the list of bypass paths is present and unreadable, the Worker does not fall back to an empty list and carry on. It turns injection off for that site. A safe failure does nothing at all.

7. Merge into the site’s structured data. The first design appended a second block. Two Product blocks on one page can cost the page its rich result in search, and the client’s rating and price display was at stake.

8. The lock lives in MongoDB. A lock that guards a token refresh has to fail closed: if two processes both believe they hold it, both refresh and the token dies. A unique index gives that, in a database the console already depends on, and a refresh happens about once every two hours per client.