apps/api is the standalone Hono host for mobile/native clients and browser tRPC traffic. apps/worker runs asynchronous jobs on BullMQ.
| Item | Value |
|---|
| Path | apps/api |
| Local run | bun --filter api dev |
| Check | bun --filter api check-types |
| Owns | /api/auth/*, /api/trpc/*, selected image/upload routes, signed /api/webhooks/stripe and /api/webhooks/didit receivers |
| Primary packages | @repo/api, @repo/auth, @repo/database, @repo/integrations |
| Item | Value |
|---|
| Path | apps/worker |
| Local run | bun --filter worker dev |
| Check | bun --filter worker check-types |
| Owns | Search sync, lead ingestion/DLQ, alerts, billing scans, AI jobs, listing-photo sanitize, CDN purge, storage reclamation, account-deletion purge, GET /health, Bull Board |
| Primary packages | @repo/database, @repo/cache, @repo/notifications, @repo/redis-search |
- API behavior usually belongs in
packages/api services and routers, not directly inside apps/api.
- Worker producers and consumers must use the same
QUEUE_SUFFIX in dev.
- The worker serves
GET /health on its one HTTP port (BULL_BOARD_PORT, else PORT, else 3000) in every environment, with no Bull Board credentials: 200 when every started BullMQ worker isRunning() and Valkey answers PING, 503 otherwise, body { ok, valkey, workers }. A new queue must call registerWorker(name, worker) from apps/worker/src/health.ts or the probe will not see it.
WORKER_QUEUES (apps/worker/src/queues-config.ts) picks the queues a worker process consumes: unset is all thirteen; core / media or a list of queue names runs the same image as a pool. Validated at boot (unknown name → exit 1 with the valid list). Each queue’s repeatable jobs are registered by the module that consumes it, so a pool owns its own schedulers and nothing double-fires when two pools run. Add a new queue to WORKER_POOLS and to the guarded imports in index.ts.
- The worker has one shutdown path (
apps/worker/src/shutdown.ts): a single SIGTERM/SIGINT listener closes every registered worker in parallel under a 25 s deadline, flushes Sentry, then exits (1 if anything failed or timed out). A new queue registers its closer with onShutdown(name, () => worker.close()); modules must not attach their own signal handlers. The Railway worker service declares deploy.drainingSeconds: 30 so the platform waits for that deadline instead of sending SIGKILL right after SIGTERM (its default).
- FLUX.2 [pro] staging (Black Forest Labs API) uses the dedicated
ai-staging queue and PostgreSQL as its dispatch/provider-attempt source of truth. BFL_API_KEY lives on the worker only; apps/api holds no AI provider credential and no staging webhook. Follow the staging rollout runbook before enabling paid tasks.
- Listing-photo sanitize runs on the
image-sanitize queue at concurrency: 2, deliberately matching the SHARP_CONCURRENCY semaphore in @repo/integrations so the memory cap is enforced by the queue rather than by a hidden wait. Raw bytes live under pending/properties/… and must never be added to an image-proxy ALLOWED_PREFIXES. Runbook: apps/worker/src/image-sanitize.FEATURE.md.
- Account purges run on the
accounts queue with jobId = account-purge-{requestId} — per request, never per user. A user who restores and later asks again gets a new request row, and BullMQ would silently drop a re-used id while the first request’s job is still retained. The hourly scan skips requests with a PENDING failed_account_purges row; replay with queue:admin retry-purge (see Incident guides).
- Notification payloads must match
@repo/notifications translations and generated Knock docs.