Files
platform/services/brain/app/main.py
Yusuf Suleman 8275f3a71b feat: brain service — self-contained second brain knowledge manager
Full backend service with:
- FastAPI REST API with CRUD, search, reprocess endpoints
- PostgreSQL + pgvector for items and semantic search
- Redis + RQ for background job processing
- Meilisearch for fast keyword/filter search
- Browserless/Chrome for JS rendering and screenshots
- OpenAI structured output for AI classification
- Local file storage with S3-ready abstraction
- Gateway auth via X-Gateway-User-Id header
- Own docker-compose stack (6 containers)

Classification: fixed folders (Home/Family/Work/Travel/Knowledge/Faith/Projects)
and fixed tags (28 predefined). AI assigns exactly 1 folder, 2-3 tags, title,
summary, and confidence score per item.

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

42 lines
1.1 KiB
Python

"""Brain service — FastAPI entrypoint."""
import logging
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from app.api.routes import router
from app.config import DEBUG
logging.basicConfig(
level=logging.DEBUG if DEBUG else logging.INFO,
format="%(asctime)s %(levelname)s %(name)s: %(message)s",
)
app = FastAPI(
title="Second Brain",
description="Save everything. AI classifies it. Search it later.",
version="1.0.0",
docs_url="/api/docs" if DEBUG else None,
redoc_url=None,
)
# No CORS — internal service only, accessed via gateway
app.include_router(router)
@app.on_event("startup")
async def startup():
from app.database import engine, Base
from app.models.item import Item, ItemAsset, AppLink # noqa: import to register models
# Create tables if they don't exist
async with engine.begin() as conn:
await conn.run_sync(Base.metadata.create_all)
# Ensure Meilisearch index exists
from app.search.engine import ensure_meili_index
await ensure_meili_index()
logging.getLogger(__name__).info("Brain service started")