FodyChat

Self-hosting, honestly: from a Cloudflare account to a docker compose up

What 'self-host' actually means for an AI chat — and the ports-and-adapters work that turned it from a pricing-page promise into a real Docker image.

A terminal showing docker compose up: migrate, web, and cron services, backed by SQLite/Postgres, Redis, pgvector and S3

We sell a self-host tier. The promise on the pricing page is “your data stays with you, the code is yours forever.” For a long time, what we could actually hand over was smaller and more awkward: the source code, a wrangler.toml, and a set of instructions for deploying it into your Cloudflare account.

That is not self-hosting. That is a different Cloudflare account with extra steps.

This is the story of what it took to make the promise honest — and what “self-host” has to mean for a product that is mostly an AI model talking to a database.

The trap was in the word “self”

“Self-host” is a dangerous phrase because it hides the work. A customer hears it and imagines a Docker image they can run on their own server. An engineer hears it and imagines: the code runs somewhere the customer controls, with their keys, and their data never leaves.

Cloudflare-native code does not do that. Workers, D1, R2, KV, Vectorize, Workers AI — each one is a binding on a shared env object, and each one is only available inside Cloudflare’s runtime. The code could not leave. We had built a recipe that only cooked in one brand of oven.

So we did the boring thing first: we grepped our own codebase and counted the bindings. The answer was a short list — a database, a key-value store, a vector index, an AI provider, object storage, and the runtime itself. Six things. But six things, each one touched in a dozen files, is a wall if you treat them as a wall.

The trick was to stop treating them as a wall.

The method: ports, not a rewrite

There is an old name for what we did next, and it predates serverless: ports and adapters. A port is an interface that describes what the code needs. An adapter is the thing that satisfies it. The business logic talks to the port. Cloudflare becomes one adapter among several.

The database port is embarrassingly small, because the slice of D1 we actually used was tiny:

interface DbStatement {
  bind(...params: any[]): DbStatement;
  all<T>(): Promise<{ results?: T[] }>;
  first<T>(column?: string): Promise<T | null>;
  run(): Promise<{ meta?: any }>;
}
interface Database {
  prepare(query: string): DbStatement;
  batch(statements: DbStatement[]): Promise<unknown[]>;
}

Five methods. Behind it, an adapter can point at D1, at better-sqlite3 on a Node server, or at Postgres through a thin shim. Same SQL, same schema. The same pattern now covers the key-value store (KvStore: get/put/delete/list — Cloudflare KV, or Redis, or an in-process map), the vector index (VectorStore: query/upsert/deleteByIds — Vectorize, or pgvector, or in-memory cosine), AI (a provider switch that already existed), and object storage (an StorageProvider with R2 and S3 implementations).

The runtime was the last and hardest port. A Cloudflare Worker has email() for inbound mail, scheduled() for cron, and a SELF binding for self-fetch — none of which exist on a plain Node server. Each one has a mundane replacement: an inbound-email webhook, node-cron, and a plain fetch. The email webhook already existed. The cron sweep was extracted into a shared module. SELF simply falls back to fetch when the binding is absent, which is exactly what Node wants.

None of this removed Cloudflare. The SaaS still runs there, because it is genuinely cheap and genuinely zero-ops. We just refused to let it be the only place the product can live.

What self-host now means

Here is the honest deliverable, not the slide-deck version:

The widget — the thing the customer actually embeds — was always the easy part. It is a JavaScript file that posts to /api/chat and knows nothing about what sits behind that URL. Point it at https://chat.yourcompany.com/api/chat, and it works. That is the part worth stating out loud, because it is the part most people assume is the whole product. It is not. It is the front door. The building is the model, the retrieval, the tools, and the data.

What still is not done

We document these things honestly, so here is the status:

“Reference” is the honest word. The difference between a reference artifact and a shipped one is not very large, but it is real: it is the difference between “this should work” and “this is working for a customer right now.”

Why this matters

The enterprise buyer is not actually asking “can I run it on my server?” They are asking “can I leave?” — and “if you disappear tomorrow, does my support chat still work?”

A Docker image is the only honest answer to that question. Not because Docker is magic, but because it is the proof that the product is not welded to a vendor. It is the difference between selling “your own Cloudflare account” and selling “your own server.” The first is a hosting detail. The second is the reason someone trusts you with their data.

Vendor lock-in is not a fate. It is a decision you make one binding at a time — or unmake, one port at a time.