System Architecture & Actors
This document describes Questarr’s system design: the actors (subsystems and external entities that can influence one another) and the data flows between them. It complementsCLAUDE.md, which covers code-level
conventions rather than system design, and docs/API.md /
docs/SECURITY_ASSESSMENT.md, which cover the
external interface and risk-assessment angles of the same system.
Update policy: update this document whenever a PR introduces a new actor
(a new external integration, download client, or background job) or changes
how data flows between existing actors.
1. Overview
Questarr is a three-layer TypeScript application in a singlepackage.json
(not a monorepo):
/client— a React 19 single-page app (Wouter routing, TanStack Query for server state)./server— an Express REST API plus a Socket.io WebSocket channel./shared— the Drizzle ORM schema and Zod validation schemas used by both sides.
DB_DIALECT=postgres and DATABASE_URL; see DATABASE.md for setup
and migration. The storage facade keeps the same API for both implementations.
2. System actors
An “actor” here is any subsystem or entity that can influence another part of the system — by writing data, triggering a request, or emitting an event.3. High-level data flow
Direct Steam owned-library import
The browser’s Settings → Integrations view preselects untracked owned Steam games, with search and 50-row preview pages.steam-library-routes.ts provides preview,
synchronous compatibility import, bulk-job start, progress and retry endpoints
behind the authentication/CSRF boundary. steam-library-jobs.ts persists one
latest job per account under steam.library.import.<userId> in system_config:
linked Steam identity, selected app IDs, results and state. No credentials are
stored in the job, and no schema migration is required.
The worker rechecks the saved account identity and Steam ownership once per run,
including after restart. steam-library-import.ts processes bounded 50-game
batches, loading the library/filter preferences and fetching IGDB mappings and
metadata per batch. Imports opt into strict IGDB lookups: configuration/request
failures stop the batch with a retryable checkpoint, while successful lookups
with missing mappings remain completed skips. New rows use schema validation, exact IDs, content filters,
and initial release-status normalization. Existing entries may gain a missing
Steam App ID but retain their status/progress. No files/download clients are
involved. Each changed batch emits an owner-scoped gameUpdated event; the
app-wide listener refreshes the Library even after Settings is closed and reconciles
missed updates when the socket reconnects. The synchronous endpoint shares the same batch implementation and
per-account process lock.
A checkpoint is saved after every batch. Startup resumes pending/running jobs
before accepting requests. Replaying a partially committed batch safely dedupes
existing game rows. A failed worker/checkpoint is exposed as retryable progress;
GET status does not mutate storage. Retry starts a new job that carries the
finished outcomes and then processes only failed and unprocessed IDs. The checkpoint keeps
compact [steamAppId, outcome] rows, plus titles for the ten recent results only, because it is
rewritten after every batch. Progress polling survives navigation and shows
the latest job, counts and ten recent results. This is a single-server worker,
consistent with Questarr’s supported single-instance deployment, not a distributed
queue. Manually started jobs are separate from scheduled wishlist sync.
4. Example flow: search, select a release, download
5. Request/response flow
Every REST call follows the same path: Client → routes (server/routes.ts
et al., validated via express-validator/Zod) → storage.ts (Drizzle ORM
queries against shared/schema.ts) → JSON response. Routes never touch
the database directly — all reads/writes go through storage.ts, which is
the only module importing the Drizzle db client for application data.
6. Out-of-band channel: Socket.io
server/socket.ts gates every connection with an io.use handshake check
(server/socket.ts:32-50): the socket must carry the auth cookie (from a
trusted Origin) or a bearer token that verifyAuthToken accepts, otherwise
the handshake is rejected with “Authentication required”. On a successful
handshake the socket joins a per-user room, user:<id>, before the
connection completes, so a notification fired right after connect can’t miss
it.
notifyUser(type, payload, userId?) (server/socket.ts:149-162) routes
events in one of two ways:
- With an owner (
userIdset):io.to("user:<id>").emit(type, payload). Only that user’s sockets receive the event. Everynotificationemit passes the notification’suserId, so in-app notifications reach only the account that owns them. - Without an owner (
userIdomitted or null):io.emit(type, payload), a broadcast to every authenticated socket. Ownerless notifications and app-wide events (downloadUpdate,importTaskUpdate,gameUpdated,library-scan-progress, and thelogLinelog stream) still go to everyone.
"notification"— emitted from bothcron.ts(game updates, download completion, auto-search results, xREL matches) androutes.ts; consumed byclient/src/components/NotificationCenter.tsx."downloadUpdate"— emitted fromcron.ts::checkDownloadStatuswhenever a tracked download’s status changes; consumed byclient/src/components/GameDetails.tsxto refresh download state for the affected game.
7. Scheduled/background actors (cron jobs)
server/cron.ts::startCronJobs() schedules seven recurring setInterval
jobs. The five primary sync/check jobs below also run once on an initial
10-second delayed startup; startCronJobs() additionally runs
logClientVersions (every 12 hours, probes configured indexer/downloader
client versions for logging) and a daily import-task cleanup (deletes
import_tasks rows older than 30 days), neither of which reads/writes
domain data covered by this table:
RSS scheduled and manual full refreshes share an in-flight promise. Full and
single-feed refreshes use one queue to prevent overlapping writes and duplicate
items. New-feed refreshes join that queue rather than racing the hourly check.
Root-folder discovery lives in Library → Library Import. Add/enable/path
changes and enabling post-processing trigger scans; changes during a running
scan queue a follow-up.
library-scan-progress carries scan timestamps and
counts. Clients invalidate games after new matches or a scan finishes (including
failure after partial writes), and refresh review candidates when progress changes.
Unmatched-folder IGDB name searches update candidates without importing; explicit
confirmation writes the game and file records. See LIBRARY_IMPORT.md.
Steam wishlist sync (syncUserSteamWishlist in server/cron.ts) also runs
on-demand when a user explicitly triggers it via
POST /api/steam/wishlist/sync (server/steam-routes.ts:37-56). The
scheduled path is opt-in per user (userSettings.steamSyncEnabled, default
false) with a configurable interval (userSettings.steamSyncIntervalHours,
default 24) tracked via userSettings.lastSteamSync.
8. Trust boundaries
- Browser ↔ Server is the primary trust boundary. The client is treated
as fully untrusted; every write path is re-validated server-side
(
express-validator/Zod) regardless of client-side checks, and all non-public routes require a valid JWT (authenticateToken,server/auth.ts:104-126). - Server ↔ third-party services is a secondary boundary, mediated by
server/ssrf.ts::safeFetchfor outbound calls whose target host is wholly or partly user-supplied (indexers, download clients, HowLongToBeat, NexusMods, Steam).safeFetchblocks link-local/cloud- metadata/broadcast ranges unconditionally, and re-validates every resolved IP to guard against DNS rebinding (server/ssrf.ts:4-18,181-249).allowPrivatedefaults totrue(server/ssrf.ts:19-22,86), i.e. private/ loopback ranges are reachable by design — Questarr is meant to be self-hosted alongside indexers/downloaders that often live on the same LAN. server/igdb.tsalso routes its Twitch/IGDB requests throughsafeFetch, consistent with every other integration, even though the target host (api.igdb.com/id.twitch.tv) is hardcoded rather than user-supplied — applied as defense in depth rather than out of SSRF necessity.
docs/THREAT_MODEL.md for a more detailed attack-surface
analysis of these trust boundaries (per-integration trust table, high-risk
data flows, and the unauthenticated-route inventory).
9. Multi-user status
Questarr is not, and is not planned to become, a multi-user application for the foreseeable future. The supported deployment is one trusted operator per instance (seedocs/PRD.md §6 Non-Goals and §8
Technical Constraints, and ../GOAL-product.md).
The schema and auth layer nonetheless have partial multi-account
plumbing, which predates this decision and should not be read as a
roadmap signal: a users table exists, authenticateToken resolves a
per-request req.user.id from a JWT, and personal-library tables
(games, user_settings, notifications, import_tasks, api_keys,
integration_requests, release_blacklist) carry a userId column. Instance-wide config and
shared runtime state — indexers, downloaders, root_folders,
rss_feeds, game_downloads — deliberately carry no userId, since
they represent one server’s shared configuration, not per-account data.
Because of this, account isolation is inconsistent by design, not a defect
to eliminate wholesale:
- Some code paths do scope by
userId(e.g.resolveOwnedGameinroutes.ts, and the igdbId-reuse checks before reusing an existing game record), because getting those specific paths right also happens to be good practice regardless of user count. - Others intentionally don’t:
notifyUser()still broadcasts app-wide Socket.io events (download, import, and scan progress) to every connected client, though owned notifications go only to their user’s room (§6);library-scanner.ts’s scan state (getAllUnmatched,getAllScanProgress) is global, matchingroot_foldersbeing global; download clients and indexers are shared instance configuration, not per-user. - The trust model is flat with no RBAC/admin split (see
docs/THREAT_MODEL.md§8, “Flat, single-tier trust model” — accepted risk).
userId scoping already present in the schema.