The useful local environment is the one that lets me inspect the same boundaries my application will use elsewhere.

A tiny service deserves a comprehensible development loop

The reading side of my blog is static. Comments introduce one small dynamic requirement: receive a submission, store it as pending, and let me decide whether it becomes public. A private contact form adds another table and a different publication policy. These are useful features, but their size should remain visible in the tools used to develop them.

I wanted to run the Worker locally and inspect real database behavior. I also wanted to keep Node.js and the Wrangler CLI out of the local runtime. That preference led me to the underlying pieces: native workerd, a D1 binding, persistent storage, and a small amount of explicit configuration.

<a href="https://github.com/cloudflare/workerd">workerd</a> is Cloudflare's open-source Worker runtime. It can run outside Cloudflare's service. That makes it a useful foundation for this experiment: the request handler executes in the Worker runtime itself, while I supply the local services and bindings it depends on.

A SQLite file is only one part of D1

My Worker uses env.DB.prepare, bind, first, and run. Giving it a SQLite executable would leave that programming interface unresolved. The local setup needs both storage and the adapter that presents storage through the expected D1 API.

In this project, the application's DB binding is a wrapper around workerd's built-in D1 API module. It connects to a D1 entry Worker, which addresses a SQLite-backed Durable Object. The entry and database Worker modules come from a pinned Miniflare distribution. Those modules execute inside workerd; the Node-based Miniflare host and its CLI are absent from the running service.

The database Worker configuration includes nodejs_compat. That enables compatibility APIs inside workerd for the library code. It does not start a separate Node.js process. Keeping that distinction clear makes the installation easier to explain: I am using native workerd plus selected Worker modules, with their actual runtime requirements recorded in configuration.

HTTP request
    → application Worker
    → env.DB / D1 API wrapper
    → D1 entry Worker
    → SQLite-backed Durable Object
    → persistent local disk

Keep the application boundary familiar

The handler is ordinary Worker JavaScript. It receives a request and an environment, reads form data, validates the submission, and uses bound SQL parameters. WSH does not execute inside the Worker. In my setup WSH is an authoring and administration environment on the Windows machine; workerd is the HTTP execution environment on the Pi.

That separation lets each side stay small. The public Worker handles comments and contact messages. A separate administration Worker accepts authenticated database operations on a loopback listener. My management tools reach that private listener through SSH. Database files and the administrative credential stay on the Pi, outside the static site's published files.

const original = await env.DB.prepare(`
  SELECT name, comment
  FROM comments
  WHERE id = ? AND post_id = ? AND status = ?
`).bind(replyId, postId, 'approved').first();

This is the shape of the quoted-reply lookup. The selected message must belong to the same article and already be approved. The service obtains the original author and text from storage, then saves a quotation snapshot with the new pending comment. It does not trust quotation text supplied by the browser.

Exercising that behavior locally tells me something useful. I can submit a valid reply, try an unavailable target, inspect the saved quotation, and confirm that the reply remains pending. A stub that always reports success would miss the relationships that make the feature work.

Installation is part of the experiment

The Pi exposed a practical runtime issue. Its kernel uses a 39-bit virtual address configuration, and the initial runtime binary aborted because its allocator expected a larger address space. The working setup uses a community build of workerd with tcmalloc disabled. That choice is recorded alongside the pinned version and checksums; it should not be mistaken for a requirement of every Linux machine.

The installation scripts download and verify the selected runtime and library artifacts. Configuration declares services, modules, sockets, bindings, and persistent storage. A deployment script reloads the service and applies the idempotent schema. A health endpoint runs a database query, so a healthy response means more than an open TCP port.

I keep persistent state separate from installed binaries. Replacing runtime files should not casually replace the database. A systemd user service manages the process. On this machine user lingering is not enabled, so startup before login is a separate operational decision. Small details like this belong in the project notes because they affect whether the local environment is actually available.

Moderation and publication are separate steps

The most satisfying part of this arrangement is what the browser does not need to coordinate. A comment submission goes to the Worker. Approval changes the database. An export selects only approved public fields. The blog build renders that snapshot into article HTML. Readers receive the result as part of the same static document they were already requesting.

Locally, notifications go into outbox tables. Testing a form does not send an email. Contact messages use a separate private table and are never selected by the comment export. This gives me a clear way to inspect both features without mixing private correspondence with public conversation.

The administration commands are written in LiveScript, bundled by lsdep, and executed as WSH JScript. They use SSH to reach the Pi's private query helper. That is a comfortable fit with the rest of my tooling: the web endpoint runs where a Worker belongs, and the management tasks run in the environment I prefer for scripting.

Close enough to learn the right things

This setup reproduces a useful local runtime and database interface. It does not reproduce Cloudflare's distributed infrastructure, deployment controls, or every production limit. The internal adapter and pinned Worker modules are explicit dependencies that I will need to revisit when upgrading. That is an acceptable maintenance boundary for this experiment.

Cloudflare documents its supported <a href="https://developers.cloudflare.com/d1/best-practices/local-development/">local D1 development workflow</a>. My arrangement deliberately assembles the lower-level pieces for my own environment. The payoff is a short loop: edit a handler, reload it, submit a real form, inspect persistent state, approve a comment, rebuild, and see the published HTML. Each step is visible, and each failure has somewhere concrete to investigate.