# baekenough/second-brain architecture

> Architecture diagram of the GitHub repository baekenough/second-brain, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/baekenough/second-brain
- Repository: https://github.com/baekenough/second-brain

## Overview

second-brain is a private, LLM-curated search and knowledge system. Its main workflow collects material from connected sources or mobile uploads, extracts and chunks content, stores it for hybrid retrieval, then serves curated answers through HTTP or MCP. Background workers add summaries, entities, and other derived knowledge; evaluation and tuning support search quality over time. The graph emphasizes those product stages and major documented capabilities. Some subsystem connections rely on README descriptions because their implementation was not sampled; those edges cite the README rather than implying source-level inspection.

Main entry points: [`internal/store/postgres.go`](https://github.com/baekenough/second-brain/blob/main/internal/store/postgres.go) (Postgres Knowledge Store), [`internal/search/search.go`](https://github.com/baekenough/second-brain/blob/main/internal/search/search.go) (Hybrid Search), [`internal/api/ingest_file.go`](https://github.com/baekenough/second-brain/blob/main/internal/api/ingest_file.go) (Upload Handlers), [`cmd/server/main.go`](https://github.com/baekenough/second-brain/blob/main/cmd/server/main.go) (HTTP API Server)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Collection and Ingest"]
  node_collector["Collector Daemon<br/>[main.go]"]
  node_ingestors["Source Collectors"]
  node_ingest_api["Upload Handlers<br/>[ingest_file.go]"]
  node_extractors["Format Extractors"]
end

subgraph group_knowledge["Knowledge Processing"]
  node_chunker["Rune Chunker<br/>[chunker.go]"]
  node_store[("Postgres Knowledge Store<br/>[postgres.go]")]
  node_workers["Enrichment Workers"]
  node_classifier["Classification Worker"]
  node_extract_worker["Entity Extraction Worker"]
  node_action_store["Action Queries<br/>[actions_query.go]"]
end

subgraph group_retrieval["Search and Access"]
  node_search["Hybrid Search<br/>[search.go]"]
  node_llm["LLM Client<br/>[client.go]"]
  node_api["HTTP API Server<br/>[main.go]"]
  node_mcp["MCP Server<br/>[main.go]"]
end

subgraph group_experience["User Interfaces"]
  node_mobile["Android Capture<br/>[SyncWorker.kt]"]
  node_web["Web Application<br/>[page.tsx]"]
end

subgraph group_quality["Quality and Operations"]
  node_eval["Nightly Evaluation<br/>[main.go]"]
  node_askeval["Ask Evaluation<br/>[llm.go]"]
end

node_agent(("AI Agent"))
node_sources(("Connected Sources"))

node_sources -->|"supplies content"| node_collector
node_mobile -->|"uploads recordings"| node_ingest_api
node_collector -->|"runs collection"| node_ingestors
node_collector -->|"starts workers"| node_workers
node_ingestors -->|"stores documents"| node_store
node_ingest_api -->|"extracts files"| node_extractors
node_ingest_api -->|"chunks uploads"| node_chunker
node_ingest_api -->|"upserts documents"| node_store
node_extractors -->|"provides text"| node_chunker
node_chunker -->|"stores chunks"| node_store
node_workers -->|"persists enrichment"| node_store
node_workers -->|"requests enrichment"| node_llm
node_classifier -.->|"updates classification"| node_store
node_extract_worker -->|"extracts entities"| node_llm
node_extract_worker -.->|"persists entities"| node_store
node_api -->|"serves search"| node_search
node_mcp -->|"offers search tools"| node_search
node_search -->|"retrieves knowledge"| node_store
node_search -->|"curates results"| node_llm
node_agent -->|"uses REST"| node_api
node_agent -->|"uses MCP"| node_mcp
node_web -.->|"calls endpoints"| node_api
node_api -.->|"queries actions"| node_action_store
node_eval -->|"evaluates retrieval"| node_search
node_eval -->|"records metrics"| node_store
node_askeval -->|"runs ask evaluation"| node_llm

click node_mobile "https://github.com/baekenough/second-brain/blob/main/mobile/second-brain-push/app/src/main/java/com/baekenough/secondbrain/sync/SyncWorker.kt"
click node_collector "https://github.com/baekenough/second-brain/blob/main/cmd/collector/main.go"
click node_ingestors "https://github.com/baekenough/second-brain/tree/main/internal/collector"
click node_ingest_api "https://github.com/baekenough/second-brain/blob/main/internal/api/ingest_file.go"
click node_extractors "https://github.com/baekenough/second-brain/tree/main/internal/collector/extractor"
click node_chunker "https://github.com/baekenough/second-brain/blob/main/internal/chunker/chunker.go"
click node_store "https://github.com/baekenough/second-brain/blob/main/internal/store/postgres.go"
click node_workers "https://github.com/baekenough/second-brain/blob/main/internal/worker/note_enrichment_worker.go"
click node_classifier "https://github.com/baekenough/second-brain/blob/main/internal/worker/classification_worker.go"
click node_extract_worker "https://github.com/baekenough/second-brain/blob/main/internal/worker/extraction_worker.go"
click node_search "https://github.com/baekenough/second-brain/blob/main/internal/search/search.go"
click node_llm "https://github.com/baekenough/second-brain/blob/main/internal/llm/client.go"
click node_api "https://github.com/baekenough/second-brain/blob/main/cmd/server/main.go"
click node_mcp "https://github.com/baekenough/second-brain/blob/main/cmd/mcp/main.go"
click node_web "https://github.com/baekenough/second-brain/blob/main/web/src/app/ask/page.tsx"
click node_eval "https://github.com/baekenough/second-brain/blob/main/cmd/eval/main.go"
click node_askeval "https://github.com/baekenough/second-brain/blob/main/internal/askeval/llm.go"
click node_action_store "https://github.com/baekenough/second-brain/blob/main/internal/store/actions_query.go"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_collector,node_ingestors,node_ingest_api,node_extractors toneBlue
class node_chunker,node_store,node_workers,node_classifier,node_extract_worker,node_action_store toneAmber
class node_search,node_llm,node_api,node_mcp toneMint
class node_mobile,node_web toneRose
class node_eval,node_askeval,node_agent,node_sources toneIndigo
```

## Components

### Collection and Ingest

- [Collector Daemon](https://github.com/baekenough/second-brain/blob/main/cmd/collector/main.go): `cmd/collector/main.go`
- [Source Collectors](https://github.com/baekenough/second-brain/tree/main/internal/collector): `internal/collector`
- [Upload Handlers](https://github.com/baekenough/second-brain/blob/main/internal/api/ingest_file.go): `internal/api/ingest_file.go`
- [Format Extractors](https://github.com/baekenough/second-brain/tree/main/internal/collector/extractor): `internal/collector/extractor`

### Knowledge Processing

- [Rune Chunker](https://github.com/baekenough/second-brain/blob/main/internal/chunker/chunker.go): `internal/chunker/chunker.go`
- [Postgres Knowledge Store](https://github.com/baekenough/second-brain/blob/main/internal/store/postgres.go): `internal/store/postgres.go`
- [Enrichment Workers](https://github.com/baekenough/second-brain/blob/main/internal/worker/note_enrichment_worker.go): `internal/worker/note_enrichment_worker.go`
- [Classification Worker](https://github.com/baekenough/second-brain/blob/main/internal/worker/classification_worker.go): `internal/worker/classification_worker.go`
- [Entity Extraction Worker](https://github.com/baekenough/second-brain/blob/main/internal/worker/extraction_worker.go): `internal/worker/extraction_worker.go`
- [Action Queries](https://github.com/baekenough/second-brain/blob/main/internal/store/actions_query.go): `internal/store/actions_query.go`

### Search and Access

- [Hybrid Search](https://github.com/baekenough/second-brain/blob/main/internal/search/search.go): `internal/search/search.go`
- [LLM Client](https://github.com/baekenough/second-brain/blob/main/internal/llm/client.go): `internal/llm/client.go`
- [HTTP API Server](https://github.com/baekenough/second-brain/blob/main/cmd/server/main.go): `cmd/server/main.go`
- [MCP Server](https://github.com/baekenough/second-brain/blob/main/cmd/mcp/main.go): `cmd/mcp/main.go`

### User Interfaces

- [Android Capture](https://github.com/baekenough/second-brain/blob/main/mobile/second-brain-push/app/src/main/java/com/baekenough/secondbrain/sync/SyncWorker.kt): `mobile/second-brain-push/app/src/main/java/com/baekenough/secondbrain/sync/SyncWorker.kt`
- [Web Application](https://github.com/baekenough/second-brain/blob/main/web/src/app/ask/page.tsx): `web/src/app/ask/page.tsx`

### Quality and Operations

- [Nightly Evaluation](https://github.com/baekenough/second-brain/blob/main/cmd/eval/main.go): `cmd/eval/main.go`
- [Ask Evaluation](https://github.com/baekenough/second-brain/blob/main/internal/askeval/llm.go): `internal/askeval/llm.go`

### Other components

- **AI Agent**
- **Connected Sources**

## Connections

- Connected Sources → Collector Daemon: supplies content (evidence: `README.md`)
- Android Capture → Upload Handlers: uploads recordings (evidence: `README.md`)
- Collector Daemon → Source Collectors: runs collection (evidence: `cmd/collector/main.go`)
- Collector Daemon → Enrichment Workers: starts workers (evidence: `cmd/collector/main.go`)
- Source Collectors → Postgres Knowledge Store: stores documents (evidence: `README.md`)
- Upload Handlers → Format Extractors: extracts files (evidence: `internal/api/ingest_file.go`)
- Upload Handlers → Rune Chunker: chunks uploads (evidence: `internal/api/ingest_file.go`)
- Upload Handlers → Postgres Knowledge Store: upserts documents (evidence: `internal/api/ingest_file.go`)
- Format Extractors → Rune Chunker: provides text (evidence: `README.md`)
- Rune Chunker → Postgres Knowledge Store: stores chunks (evidence: `README.md`)
- Enrichment Workers → Postgres Knowledge Store: persists enrichment (evidence: `internal/worker/note_enrichment_worker.go`)
- Enrichment Workers → LLM Client: requests enrichment (evidence: `internal/worker/note_enrichment_worker.go`)
- Classification Worker → Postgres Knowledge Store: updates classification
- Entity Extraction Worker → LLM Client: extracts entities (evidence: `internal/worker/extraction_worker.go`)
- Entity Extraction Worker → Postgres Knowledge Store: persists entities
- HTTP API Server → Hybrid Search: serves search (evidence: `README.md`)
- MCP Server → Hybrid Search: offers search tools (evidence: `README.md`)
- Hybrid Search → Postgres Knowledge Store: retrieves knowledge (evidence: `README.md`)
- Hybrid Search → LLM Client: curates results (evidence: `README.md`)
- AI Agent → HTTP API Server: uses REST (evidence: `README.md`)
- AI Agent → MCP Server: uses MCP (evidence: `README.md`)
- Web Application → HTTP API Server: calls endpoints
- HTTP API Server → Action Queries: queries actions
- Nightly Evaluation → Hybrid Search: evaluates retrieval (evidence: `cmd/eval/main.go`)
- Nightly Evaluation → Postgres Knowledge Store: records metrics (evidence: `cmd/eval/main.go`)
- Ask Evaluation → LLM Client: runs ask evaluation (evidence: `internal/askeval/llm.go`)
