# How dropshelf works

Source: https://dropshelf.ai/docs/reference/project/architecture

The shape of the dropshelf server, for operators, security reviewers and contributors who want to understand its design.

This page describes the shape of the dropshelf server: how a version goes live, what each replica
caches, how the two kinds of host are kept apart and what runs in the background. It is for
operators, security reviewers and contributors. The [security model](/docs/reference/project/security)
covers the defences that rest on this design.

## One deployable [#one-deployable]

dropshelf ships as one image, `ghcr.io/dropshelf/dropshelf:<version>`, for `linux/amd64` and
`linux/arm64`. It is built on `gcr.io/distroless/static:nonroot`, so it carries no shell. The server
runs as UID 65532 and expects a read-only root filesystem. It needs two writable mounts:
[`server.spoolDir`](/docs/reference/configuration#server) for uploads and
[`cache.dir`](/docs/reference/configuration#cache) for the object cache.

The recommended install is the Helm chart at `oci://ghcr.io/dropshelf/charts/dropshelf`. It is
published at the same version as the image. Its `config` value becomes the server's configuration
file as it is. By default the chart runs two replicas behind a rolling update.

Configuration is one YAML file. Every key also has an environment variable, so `server.baseDomain`
is `DROPSHELF_SERVER_BASE_DOMAIN`. A container can run from the environment alone, with no file.
Secrets belong in the environment, never in the file.

## Immutable versions [#immutable-versions]

Each upload, called a deploy in the API and the configuration, writes its files under
`drops/<drop-id>/<deploy-id>/` in the bucket. A manifest goes beside them. Publishing then moves the
drop's pointer to the new version in one database transaction.

Nothing is overwritten in place. That has three consequences:

- Neither cache ever needs invalidating, because a key always names the same bytes.
- A `304 Not Modified` is answered from the manifest without touching the bucket.
- The previous version keeps serving until the new one is live.

An upload sent with `publish=false` ends as a draft instead. Any kept version can be made live
again, so the pointer moves backwards as well as forwards. The reaper deletes the files of versions
beyond the kept counts, [`deploy.keepHistory`](/docs/reference/configuration#deploy) and
`deploy.keepDrafts`, once `deploy.supersededGracePeriod` has passed.

## Two caches per replica [#two-caches-per-replica]

Parsed manifests stay in memory. The server consults one on every request to resolve the path and
to answer a 304 or a 404 without touching the bucket.
[`cache.manifestMaxBytes`](/docs/reference/configuration#cache) bounds it, at 40 MB by default.

Object bytes are cached on a local disk volume, `cache.dir`. Each object is a file named by the
hash of its key, so names that members chose never reach the filesystem. The cache is a
least-recently-used store bounded in bytes, 1 GB by default. Many visitors missing the same object
at once fill it once. A cache error never fails a request: the server reads from the bucket
instead.

Both caches belong to one replica and are disposable. The disk cache is emptied at every start.

## Two host classes [#two-host-classes]

`drop.example.com` is the control plane: the dashboard, the API, the sign-in routes and the
discovery routes. `<name>.drop.example.com` is a drop host. The server tells them apart by comparing
the request's host with [`server.baseDomain`](/docs/reference/configuration#server).

The two share a listener and nothing else:

- A drop host never reads the dashboard's cookie, and the control plane never reads the visitor
  cookie.
- Drop responses carry `frame-ancestors 'self'` plus the dashboard's host. The dashboard's viewer
  can show any drop the reader may see, and no other page can frame one.
- Control-plane responses carry `frame-ancestors 'none'` and `X-Frame-Options: DENY`, so no page can
  frame the dashboard to trick a click on **Delete**.

Every drop shares a site with every other drop. Without that framing rule, one drop could frame a
restricted drop and carry the reader's access into a page it controls.

While the viewer shows a drop, a link in it that leads to another site opens in a new tab. Most
sites refuse to be framed, the dashboard among them, so the frame could not show the page. Links
between the drop's own pages stay in the frame.

A version's preview address, such as `v7--blog.drop.example.com`, is a drop host like any other. It
is one label, so the wildcard certificate and the wildcard Ingress rule already cover it. Only people
who can edit the drop can open it. That leaves `blog.drop.example.com` free to always serve the live
version.

## Two cookies carry identity [#two-cookies-carry-identity]

`__Host-dropshelf_session` is the dashboard's cookie. A browser accepts a `__Host-` cookie only from
the exact host, with `Secure`, `Path=/` and no `Domain`. A page on a drop host therefore cannot
plant or replace it.

`__Secure-dropshelf_visitor` is set with `Domain=.drop.example.com`. It is what lets a signed-in
member open a drop.

Both cookies are `HttpOnly`, encrypted and authenticated. The cookie's kind is bound into the
encryption, so one kind never verifies as the other. A third cookie, `__Host-dropshelf_auth`, lives
only for a sign-in, at most 10 minutes. Over plain `http`, which is for local development only, the
prefixes and the `Secure` flag are dropped.

## Retention and the reaper [#retention-and-the-reaper]

Each drop has a retention policy: a number of days, or Forever. Its expiry time is derived from that
policy, and every publish recomputes it from the time of the publish.

A background reaper runs every [`reaper.interval`](/docs/reference/configuration#reaper), 60 seconds
by default. Each run does the following:

- It expires drops whose retention has passed.
- It purges the files and rows of deleted drops.
- It fails deploys whose lease lapsed because the replica holding them stopped.
- It deletes the files of versions beyond the kept counts.
- It removes expired agent sign-ins, upload tickets and read notifications.

Every step claims its rows with a lease. Several replicas can run the reaper at once without doing
the same work twice. A step that stops halfway leaves its lease, and a later run retries it once the
lease lapses.

## People [#people]

Every member has a profile page with a picture, a short bio and their drops. Another member sees only the
drops they may open. On your own profile, the drops you bookmarked appear too.

Any member who can see a drop can like it, comment on it and bookmark it. These routes find the drop
the way the rest of the API does. A drop you may not see answers them as though it did not exist.

Likes and comment counts belong to the drop, and everyone who can see it sees them. A bookmark is
private. It is listed by a route that reads the session and takes no member id, so it appears in
nobody else's answer.

A profile picture is one object per member under `users/` in the bucket. It is raster only and
replaced in place. The control plane serves it to signed-in callers, so a browser never reads the
bucket.

## The MCP server is a client of the API [#the-mcp-server-is-a-client-of-the-api]

Every tool at `/mcp` is an HTTP request to the API in the same process. It carries the caller's own
bearer token. The MCP server holds no database, no bucket and no deploy logic of its own, so it
cannot do anything the API would refuse.

Agents sign in through an OAuth server that issues ordinary [personal access tokens](/docs/use/tokens),
each tied to that sign-in. Past the token check, an agent signed in with OAuth is a token like any
other.

## Related topics [#related-topics]

- [Security model](/docs/reference/project/security)
- [Releases and versions](/docs/reference/project/releases)
- [Configuration reference](/docs/reference/configuration)
- [Install with Helm](/docs/self-host/install/helm)
- [Monitor an instance](/docs/self-host/operate/monitor)
