Concepts
How it works
The services that make up Hubstruct, what each one does, and how a photo travels through them.
Hubstruct is built from a few services with one job each, all started together by Docker Compose. This page explains what they are, how they talk to each other, and what happens between adding a photo and finding it by searching for what's in it.
The services
| Service | What it does | Needs |
|---|---|---|
console | The app you open in the browser. It draws pages on the server where that helps (your theme and colors, page headers), and passes the browser's calls on to the API. | api |
api | Everything the app can do, as an HTTP API with an OpenAPI reference. Sign-in, permissions, lists, search, edits, uploads, and the live stream of changes. | postgres, storage, models |
worker | All background work: the processing steps, keeping album rules current, suggesting people and putting media in places. | postgres, storage, the models |
migrator | Runs once at every start: applies any database changes the new version brings, then exits. Everything else waits for it. | postgres |
postgres | PostgreSQL 18 with pgvector: the media, tags, albums, people, the embeddings and the indexes that search them. | |
storage | Garage, an S3-compatible object store: libraries' originals and renditions, and the pictures Hubstruct makes itself, such as album mosaics. | |
models | llama.cpp, one server per model, started as needed: Gemma (descriptions, titles, reading text), EmbeddingGemma (the embeddings for search and similarity) and d1, the classifier behind smart tags and NSFW scores. | GPU |
vision | Image models over HTTP: the face detectors and embedders (real and drawn faces), and the text detector. | GPU |
Architecture goes into ports, volumes and health checks.
The app never touches the database
The browser talks only to console, on one address. Calls to /api/… are passed on to the API by the app's own server, so the browser never needs to reach the API directly and the session cookie stays on one origin. When the app draws a page on the server, it calls the API over Compose's private network.
The API is the only thing that reads and writes on behalf of people. The worker writes too, but only the results of its own work.
No queue: work is worked out from the data
Most systems like this put jobs on a queue. Hubstruct doesn't. Instead, each processing step has a processor in the worker that asks the database a question: which media need this step right now? The answer comes from a view that compares what each media has with what the step needs:
- Has the step never run on it? It's due.
- Did the step fail, and has its back-off time passed? It's due again.
- Has something it depends on changed since it last ran, such as the text an embedding was made from? It's due again.
- Are the steps it depends on done? If not, it waits.
Each run is recorded on the media: when it started, how long it took, which model ran, and what went wrong if anything did. That record is what the dashboard shows.
Because the database is the only source of truth:
- Nothing is lost on a restart. The worker asks the same question again and carries on.
- Turning a model off pauses its steps. A processor only takes work while the model server it needs answers its health check. Stop
models, and the steps that need it simply wait. - Changes re-trigger the right work. Edit a title and the embedding is redone; add a smart tag and every media is scored for it; nothing has to be queued by hand.
- Several workers can share the work. Taking a media is a conditional write that only succeeds once, so two workers never do the same thing. See Scaling.
From a photo to a search result
Here is what happens when you upload a photo to a library:
- The upload streams the file straight into storage, never holding it in memory, and creates its row. The page shows it at once.
- metadata reads what the file is: its size, how long it is if it's a video, when it was taken (from EXIF) and its ThumbHash, a tiny blurry placeholder.
- renditions makes a thumbnail and a preview (for a video, from a frame a moment in).
- In parallel, the rest begin:
- analysis measures colors, sharpness and exposure, and a perceptual hash;
- visual makes an embedding of the pixels alone;
- tagging asks the classifier about each smart tag;
- nsfw asks it one more question;
- text finds any text and reads it;
- faces finds the faces and embeds each one;
- description, then title, have Gemma describe it.
- duplicates compares its hash and image embedding with the rest of the library.
- embedding combines everything written about it (titles, descriptions, the text in it, its tags) with its picture into one vector. This is what search, similar media and album rules compare.
- Meanwhile, the worker's people pass places its faces with people, and the albums pass adds it to any album whose rules it now matches.
Each finished step announces itself, and open pages update within about a second. See Live updates.
Where things are kept
| What | Where |
|---|---|
| Media rows, tags, albums, people, faces, embeddings, settings, accounts | PostgreSQL |
| Libraries' originals, thumbnails and previews | Storage, under libraries/<id>/ |
| Album, tag and person mosaics (the cover pictures) | Storage, made on demand and cached |
| Models | The models volume |
Secrets
Secrets Hubstruct keeps in the database are encrypted with the app secret (APP_SECRET, or one derived from POSTGRES_PASSWORD if it's unset). Passwords are hashed with scrypt; sessions and API keys are stored only as SHA-256 hashes, so the database's contents can't be used to sign in.