Skip to content

Data model

The app database (hotaru.db) as of SI-523. Schema: packages/core/src/db/schema.ts and auth-schema.ts. Services that read and write it: packages/core/src/services/.

erDiagram
users ||--o{ sessions : ""
users ||--o{ accounts : ""
users ||--o| user_settings : ""
users ||--o| user_quotas : ""
users ||--o| user_model_keys : ""
users ||--o{ subscriptions : follows
users ||--o{ tags : owns
users ||--o{ user_items : ""
users ||--o{ api_tokens : ""
users ||--o{ feed_tokens : ""
users ||--o{ integrations : ""
users ||--o{ item_saves : ""
items ||--o{ item_saves : ""
items ||--o{ item_summaries : ""
stories |o--o{ items : ""
sources ||--o{ subscriptions : ""
sources ||--o{ items : ""
subscriptions ||--o{ subscription_tags : ""
tags ||--o{ subscription_tags : ""
items ||--o{ user_items : ""
users ||--o{ item_pipeline : ""
items ||--o{ item_pipeline : ""
pipeline_batches ||--o{ item_pipeline : ""
item_pipeline ||--o{ item_pipeline_steps : ""
users ||--o{ ai_calls : ""
items |o--o{ ai_calls : ""

Shared and per user

  • Shared, fetched once: sources, items, item_summaries and stories. Also pipeline_batches, the pipeline’s machinery. Two users who follow the same feed URL share one source, so it’s fetched once and its items are stored once. A source is identified by (type, url), an item by (source_id, guid).
  • Per user (user_id on every row, every query filters by it): user_settings, subscriptions, tags, subscription_tags (through the subscription), user_items, api_tokens, feed_tokens, integrations, item_saves, item_pipeline, item_pipeline_steps, ai_calls, taste_reviews, taste_changes, filter_rules, chat_conversations, saved_views, checks, check_answers, user_quotas, user_model_keys, and the auth tables. invites belong to the instance: the admin who made one and the account made with it are linked. Tests check that no route or agent tool crosses between accounts (accounts.md).

Tables

Table What it holds
users, sessions, accounts, verifications Better Auth’s tables, in the shape it expects with usePlural: true and the username plugin (ADR-0003). Set up in auth.md.
api_tokens Personal API tokens: name, prefix, SHA-256 hash (never the token), read or write scope, last use, expiry (auth.md).
feed_tokens The secret of a user’s own feed, such as the starred feed: one per user and kind, prefix and SHA-256 hash, last use. Rotating replaces the row (stream.md).
user_settings One row per user: time zone, and free-form preferences until they earn their own column. preferences holds the account-wide reading preferences: markReadOn, hideShorts, hideLive and dateFormat (stream.md), and gate (gate.md) and summaries (summaries.md) settings.
user_quotas An account’s own limits, set by an admin: sources, text kept, highest AI budget. Null: the instance’s default (accounts.md).
user_model_keys A user’s own OpenRouter key, encrypted, and its last four characters. Set, it pays for the user’s calls (costs.md).
invites Single-use invites to register: a hash of the code, an optional email, who made it, when it expires, was used (and by whom) or revoked (accounts.md).
instance_settings Settings of the whole instance: who may register (registration, accounts.md) and the default quotas (quotas).
sources What gets fetched: type (rss, youtube, web, github, api), URL, type-specific config (JSON), and the fetch state for the scheduler (status, next fetch, interval, failures, ETag, Last-Modified, newest item). The fetcher writes it: feeds. After a permanent redirect, config.previousUrls keeps the old URLs, and findSource() matches them.
subscriptions A user following a source: custom title, weight (SI-538), paused, always_show to skip the AI gate (SI-539), and full_article to load the full article of new items (SI-568).
tags, subscription_tags A user’s labels for subscriptions. Like Inoreader folders: a subscription can have several (SI-515, SI-525). A tag lives as long as a subscription carries it (tags.md).
items One entry of a source: canonical URL, guid, title, author, excerpt, full content, image, media (JSON), publish date. content_extracted_at marks content that is the full article from the page, and extraction_error why loading it failed (stream.md). text, text_source, word_count and text_extracted_at hold the clean text the AI stages read: the article, a video’s transcript, or the feed’s text (extraction.md). YouTube items also have video_kind: video, short or live (youtube.md). search_rowid links the item to its row in the full-text index items_fts, kept in sync by triggers (search.md).
user_items A user’s copy of an item: read, opened (opened_at, a real read, SI-555, stats.md), starred, vote, labels (SI-545, labels.md), whether they split it from its story, the gate’s verdict with jev’s worth, Hype, Facts and Signal (SI-539, gate.md), and the filter rule that mutes it, muted_by (SI-554).
keywords, item_keywords A user’s keywords with their weight and pause, and which of the user’s items have each (SI-537, keywords.md). keywords.topic_id puts a keyword in one of the user’s topics (SI-552).
topics Broader groups over a user’s keywords, made by the AI (SI-552): a name per user (topics.md).
chat_conversations Each user’s agent chat (SI-547): the pi-durable conversation in durable.db that holds it, by ID only (chat.md).
saved_views Views the agent showed that the user pinned (SI-548): a title and the view’s spec, which says what to show, not the items (views.md).
checks A user’s own questions about every item (SI-567): name, icon, kind (yes/no, scale, choice), question, ends or options, colors, order (checks.md).
check_answers The answer to a check for one user’s item: whether it applies, the value, the chosen option, the model. Dropped when the check’s question changes.
filter_rules A user’s filters and mute words (SI-554): name, conditions (JSON), on or off, expiry. A rule mutes the items it matches before the AI pipeline (filters.md).
action_rules A user’s rules: name, conditions (JSON, as a filter rule’s), actions (JSON: mark as read, star, save to Raindrop, send to Readwise Reader or MyMind), on or off, how many items it ran on. Runs on new items as they arrive (rules.md).
taste_reviews, taste_changes The feedback loop (SI-546): what each review learned, and every weight change it made or proposed, so it can be undone (feedback.md).
stories The same news from several sources (SI-540). Shared like items; items.story_id puts an item in one, items.story_joined_at says when (dedupe.md).
story_follows The stories a user follows, and when they last looked at each: later items are its updates (SI-553, stories.md).
item_summaries An item’s AI summary in one language, with key points and the item’s own language (SI-536, summaries.md). Shared by every user who reads that language.
integrations A user’s connection to a service Hotaru saves items to, one per user and kind (raindrop, readwise, mymind): the token or access key, encrypted with AES-256-GCM under a key derived from BETTER_AUTH_SECRET, the account name, settings (Raindrop: default collection, whether saving asks first; Readwise and MyMind: the routing, location or space, tags) and the last error (raindrop.md, forwarding.md).
item_saves An item a user saved to a service, keyed by user, item and kind: status (saving, saved, failed), the bookmark’s id at the service, collection or target (Readwise location, MyMind space), tags, why it went (trigger: by hand, rule, star, raindrop), its format (long, video, quick), the error, tries so far and when the scheduler tries again. Stream entries carry its status as raindropStatus, readwiseStatus and mymindStatus (raindrop.md, forwarding.md).
pipeline_batches One run of the item pipeline over up to 25 items: the pi-durable task in durable.db that runs it (by ID only, ADR-0002), status, the stage it’s in, error (pipeline.md).
item_pipeline A user’s item in the pipeline: status (queued, running, done, skipped, failed), its batch, how many runs (re-runs included), error. The Executions view reads it, most recently changed first.
item_pipeline_steps What one stage did for a user’s item: done, skipped with a reason (disabled, budget, not_applicable, upstream_failed) or failed with the error, and a short note. Written as an upsert, since a stage can run twice.
ai_calls The cost ledger: one paid model or jev call and a user who pays for it, keyed by OpenRouter’s generation ID. Stage, item, the model that answered, tokens and the user’s share of the cost in US dollars, and whether the user’s own key paid (own_key). A call for several users has one row each (costs.md).

The stream: one row per user and item

When an item arrives, every subscriber of its source gets a user_items row with the item’s publish date copied in (fan-out on write). The stream is then one range of the index user_items (user_id, published_at, item_id), newest first, with cursor paging on (published_at, item_id). The alternative, sorting the items of all subscribed sources on every page, grows with the whole history (500 items a day is about 180,000 a year). A test checks the query plan: the stream query uses the index and never sorts in a temporary table.

  • A new subscriber to a source others already follow gets its latest 50 items.
  • A paused subscription hides its items, but keeps them.
  • Unsubscribing removes the user’s items of that source, except starred ones.
  • Starred items are one range of user_items (user_id, starred_at, item_id), most recently starred first. That view keeps items of paused and unfollowed sources.
  • New since: user_items.created_at is when the item reached the user. The index user_items (user_id, created_at) counts the items that arrived after a page loaded, for the “new items” pill (stream.md).

Retention

Full item content is kept for 90 days (CONTENT_RETENTION_DAYS). After that, pruneItemContent() clears content and sets content_pruned_at. Title, URL, excerpt, dates and the users’ state stay, which is enough for the stream, search by title, duplicate detection and stats. Items any user starred keep their content. At about 500 items a day and ~20 KB of content each, that caps content at roughly 1 GB instead of growing by ~3.6 GB a year. The scheduler (SI-522) runs it daily.

Development data

pnpm db:seed fills apps/web/data/hotaru.db with a dev user (log in as dev with hotaru-dev-password), three sources and 33 items, without network access. Running it again adds nothing.