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

| Component | Technology | Responsibility |
|---|---|---|
| Admin console | Next.js, TypeScript, server actions | Review inbox, per-site policy and kill switch, sync jobs, history |
| Core library | TypeScript package | Proposal generation, policy rules, KV key and payload planning, the Cafe24 client |
| Database | MongoDB replica set through Prisma | Sites, tokens, pages with proposals and decisions, jobs, the apply log, locks, measurements |
| Edge Worker | Cloudflare Workers, HTMLRewriter | Routes each request, fetches the origin once, merges the payload into HTML |
| Edge store | Workers KV | Per-host site config, per-URL page payloads, llms.txt and robots.txt |
| Observation | Workers Analytics Engine | Bot visits and AI-referred visitors, by host and path |
| Platform client | Cafe24 Admin API over OAuth | Product reads and writes for shops on that platform |
| CI | GitHub Actions | Lint 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 family | Value | Read by the Worker |
|---|---|---|
site:<hostname> | Whether injection is enabled, how to reach the origin, paths to bypass, which query parameters identify a page | On every request |
page:<hostname>:<path> plus selected parameters | The payload for that URL: structured data to merge, and an optional visible summary that is off by default | On every HTML response that passes the guard |
special:<hostname> | The text of llms.txt and robots.txt | On 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.

- 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.
- 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.
- 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.
- 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.
- 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.
| Collection | Holds |
|---|---|
| Sites | The channel type, platform and proxy settings, the write policy, the kill switch |
| Tokens | Platform credentials, encrypted, in their own collection so that a screen listing sites cannot leak one |
| Pages | A URL with its extracted facts, its proposals, the decision on them, the payload, and what was last synced |
| Jobs | Sync and diagnosis jobs with the plan output a person read before applying |
| Apply log | One row per write: target, channel, before, after, decided by, scope, result |
| Locks | Named locks with an owner and an expiry |
| Measurements, signals | Results 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
| Limit | What the code does |
|---|---|
| KV reads are cached for about a minute | The 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 encoded | Keys 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 length | The content-length header is removed from rewritten responses |
| Overriding the Host header for an arbitrary origin is an enterprise feature | An 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 feature | Only 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.
