Skip to content
njarrarPublic

About

Brain is the one place that remembers everything you have or care about, and an AI that knows it all. Save anything, from anywhere, and ask about it later in plain words, in English or Arabic.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

42 Commits

Folders and files

Repository files navigation

Brain

Brain is the one place that remembers everything you have or care about, and an AI that knows it all. Save anything, from anywhere, and ask about it later in plain words, in English or Arabic.

"What gift should I get my colleague's kids?" Brain finds the kids' names and ages in a voice memo you recorded months ago, then the toys you screenshotted, the pins you saved and the email about the party, and suggests ideas, with a link to each save it used.

How the AI works for you

You pick the AI in Settings: Claude, ChatGPT or Gemini, with your own key.

  • It reads everything. Bookmarks, posts, emails, pins, notes, screenshots, photos and voice memos. It writes out what was said, reads the text in pictures, and picks out the people, dates and events in each save, such as a birthday or a meeting.
  • It sorts everything. Each save gets a category, a sub-topic, a one-line summary, tags, its language and a sensitive flag. Categories aren't fixed: when nothing fits, the AI adds a new one.
  • It joins things up. Ask Brain works out what to look for, searches your saves by words and by meaning, then searches again for the people it found, so a name in a voice memo links to the screenshots, bookmarks and emails about that person.
  • It brings things back. Remind me, a daily Resurface, Related saves on each item, a weekly digest of what you saved, and a podcast where two hosts talk through your month.
  • It helps you decide. Clear the pile walks your inbox oldest first, one save at a time: keep it, let it go or snooze it. When you keep one, say why (to use, to learn, to buy, for someone, an idea), and Ask Brain uses that later. The topic map shows what you keep, by topic.
  • It goes where you work. A connector link lets Claude, ChatGPT or any AI app that takes MCP connectors search and read your saves. It can't change anything.

What goes in

  • X bookmarks, YouTube likes and playlists, Instagram saves, Feedly articles and Pinterest boards
  • Gmail and Outlook mail, read only, your whole history
  • Screenshots from your iPhone album, photos, voice memos and notes
  • Anything you share to Save to Brain from any iPhone app, or add on the web

Nothing is thrown away. Your data stays in your own cloud account, and the web and iPhone apps stay in sync. You can search, filter, read, archive, retag or add a note to anything. Arabic text shows right to left.

Version 0.8.2. See CHANGELOG.md for what changed.

What it looks like

The screenshots below use sample data on a local copy of the app. Each desktop page has the same page on a phone beside it.

The inbox as a card grid, with the side menu on the left The same page on a phone

