Skip to content

Architecture overview

How Hotaru is built: the parts, where they live, and how data flows. The why behind the main choices is in decisions/. The rules that follow from them are in conventions.md.

The system

flowchart TB
scheduler["Scheduler<br/>(adaptive polling, in process)"]
subgraph web["apps/web: one Node process"]
direction TB
ui["SvelteKit UI<br/>pages and load functions"]
api["REST API /api/v1<br/>SSE /api/v1/events, /api/v1/chat/events"]
auth["Better Auth<br/>sessions + API tokens"]
core["packages/core<br/>services · durable pipeline · agent · jev · OpenRouter"]
ui --> core
api --> core
end
appdb[("data/hotaru.db<br/>Drizzle · WAL · FTS5")]
durabledb[("data/durable.db<br/>pi-durable · one writer")]
openrouter["OpenRouter<br/>jev · GPT-6 Luna · Haiku"]
scheduler --> core
core --> appdb
core --> durabledb
core --> openrouter
browser["Browser"] --> ui
browser --> sdk
tui["TUI (M5)"] --> sdk["packages/sdk"]
cli["CLI (M5)"] --> sdk
agents["Local agents: Pi, Claude Code (MCP via hotaru mcp)"] --> cli
cron["Cron jobs"] --> sdk
sdk --> api
  • One process (ADR-0001). The SvelteKit server also starts the core runtime: the pi-durable harness, the scheduler and the item pipeline. It’s the only process that writes durable.db.
  • The scheduler is part of that process, not a system cron. It fetches the sources that are due (SI-522), as a plain loop rather than durable tasks, because a fetch can safely run twice (ADR-0004, scheduler.md). The “Cron” in the reference repo’s diagram is this loop.
  • Two SQLite files (ADR-0002). hotaru.db holds the app data (Drizzle). durable.db holds pi-durable’s transcripts, documents and tasks.
  • Clients never run work. The browser, the TUI, the CLI and local Pi agents only read state and submit requests. Closing a tab or a terminal interrupts nothing.

An item’s way through the system

  1. The scheduler finds a due source and fetches it (SI-521, SI-522).
  2. New items go into hotaru.db. The pipeline loop queues them per user and puts them into batches of up to 25. Each batch is one durable task with one phase per stage: extract → triage (jev) → dedupe (jev) → summarize (GPT-6 Luna) → score. Each phase is a checkpoint, so a crash resumes at the stage it was in, and paid calls that finished aren’t made again (pipeline.md, ADR-0005).
  3. Each stage writes its result to hotaru.db as an idempotent upsert, because a stage can run twice (see conventions), and one step row per user and item for the Executions view.
  4. The live version for each affected user goes up. Open pages reload their data (SSE, below).

Directory layout

hotaru/
├── apps/
│ └── web/ SvelteKit (adapter-node): UI, /api/v1, SSE, auth.
│ Starts the core runtime in the server init hook.
├── packages/
│ ├── core/ Domain and runtime. No SvelteKit imports.
│ │ ├── src/db/ Drizzle schema and client for hotaru.db
│ │ ├── drizzle/ SQL migrations (embedded into src/db/migrations.gen.ts)
│ │ ├── src/services/ Sources, items, feedback, settings. Used by web routes and the REST API.
│ │ ├── src/pipeline/ Durable item pipeline: loop, batch task, stages (SI-533)
│ │ ├── src/scheduler/ Adaptive polling (SI-522)
│ │ ├── src/agent/ Harness setup, chat agent, tools (M3)
│ │ ├── src/ai/ OpenRouter client, jev client, cost ledger (SI-534)
│ │ └── prompts/jev/ jev command.json files (from spikes/jev-bench)
│ └── sdk/ Wire types (zod) and a typed HTTP client for /api/v1
├── docs/
│ └── architecture/ This overview, conventions, decisions
├── spikes/ Throwaway experiments, not part of the build
└── fixtures/ Test data. fixtures/private/ is git-ignored.

Later: apps/cli and apps/tui (M5). They depend only on packages/sdk, never on core.

Workspaces: plain pnpm workspaces (apps/*, packages/*), no Turborepo. With three packages, pnpm -r and pnpm --filter are enough. Add Turborepo when build or test times start to hurt. Tooling (TypeScript strict, lint, format, tests, CI) is set up in SI-517, following Konbini.

Interfaces

  • Browser: SvelteKit load functions read through core services directly, with no HTTP round trip inside the server. Every change goes through the REST API with the SDK client, like any other client (ADR-0006).
  • REST API /api/v1: the same services for every client: the browser, CLI, TUI, cron jobs, local Pi agents, and later integrations. Clients authenticate with a session cookie or an API token (prefix hotaru_, scoped read, cron or write). Requests and responses are zod schemas from packages/sdk. The OpenAPI document is generated from them (api.md).
  • Capability parity (SI-558): packages/sdk/src/capabilities.ts lists every route, the client method that calls it and the scope it needs. Tests fail when a route, a capability or a client method is missing, or when the browser goes around the SDK.

Live updates

  • GET /api/live (SSE): each user has an in-memory change version. Every successful write raises it. Pages reload their data when it changes, debounced, with polling as a fallback. This is Konbini’s docs/live.md design, and it works because there is only one process.
  • GET /api/v1/chat/events (SSE): a pi-durable watch on the user’s conversation, shared by all their open pages, sent to each. Several clients follow one chat at once (chat.md).

Multi-user

Every user-owned row carries a user_id, and every query filters by it. Sources that several users follow are fetched once. Subscriptions, item state, feedback, weights and AI judgements are per user. There is no personal configuration in code or environment variables. Registration is off by default, and accounts are created by invite or by the admin CLI. The rules are in conventions.md. The tables are described in data-model.md.

Deployment

One container (or one systemd service) on a single server, with a persistent data/ volume holding both database files. It runs one replica, never more: in-memory live versions, one pi-durable writer and SQLite all rule out a second one. Backups (for example, Litestream) cover both files. Details are in SI-518.