Files
platform/services/brain
Yusuf Suleman 4592e35732
All checks were successful
Security Checks / dependency-audit (push) Successful in 1m13s
Security Checks / secret-scanning (push) Successful in 3s
Security Checks / dockerfile-lint (push) Successful in 3s
feat: major platform expansion — Brain service, RSS reader, iOS app, AI assistants, Firefox extension
Brain Service:
- Playwright stealth crawler replacing browserless (og:image, Readability, Reddit JSON API)
- AI classification with tag definitions and folder assignment
- YouTube video download via yt-dlp
- Karakeep migration complete (96 items)
- Taxonomy management (folders with icons/colors, tags)
- Discovery shuffle, sort options, search (Meilisearch + pgvector)
- Item tag/folder editing, card color accents

RSS Reader Service:
- Custom FastAPI reader replacing Miniflux
- Feed management (add/delete/refresh), category support
- Full article extraction via Readability
- Background content fetching for new entries
- Mark all read with confirmation
- Infinite scroll, retention cleanup (30/60 day)
- 17 feeds migrated from Miniflux

iOS App (SwiftUI):
- Native iOS 17+ app with @Observable architecture
- Cookie-based auth, configurable gateway URL
- Dashboard with custom background photo + frosted glass widgets
- Full fitness module (today/templates/goals/food library)
- AI assistant chat (fitness + brain, raw JSON state management)
- 120fps ProMotion support

AI Assistants (Gateway):
- Unified dispatcher with fitness/brain domain detection
- Fitness: natural language food logging, photo analysis, multi-item splitting
- Brain: save/append/update/delete notes, search & answer, undo support
- Madiha user gets fitness-only (brain disabled)

Firefox Extension:
- One-click save to Brain from any page
- Login with platform credentials
- Right-click context menu (save page/link/image)
- Notes field for URL saves
- Signed and published on AMO

Other:
- Reader bookmark button routes to Brain (was Karakeep)
- Fitness food library with "Add" button + add-to-meal popup
- Kindle send file size check (25MB SMTP2GO limit)
- Atelier UI as default (useAtelierShell=true)
- Mobile upload box in nav drawer

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 00:56:29 -05:00
..

Second Brain Service

A "save everything" knowledge management backend. Captures links, notes, PDFs, images, and documents. AI classifies everything automatically. Supports keyword, semantic, and hybrid search.

Architecture

brain-api        → FastAPI REST API (port 8200)
brain-worker     → RQ background processor
brain-db         → PostgreSQL 16 + pgvector
brain-redis      → Redis 7 (job queue)
brain-meili      → Meilisearch (keyword search)
brain-browserless → Headless Chrome (JS rendering + screenshots)

Quick Start

cd services/brain

# Copy and edit env
cp .env.example .env
# Add your OPENAI_API_KEY

# Start the stack
docker compose up -d

# Check health
curl http://localhost:8200/api/health

API Endpoints

Method Path Description
GET /api/health Health check
GET /api/config List folders/tags
POST /api/items Create item (link/note)
POST /api/items/upload Upload file
GET /api/items List items (with filters)
GET /api/items/{id} Get item by ID
PATCH /api/items/{id} Update item
DELETE /api/items/{id} Delete item
POST /api/items/{id}/reprocess Re-run AI classification
POST /api/search Keyword search (Meilisearch)
POST /api/search/semantic Semantic search (pgvector)
POST /api/search/hybrid Combined keyword + semantic

Gateway Integration

The platform gateway proxies /api/brain/* to brain-api:8200/api/*.

Auth is handled by the gateway injecting X-Gateway-User-Id header.

The brain-api container joins the pangolin Docker network so the gateway can reach it.

Processing Flow

  1. User submits URL/note/file → stored immediately as pending
  2. RQ worker picks it up → status becomes processing
  3. Worker: fetches content, takes screenshot, extracts text
  4. Worker: calls OpenAI for classification (folder, tags, title, summary)
  5. Worker: generates embedding via OpenAI
  6. Worker: indexes in Meilisearch
  7. Status becomes ready (or failed on error)

Storage

Files stored locally at ./storage/. Each item gets a subdirectory:

storage/{item_id}/screenshot/screenshot.png
storage/{item_id}/archived_html/page.html
storage/{item_id}/original_upload/filename.pdf

S3-compatible storage can be added by implementing S3Storage in app/services/storage.py.