The inbox. The menu starts with Resurface (with today's count) and the weekly digest, then Inbox, Unread, All, Archive and Trash. Each card shows who posted it, the sub-topic, the text, AI's summary, the category, tags and any reminder.

The List layout with an item open in the reading pane The same page on a phone

The List layout. A card opens in the reading pane beside the list; j and k move through it.

The ⌘K box with word matches and Ask Brain The same page on a phone

⌘K: word matches and things about the same idea, and Ask Brain for a written answer.

The Ask Brain page with an answer that links a voice memo, an email, a screenshot, a pin and a bookmark The same page on a phone

Ask Brain. Type a question and the AI answers from your own saves. Here it finds the kids' names in a voice memo, the party in an email, then a screenshot, a pin and a bookmark, and suggests gifts. "Looked for" shows what it searched, and each number opens the save it used.

The Add to Brain page with Link, Note, Voice memo, Pictures and File, a recorded voice memo, a note and tags The same page on a phone

Add to Brain on the web. Pick what you're adding: a Link, a Note, a Voice memo (record it in the browser or pick a recording), up to 10 Pictures (each its own save) or any File up to 20 MB. Add a note and your own tags if you like. Let AI sort lets the chosen AI pick the category, summary and tags after you save.

A Resurface card with Done, Tomorrow and Keep The same page on a phone

Resurface: a few saves a day. Keys 1, 2 and 3 answer.

The Remind me menu on an item page The same page on a phone

Remind me on an item page: pick when it comes back.

A weekly digest with numbered links to the saves The same page on a phone

The weekly digest, written by your chosen AI, with numbered links to the saves.

One category opened from the side menu The same page on a phone

One category, picked from the side menu. Arabic posts read right to left.

An Arabic item page with its note, category and tags The same page on a phone

An item page: open the original, archive it, write a note, change the category, add or remove tags.

The Sources page The same page on a phone

Sources: Your chosen AI sorting with a "Sort now" button, then each source with its status and setup steps.

The side menu open on a phone

On a phone the side menu slides in from the left.

Categories

Brain starts with these eight. The AI adds a new broad category when nothing fits (up to 24 in all).

Category What goes in it
AI, Code & Dev Tools LLMs, agents, prompts, coding tools, open source, Mac utilities
Markets, Startups & Finance SaaS, venture capital, investing, macro and oil, MENA fintech
MENA Geopolitics & Society Egypt, Jordan, the Gulf, Palestine, investigative threads
Cinema, Gaming, History & Culture Film, games, books, history, art, calligraphy
Health, Biotech & Longevity Health, fitness, sleep, nutrition, biotech
Menswear, Design & Travel Tailoring, style, architecture, design, places to go
Viral Threads & Internet Culture Memes, viral stories, social commentary, humor
Models, Pop Culture & NSFW Celebrities, models, pop culture, sensitive content

The categories live in the categories table, so you can rename or add them too.

The web app

The app is in web/. It is a Next.js 16 app that runs on Cloudflare Workers through OpenNext.

  • Data: Cloudflare D1 (SQLite), database digital-brain. The schema is in db/migrations/. Search uses an FTS5 index over the title, note, summary, author, handle and text. It handles English and Arabic alike, and matches word starts.
  • Files: photos and screenshots go in R2, bucket digital-brain-files, and are served at /files/<id> only to you and your iPhone app.
  • Sign in: Better Auth with email and password, plus Google (and Apple) when their keys are set. The archive is private: ALLOWED_EMAILS lists who may make an account. Without it, only the first account can be made.
  • One link, one item: the same link saved from two places becomes one item with two saves, so you can see every place you saved it.

What you can do in it:

  • Inbox, Unread, All, Archive, Trash: new items land in the inbox with an unread dot. Opening one reads it; Mark unread brings the dot back.
  • Search by word, @handle or topic, in English or Arabic.
  • ⌘K (or /) opens one box for everything: word matches, then things about the same idea (search by meaning), then Ask Brain, which answers a question from your own saves and cites them as [1], [2].
  • Resurface: a few saves each day. Ones you asked to see again with Remind me (Tomorrow, This weekend, Next week, Next month or a day you pick), then ones from this day in past years. Keep brings a card back later and then less often; Tomorrow brings it back tomorrow; Done lets it go. Keys 1, 2 and 3 answer.
  • Weekly digest: every Sunday evening your AI writes a short note on what you saved that week, grouped by theme, with links to the items. "Write this week's now" makes one at once.
  • Clear the pile: every inbox save, oldest first, one at a time, with how many are left. Keep (d) moves it to the Archive, Let go (x) moves it to Trash, Snooze (s) hides it for two weeks, Undo (u) takes the last call back. After Keep, keys 1 to 5 say why you kept it. The item page can change the reason later.
  • Podcast: press Make and two hosts talk through the last thirty days of what you saved and kept, and push back on each other. The chosen AI writes the script; Workers AI (@cf/deepgram/aura-1) speaks it, and the episode is kept in R2 as one MP3.
  • Topic map: one circle per category, sized by how much you saved in it, with lines between categories whose saves share tags.
  • Use Brain in other AIs: Settings makes a connector link, https://<your site>/api/mcp/<key>. Add it as a custom connector in Claude (Settings, Connectors, Add custom connector) or ChatGPT (Settings, Apps and Connectors, Create, No authentication). The connector is read only, with five tools: search_saves, get_save, recent_saves, topics and ask_brain. Each link has its own key; remove one in Settings and it stops working. A connector key can't open /api/app/*.
  • Related: each item page lists saves about the same thing.
  • Reading pane: in the List layout a card opens beside the list. j and k move, e archives, u marks unread, Esc closes.
  • Filter by category and sub-topic, tag or source, by language (English or Arabic), by media (with pictures or text only) and by the sensitive flag. Sensitive pictures are blurred until you turn the blur off.
  • Grid or list layout.
  • Item page: read the full text and pictures, see where and when you saved it, write a note, set the category, add or remove tags. Tags you add look different from the ones your AI suggests; press ✓ to keep a suggestion.
  • Add by hand at /add: pick a link (the title and picture are filled in from the page), a note, a voice memo (record it in the browser or pick a recording), up to 10 pictures or a file up to 20 MB, then add a note and tags if you like.

Sources

Each source shows its status on the Sources page (/sources).

Source How it connects today
X Click Connect X on the Sources page. Brain pulls new bookmarks from the X API on Sync now and every six hours, and stops at the first page it has already seen. Older bookmarks can come from an export file with npm run import:x (see below).
Feedly Each article you save for later reaches Brain through an IFTTT webhook. The Sources page shows the link and the body to paste into IFTTT.
YouTube Its own Google connection with read-only YouTube access. Tick Liked videos and any of your playlists on the Sources page, and Brain brings in those, then checks again every six hours. Needs the Google keys.
Instagram Upload Instagram's "Download your information" export (the zip or saved_posts.json) on the Sources page. Instagram gives only the link, the account and the date. You can also share a post to Brain from the iPhone share sheet.
Gmail Click Connect Gmail on the Sources page. Read only (gmail.readonly). Brings in your whole history, newest first, a slice every six hours (or on Sync now), then new mail. Spam, Trash, Drafts, chats and the Promotions, Social and Forums tabs stay out. Email lands under All, not the Inbox. The AI sorts and reads it like everything else. Needs the Google keys and the Gmail API turned on.
Outlook Outlook, Hotmail and Live mail, through Microsoft Graph (Mail.Read). Works like Gmail. Junk, Deleted, Drafts and the Other tab stay out. Needs the Microsoft keys.
Pinterest Click Connect Pinterest. Brings in the pins on your boards, each tagged with its board name, then checks again every six hours. Needs the Pinterest keys.
Screenshots The iPhone app sends your Screenshots album. Your AI looks at each picture to sort it.
Added by hand The /add page, or "Save to Brain" in any iPhone app.
Voice memos Share a memo from Voice Memos to Save to Brain, pick a sound file in the iPhone Add sheet, speak in the Add sheet, or record one or pick a sound file on /add.

Feedly and other tools post to /api/ingest/<source>?key=.... The key is made for you and shown on the Sources page. Keep it private.

Import X bookmarks you already exported

The older x-bookmark-manager and x-bookmarks-review repos hold JSON exports. Import one or both. Running it again is safe: bookmarks already there are skipped.

cd web
npm run import:x -- ../../x-bookmark-manager/bookmarks_export.json ../../x-bookmarks-review/bookmarks_db.json

Add --remote to load them into the real D1 database, and --status read to keep them out of the inbox.

Choosing the AI

Settings (/settings on the web, Settings, AI on the iPhone) picks which AI does Brain's work: Claude, ChatGPT or Gemini. The choice is stored in the cloud, so the web and the phone always agree. It sorts saves, reads voice memos and pictures for people and dates, answers Ask Brain and writes the weekly digest.

AI Default model Key from
Claude claude-haiku-4-5 console.anthropic.com
ChatGPT gpt-5.4-mini platform.openai.com
Gemini gemini-flash-latest aistudio.google.com

Each AI has its own key and an optional model name. Keys are stored encrypted (AES-GCM under BETTER_AUTH_SECRET) and shown back only as their last four characters. Test makes one small call, so you know a key and model work. Keys only: none of the three lets another app sign in with your account and use your plan for API calls (Gemini can take a Google sign-in, but only through a Google Cloud project of your own, which a key is simpler than). Search by meaning and writing out voice memos stay on Workers AI, so switching AI never means building the search index again.

The code is in web/src/lib/ai.ts: one askJson and one askText call that every feature uses. ChatGPT gets a strict JSON schema, Gemini a response schema, and Your AI structured outputs, so all three return the same shapes.

Sorting

The AI sorts items (email included) in batches of 20. Categories aren't fixed: when nothing fits, the AI adds a new broad one, up to 24 in all. It reuses sub-topics already in use so they stay tidy, and it never overwrites a category, sub-topic or summary you already have.

  • New items from Feedly, the /add page, the share sheet and screenshots are sorted as they arrive.
  • Sort now on the Sources page sorts everything still unsorted and shows progress.
  • A timer in web/worker.ts runs every hour. Every sixth hour it syncs X, YouTube, Gmail, Outlook and Pinterest. Every hour it reads up to 80 saves, sorts up to 10 batches of unsorted items, makes meaning vectors for new and changed items, and on Sunday evening (UTC) writes the weekly digest.

Without a key for the chosen AI, items still save, and the Sources page says it needs one.

Reading every save

The AI reads every save once (web/src/lib/memory/read.ts): voice memos, screenshots, notes, bookmarks, posts, emails and pins.

  • Sound and video are written out by Workers AI Whisper (@cf/openai/whisper-large-v3-turbo), in the language spoken. Files up to 20 MB.
  • Screenshots and photos, and the first picture on a post or pin: the AI reads the text in the picture.
  • Then the AI lists the people and the dates (birthdays, meetings, trips; yearly ones marked), gives voice memos and pictures a short title, and adds up to five labels, such as "Birthday" and the people's names.

The transcript and the facts go into word search, search by meaning and Ask Brain. Saves already in Brain are read a few batches every hour, or all at once with Read now on the Sources page. Read again on an item starts over.

Search by meaning

Search by meaning, Related and Ask Brain use Workers AI (@cf/baai/bge-m3, which reads English and Arabic) and a Vectorize index called digital-brain-items. Each item is read once after it is saved or sorted, and again when its text changes. The deploy makes the index the first time. Without the index (for example in npm run dev), these fall back to word search.

The app API

The iPhone app talks to /api/app/* with a Bearer brn_… key from /connect-app. The same routes work from a signed-in browser. Every route checks its input with zod (web/src/lib/items/schema.ts) and answers mistakes with a 400 and a plain message. Unknown fields are refused.

Route What it does
GET /items The list. Same filters as the web page. Page with cursor (from nextCursor); page still works.
GET /items/:id, PATCH /items/:id One item. PATCH takes status, read, trash, category, note, addTags, removeTags, remindAt, keptWhy (null clears).
DELETE /items/:id, DELETE /items?view=trash Delete for good, from Trash only.
GET /items/:id/related Saves about the same thing.
POST /items/:id/read Hear or read the item again: transcript, people and dates.
GET /resurface, POST /resurface Today's cards; answer one with { id, how: keep, later or done }.
POST /ask { q }, answers from your saves with the items it used.
GET /pile, POST /pile The next inbox saves, oldest first, and how many are left (skip leaves out ids the screen holds). POST { id, how: done, letgo, snooze or undo }, or { id, why: use, learn, buy, someone, idea or null }.
GET /map The topic map: circles with x, y, r on a 1000 by 1000 square, and the lines between them.
GET /podcast, POST /podcast The latest episodes; POST makes a new one (about a minute). The sound is at /podcast/:id/audio.
GET /digest, POST /digest The latest weekly digests; POST writes this week's now.
POST /save A link, a note or a file (a picture, a voice memo or a video).
GET /ai, PUT /ai, POST /ai/test The AI in use, its model and keys (last four only); change them; test one.
GET /version The live web build: version, commit and build time.
GET /menu, GET/PUT /prefs, GET /sources, GET /unfurl, POST /import Counts, look, sources, link previews, bulk import.

The iPhone app

The app is in ios/. It is a SwiftUI app built with XcodeGen, with a share extension called Save to Brain that saves a link, text, picture or voice memo from any app.

It reads and writes the same cloud data as the web app, so a note, tag or archive on one shows up on the other. You sign in with the same account as the web, Google included. Sources are set once on the web and shared; the AI choice and its keys can be set on either. Screenshots from the Screenshots album and anything shared to Save to Brain go straight to the cloud. It has three tabs in the system tab bar: Inbox, Library and Search. Search finds saves as you type, and its top row, Ask Brain, turns the same words into an answer from your saves. Before you type it offers questions drawn from your own saves. Library opens Resurface, Clear the pile, the weekly digest, the podcast and the topic map, and each item has Remind me in its More menu and a list of related saves. Text follows the phone's text size setting, and saving, archiving, deleting, tagging and setting a reminder each give a small buzz. Speaking in the Add sheet keeps the voice memo, and an item shows a player, what was said and what Brain found in it, and a Kept row that says why you kept it. See ios/README.md to build it.

Sign in, with the app icon and what Brain does Inbox grouped by day Library with Resurface, the weekly digest, Unread and categories An item with its summary, note, category and tags The Search tab with Ask Brain questions drawn from your saves Settings with the look, AI and storage

Sign in, the inbox, Library, an item, Search with Ask Brain, and Settings, with made-up sample data.

Adding a note

The Add to Brain sheet with a note, tags and every option

Tap + at the top right of Inbox or Library to open Add to Brain. The sheet opens just tall enough for what it holds:

  • The text box takes a link or a note. Brain shows what it found (Note, Link, Photo, Voice) at the bottom right.
  • Let AI sort lets the chosen AI pick the category, summary and tags. Tap it to turn that off.
  • Add tags opens a Tags box for your own tags, split with commas. Both chips turn blue when on.
  • Photos picks up to 10 pictures, Camera takes one, Microphone writes down what you say and keeps it as a voice memo, and Files adds pictures, sound or video files.
  • Save sends it to the cloud. The web and the phone both see it at once.

The Android app

android/ holds a native Android app (Kotlin, Jetpack Compose) that does what the iPhone app does: Inbox, Library, Search with Ask Brain, the Add sheet and "Save to Brain" from the share sheet. It talks to the same web app with the same app key. GitHub builds it on every change; to install it, open Actions, pick android, and download brain-android-apk from the latest run. Set your own server under Server on the sign-in screen. See android/README.md.

Deploys

To run your own copy:

  1. In web/, make the database with npx wrangler d1 create digital-brain and put its id in web/wrangler.jsonc.
  2. Set BETTER_AUTH_URL in web/wrangler.jsonc and baseURL in ios/Shared/Config.swift to your Worker address.
  3. Pick your own bundle ids and app group in ios/project.yml and the two .entitlements files.
  • .github/workflows/deploy.yml runs when you start it from the Actions tab. It applies new D1 migrations, then builds and deploys the Worker. It needs a CLOUDFLARE_API_TOKEN repository secret (Edit Cloudflare Workers template, plus D1 Edit and Vectorize Edit). It also makes the Vectorize index the first time.
  • .github/workflows/web.yml runs lint, a typecheck, the unit tests and a build on every pull request.

Set Worker secrets once from web/:

cd web
npx wrangler secret put NAME
Secret What it is
BETTER_AUTH_SECRET Long random string that signs sessions. Also guards the six-hourly timer.
ALLOWED_EMAILS Who may make an account, comma separated. Unset means only the first account.
ANTHROPIC_API_KEY, OPENAI_API_KEY, GEMINI_API_KEY Optional. Used when no key for that AI is saved in Settings.
GOOGLE_CLIENT_ID, GOOGLE_CLIENT_SECRET Optional. Shows "Continue with Google" and lets you connect YouTube.
MS_CLIENT_ID, MS_CLIENT_SECRET Optional. Lets you connect Outlook mail. From an app registration in the Microsoft Entra admin center.
PINTEREST_APP_ID, PINTEREST_APP_SECRET Optional. Lets you connect Pinterest. From an app at developers.pinterest.com.
APPLE_CLIENT_ID, APPLE_CLIENT_SECRET, APPLE_APP_BUNDLE_ID Optional. Shows "Continue with Apple".

BETTER_AUTH_URL is not a secret. It is set in web/wrangler.jsonc.

Redirect URLs to add in Google and Apple:

  • https://<your app>/api/auth/callback/google (Google sign in)
  • https://<your app>/api/youtube/callback (YouTube)
  • https://<your app>/api/connect/gmail/callback (Gmail)
  • https://<your app>/api/connect/outlook/callback (Outlook, in the Microsoft app registration)
  • https://<your app>/api/connect/pinterest/callback (Pinterest, in the Pinterest app)
  • https://<your app>/api/auth/callback/apple (Apple sign in)

Run it locally

You need Node 20 or later. Wrangler keeps a local copy of D1 and R2 in web/.wrangler.

cd web
npm install
cp .dev.vars.example .dev.vars   # then set BETTER_AUTH_SECRET and ALLOWED_EMAILS
npm run migrate                  # makes the tables in the local D1 copy
npm run dev                      # http://localhost:3000

Workers AI and Vectorize only run on Cloudflare, so npm run dev leaves them off. Run BRAIN_REMOTE=1 npm run dev after npx wrangler login to use the real ones.

Open http://localhost:3000, sign up with an email from ALLOWED_EMAILS, and add items at /add. Add ANTHROPIC_API_KEY (or OPENAI_API_KEY, GEMINI_API_KEY) to .dev.vars to try sorting. Never commit .dev.vars.

Other scripts:

Script What it does
npm run preview Builds the real Worker and runs it at http://localhost:8787
npm run lint ESLint
npm test Unit tests (input checks, paging, Resurface schedule, digest week, links)
npm run build Next.js build
npm run migrate:remote Applies migrations to the real D1 database
npm run deploy Builds and deploys by hand
npm run cf-typegen Rebuilds the binding types in cloudflare-env.d.ts

Repo layout

.
├── web/                     Next.js app on Cloudflare Workers
│   ├── src/app/(app)/       Pages: list, item, add, sources
│   ├── src/app/api/         Sign in, ingest hook, timer, YouTube, iPhone app API
│   ├── src/components/      Cards, side menu, forms
│   ├── src/lib/             Database, sorter, sources, auth
│   ├── src/lib/items/       Input checks, item SQL and the one item service
│   ├── src/lib/memory/      Resurface, search by meaning, Ask Brain, weekly digest
│   ├── scripts/import-x.ts  X export import
│   ├── worker.ts            Worker entry and six-hourly timer
│   └── wrangler.jsonc       D1, R2 and timer settings
├── db/migrations/           D1 schema, applied in name order
├── ios/                     iPhone app and "Save to Brain" share extension
├── android/                 Android app (Kotlin, Jetpack Compose)
├── docs/                    Design doc and README screenshots
├── CHANGELOG.md             What changed in each version
└── .github/workflows/       Deploy by hand, checks on pull requests

About

Brain is the one place that remembers everything you have or care about, and an AI that knows it all. Save anything, from anywhere, and ask about it later in plain words, in English or Arabic.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages