/ case study
Luma
A book reader with an AI that has read the book. Tap a paragraph for its meaning in Indonesian, or ask about the whole book and get answers cited from its pages.
- Type
- Mobile
- Role
- Solo build
- Year
- 2026
- Status
- Invite-only beta
- Platforms
- iOS · Android
- Agentic RAG
- Hybrid retrieval
- Grounded citations
- Local-first sync
- BYOK
Stack: Flutter · Riverpod · Drift · Hono · Cloudflare Workers · D1 · R2 · Better Auth · OpenRouter · React
- Commits in 7 weeks
- 576
- Apps: mobile, API, admin
- 3
- Test files
- 224
- Design and tech docs
- 18
The problem
Indonesians who read English books all do the same thing with a hard paragraph: copy it into a chatbot, ask what it means, then hunt for their place again. The chatbot hasn't read the book, so it doesn't know the characters, the earlier chapters, or the irony.
Luma puts the explanation next to the text, and answers from the book itself: retrieval-augmented generation (RAG) over the reader's own copy, with every claim grounded in a citation they can tap.
Features
Everything a reader touches, from the first screen to the last page.
Step 4 of 6What Luma is built around
Tap a paragraph, and the book explains itself. Ask, and it answers from its own pages.

Artinya
tap a paragraph for its translation and meaning, streamed
Bedahin
break an idea into parts and link it to other chapters
Ngobrolin buku
chat about the book, every answer cited
Ask about a quote
start a chat from the passage you're on

How it's built
A local-first mobile app, an edge API, and an admin dashboard, in one monorepo.
| Layer | Stack |
|---|---|
| Mobile | Flutter, Riverpod, Drift (SQLite), go_router |
| API | Hono on Cloudflare Workers, D1, R2, Better Auth, Drizzle |
| Dashboard | React, Vite, TanStack Query and Table, Tailwind |
| AI | OpenRouter, streamed; Qwen3 embeddings, BM25 for keywords |
| Shared | Zod contracts with fixtures that the Dart tests read too |
Decisions that mattered
- Local-first. SQLite on the device is the source of truth for books, progress, translations, and chats. The server holds a replica.
- No AI proxy. The phone calls OpenRouter directly. The backend only mints per-user keys that expire after 30 days and carry a daily spend cap, so the whole server fits Cloudflare's free tier.
- Cost-aware by default. No automatic retries, since every retry is another paid request. The only extra calls are bounded repairs of an invalid answer.
- BYOK without silent fallback. A reader's own key always wins; if it's rejected, the AI stops instead of quietly billing the free quota.
- Grounded citations. Each one is a frozen snapshot of a source passage (revision, range, hash), revalidated before the reader jumps to it. Generated notes are never citable.
- Stable cache keys. Saved translations are keyed by paragraph-group index, so a re-import never points a translation at the wrong text.
Talking to the book
The hard part isn't the chat. It's retrieval: deciding what to read before answering, within a budget. Luma runs an agentic RAG pipeline with two paths, and picks between them per question.
- Planner. Rewrites the question into English search queries and routes it (these chapters, the whole book, one moment, a correction, or off-topic), using the real table of contents and the reader's position.
- Long-context path. Chapters that fit go into the prompt as original text. Longer reads are summarized per chapter in budgeted batches, map-reduce style, and those notes are cached for any model.
- Hybrid retrieval path. The book is chunked (1,800 characters, 200 overlap). Dense embedding ranks and BM25 ranks are merged with reciprocal rank fusion, then an LLM selector reranks the evidence over rounds and can ask for missing queries.
- One budget. Tokens and time are shared across every step, with a reserve held back for the answer.
- Structured output. The answer is validated against a schema (status, parts, source IDs) before it reaches the reader, and repaired at most twice.

Sync and backup
Sync follows the outbox pattern: database triggers queue every change, pushes are stamped with a per-user sequence number, and other devices pull by cursor. Upserts are idempotent, so a retried push never duplicates anything. Conflicts resolve per record type:
| Record | Rule |
|---|---|
| Book | Earliest first-opened date, most reading time |
| Reading session | Append only |
| AI result | Higher prompt version wins |
| Everything else | Last write wins |
Backups are a .zip with a clean copy of the database and the book files, restored on a temporary copy first.
The admin dashboard
A second Worker, for the only operator: me. Built to answer "is anything about to break or cost too much?" with metadata only.




Admins see
- Sign-ups, bans, and invite codes
- Storage and sync volume, per user and in total
- AI spend against the daily and monthly budget
- Which services are switched on
Never leaves the API
- What anyone is reading or syncing
- API keys, encrypted or not
- Session tokens
Keeping it honest
- Hygiene check on every commit: docs, comments, analyzers, and formatters across all three apps.
- CI on every pull request, in five jobs. Deploys migrate, ship, then health-check.
- Golden tests per API route, including how many database queries each one runs.
- An eval harness for the book chat: offline replay against recorded fixtures, plus live runs on held-out books that count as spent once queried, so prompts can't overfit to them.
What's still rough
- Two phones pushing at the same moment can race on merge results.
- iOS installs from a free Apple account expire after seven days, hence the backup reminder.
- A citation proves which passage was used, not that the answer read it correctly.
Where it is now
An invite-only beta, with the source public on GitHub. No usage numbers yet: there aren't enough users for them to mean anything.
