Blog

How this site is built

One Rust binary serves every site of yaroslav-zhurbilo.dev. Here is how it is put together, and why I kept it this small.

This site is not one site. The home page, the CV, this blog, the courses, the services page and the admin app all live on their own hosts. Behind them is one Rust binary, one Postgres database and one bucket for images. This post is a tour of that binary and of the few decisions that shaped it.

One binary, every site#

The request path: nginx in front, one axum binary that picks the site from the Host header, Postgres and Cloud Storage behind it

nginx terminates TLS and proxies every host to the same process. The first thing the app does with a request is to decide which site it belongs to. That is a middleware that reads the Host header and looks it up in a table: the production host of every site, plus extra hosts from the environment for staging and local runs.

crates/yw-http/src/site_hosts.rs
1/// One `site=host` entry of `YW_SITE_HOSTS`.2pub struct SiteHost {3    pub site: SiteId,4    pub host: String,5}

Staging is the same binary with YW_SITE_HOSTS=blog=blog-stg.…,cv=cv-stg.…. There is no "staging build", only a different table. An unknown host is refused rather than guessed.

Why not a separate service per site? Because the sites share almost everything: the page model, the design system, the image store, the admin API. Splitting them would buy me deploys I do not need and contracts I would have to keep in sync by hand.

The workspace#

The code is a Cargo workspace of small crates, each with one job:

  • yw-domain – plain types: sites, codes, files. No I/O.
  • yw-blocks – the page document: blocks, their kinds and the rules a page must pass.
  • yw-db – every SQL query, checked at compile time by sqlx.
  • yw-http – axum routes, one module per site, and the askama templates.
  • yw-cli – yw, the command-line tool I write content with.
  • yz-website – the main that wires it together.

The workspace lints are strict on purpose: unwrap, expect, panic and wildcard enum matches are denied. A new enum variant then breaks the build in every place that has to decide what to do with it, which is exactly where I want to be told.

Pages are HTML first#

Every public page is rendered on the server with askama. There is no client-side framework on the public sites. The few things that need JavaScript – copying a code block, highlighting the current heading in the contents list, filtering skills on the CV – are small TypeScript islands, built by Vite and loaded only on the pages that use them.

The admin app is the exception: it is a React single-page app, because it is an editor. It talks to the same /api as the yw CLI, so there is exactly one way to change content.

The server is the source of truth

Content is written in a separate Git repository as YAML or Markdown and sent with yw push. The repository is for writing and review; yw pull shows any drift from what the server holds.

Data#

Postgres 17 keeps pages, their blocks, tags and the file records. A page is a list of typed blocks – text, heading, image, code, callout, quote – and every save is checked against the block rules before it is stored. Uploaded images go to a private Cloud Storage bucket and are served by the app itself; that is a story for another post.

Deploys#

A deploy is a shell script, not a pipeline. It builds one linux/amd64 binary in Docker from the committed code, uploads it, starts it on a spare port as a smoke test, swaps it in while keeping the previous binary, and checks the health of every site host. Staging deploys only from develop, production only from master.

It is boring, and that is the point: the whole system fits in my head, and a rollback is a file rename.

Share LinkedIn X Email

← All posts · Yaroslav Zhurbilo