# alpha-tf141/second-brain-major-project architecture

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

- Interactive diagram: https://gitdiagram.com/alpha-tf141/second-brain-major-project
- Repository: https://github.com/alpha-tf141/second-brain-major-project

## Overview

Second Brain is an Electron/React desktop assistant backed by FastAPI: it captures activity, turns screenshots into searchable memories, and uses those memories for chat and voice responses. Its main knowledge workflow is capture → OCR → archive → semantic indexing/search → RAG chat. The README also documents integrations, graph/relationship features, research, and realtime voice. Several backend subsystems are represented at their exact directories because their implementation was not sampled; edges are limited to documented workflows or shown references.

Main entry points: [`backend/app/routes`](https://github.com/alpha-tf141/second-brain-major-project/tree/main/backend/app/routes) (FastAPI routes), [`src/routes/AppRoutes.jsx`](https://github.com/alpha-tf141/second-brain-major-project/blob/main/src/routes/AppRoutes.jsx) (React workspaces), [`backend/app/models/memory.py`](https://github.com/alpha-tf141/second-brain-major-project/blob/main/backend/app/models/memory.py) (Memory records), [`backend/app/semantic_search`](https://github.com/alpha-tf141/second-brain-major-project/tree/main/backend/app/semantic_search) (Semantic memory)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_desktop["Desktop experience"]
  node_electron["Electron shell<br/>[main.js]"]
  node_frontend["React workspaces<br/>[AppRoutes.jsx]"]
  node_frontend_context["Backend context<br/>[BackendContext.jsx]"]
  node_api_client["API client<br/>[apiClient.js]"]
end

subgraph group_capture["Capture and archive"]
  node_capture_routes["Live capture<br/>[capture.py]"]
  node_capture_pipeline["Activity capture"]
  node_ocr["OCR processing"]
  node_archive["Memory archive"]
  node_memory_store[("Memory records<br/>[memory.py]")]
end

subgraph group_knowledge["Memory and reasoning"]
  node_semantic["Semantic memory"]
  node_embedding_worker["Embedding indexer"]
  node_vector_store[("Vector store<br/>[chroma_store.py]")]
  node_memory_search["Keyword search<br/>[memory_search.py]"]
  node_research["Adaptive research"]
  node_graph["Knowledge graph"]
end

subgraph group_assistant["Assistant capabilities"]
  node_chat["RAG chat<br/>[pipeline.py]"]
  node_llm["LLM client<br/>[llm_client.py]"]
  node_voice["Voice assistant"]
  node_integrations["Mail and social"]
end

subgraph group_platform["Backend platform"]
  node_backend["FastAPI routes"]
  node_database[("SQLite models<br/>[session.py]")]
  node_live_socket["Live WebSockets"]
end

node_user(("Desktop user"))

node_user -->|"uses workspaces"| node_frontend
node_frontend -->|"runs in shell"| node_electron
node_frontend -->|"mounts provider"| node_frontend_context
node_frontend_context -->|"calls"| node_api_client
node_frontend_context -->|"opens live socket"| node_live_socket
node_frontend -->|"requests API"| node_api_client
node_api_client -->|"calls documented endpoints"| node_backend
node_backend -->|"routes capture APIs"| node_capture_routes
node_capture_routes -->|"captures activity"| node_capture_pipeline
node_capture_pipeline -->|"feeds screenshots"| node_ocr
node_ocr -->|"provides chunks"| node_archive
node_archive -->|"stores memories"| node_memory_store
node_memory_store -.->|"queues indexing"| node_embedding_worker
node_embedding_worker -->|"writes vectors"| node_vector_store
node_semantic -->|"queries vectors"| node_vector_store
node_semantic -->|"runs keyword search"| node_memory_search
node_semantic -->|"hydrates results"| node_memory_store
node_research -->|"retrieves candidates"| node_vector_store
node_research -->|"ranks memories"| node_memory_store
node_chat -->|"retrieves context"| node_semantic
node_chat -->|"streams response"| node_llm
node_chat -->|"stores conversation"| node_memory_store
node_backend -->|"serves chat APIs"| node_chat
node_backend -->|"serves voice APIs"| node_voice
node_backend -.->|"serves mail features"| node_integrations
node_frontend -->|"offers graph workspace"| node_graph
node_backend -->|"persists application data"| node_database

click node_electron "https://github.com/alpha-tf141/second-brain-major-project/blob/main/electron/main.js"
click node_frontend "https://github.com/alpha-tf141/second-brain-major-project/blob/main/src/routes/AppRoutes.jsx"
click node_frontend_context "https://github.com/alpha-tf141/second-brain-major-project/blob/main/src/context/BackendContext.jsx"
click node_api_client "https://github.com/alpha-tf141/second-brain-major-project/blob/main/src/services/apiClient.js"
click node_capture_routes "https://github.com/alpha-tf141/second-brain-major-project/blob/main/backend/app/routes/capture.py"
click node_capture_pipeline "https://github.com/alpha-tf141/second-brain-major-project/tree/main/backend/app/capture"
click node_ocr "https://github.com/alpha-tf141/second-brain-major-project/tree/main/backend/app/ocr"
click node_archive "https://github.com/alpha-tf141/second-brain-major-project/tree/main/backend/app/memory"
click node_memory_store "https://github.com/alpha-tf141/second-brain-major-project/blob/main/backend/app/models/memory.py"
click node_semantic "https://github.com/alpha-tf141/second-brain-major-project/tree/main/backend/app/semantic_search"
click node_embedding_worker "https://github.com/alpha-tf141/second-brain-major-project/blob/main/backend/app/workers/embedding_worker.py"
click node_vector_store "https://github.com/alpha-tf141/second-brain-major-project/blob/main/backend/app/vectorstore/chroma_store.py"
click node_memory_search "https://github.com/alpha-tf141/second-brain-major-project/blob/main/backend/app/search/memory_search.py"
click node_research "https://github.com/alpha-tf141/second-brain-major-project/tree/main/backend/app/research"
click node_graph "https://github.com/alpha-tf141/second-brain-major-project/tree/main/backend/app/graph"
click node_chat "https://github.com/alpha-tf141/second-brain-major-project/blob/main/backend/app/rag/pipeline.py"
click node_llm "https://github.com/alpha-tf141/second-brain-major-project/blob/main/backend/app/llm/llm_client.py"
click node_voice "https://github.com/alpha-tf141/second-brain-major-project/tree/main/backend/app/voice"
click node_integrations "https://github.com/alpha-tf141/second-brain-major-project/tree/main/backend/app/agents"
click node_backend "https://github.com/alpha-tf141/second-brain-major-project/tree/main/backend/app/routes"
click node_database "https://github.com/alpha-tf141/second-brain-major-project/blob/main/backend/app/database/session.py"
click node_live_socket "https://github.com/alpha-tf141/second-brain-major-project/tree/main/backend/app/websocket"

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_electron,node_frontend,node_frontend_context,node_api_client,node_user toneBlue
class node_capture_routes,node_capture_pipeline,node_ocr,node_archive,node_memory_store toneAmber
class node_semantic,node_embedding_worker,node_vector_store,node_memory_search,node_research,node_graph toneMint
class node_chat,node_llm,node_voice,node_integrations toneRose
class node_backend,node_database,node_live_socket toneIndigo
```

## Components

### Desktop experience

- [Electron shell](https://github.com/alpha-tf141/second-brain-major-project/blob/main/electron/main.js): `electron/main.js`
- [React workspaces](https://github.com/alpha-tf141/second-brain-major-project/blob/main/src/routes/AppRoutes.jsx): `src/routes/AppRoutes.jsx`
- [Backend context](https://github.com/alpha-tf141/second-brain-major-project/blob/main/src/context/BackendContext.jsx): `src/context/BackendContext.jsx`
- [API client](https://github.com/alpha-tf141/second-brain-major-project/blob/main/src/services/apiClient.js): `src/services/apiClient.js`

### Capture and archive

- [Live capture](https://github.com/alpha-tf141/second-brain-major-project/blob/main/backend/app/routes/capture.py): `backend/app/routes/capture.py`
- [Activity capture](https://github.com/alpha-tf141/second-brain-major-project/tree/main/backend/app/capture): `backend/app/capture`
- [OCR processing](https://github.com/alpha-tf141/second-brain-major-project/tree/main/backend/app/ocr): `backend/app/ocr`
- [Memory archive](https://github.com/alpha-tf141/second-brain-major-project/tree/main/backend/app/memory): `backend/app/memory`
- [Memory records](https://github.com/alpha-tf141/second-brain-major-project/blob/main/backend/app/models/memory.py): `backend/app/models/memory.py`

### Memory and reasoning

- [Semantic memory](https://github.com/alpha-tf141/second-brain-major-project/tree/main/backend/app/semantic_search): `backend/app/semantic_search`
- [Embedding indexer](https://github.com/alpha-tf141/second-brain-major-project/blob/main/backend/app/workers/embedding_worker.py): `backend/app/workers/embedding_worker.py`
- [Vector store](https://github.com/alpha-tf141/second-brain-major-project/blob/main/backend/app/vectorstore/chroma_store.py): `backend/app/vectorstore/chroma_store.py`
- [Keyword search](https://github.com/alpha-tf141/second-brain-major-project/blob/main/backend/app/search/memory_search.py): `backend/app/search/memory_search.py`
- [Adaptive research](https://github.com/alpha-tf141/second-brain-major-project/tree/main/backend/app/research): `backend/app/research`
- [Knowledge graph](https://github.com/alpha-tf141/second-brain-major-project/tree/main/backend/app/graph): `backend/app/graph`

### Assistant capabilities

- [RAG chat](https://github.com/alpha-tf141/second-brain-major-project/blob/main/backend/app/rag/pipeline.py): `backend/app/rag/pipeline.py`
- [LLM client](https://github.com/alpha-tf141/second-brain-major-project/blob/main/backend/app/llm/llm_client.py): `backend/app/llm/llm_client.py`
- [Voice assistant](https://github.com/alpha-tf141/second-brain-major-project/tree/main/backend/app/voice): `backend/app/voice`
- [Mail and social](https://github.com/alpha-tf141/second-brain-major-project/tree/main/backend/app/agents): `backend/app/agents`

### Backend platform

- [FastAPI routes](https://github.com/alpha-tf141/second-brain-major-project/tree/main/backend/app/routes): `backend/app/routes`
- [SQLite models](https://github.com/alpha-tf141/second-brain-major-project/blob/main/backend/app/database/session.py): `backend/app/database/session.py`
- [Live WebSockets](https://github.com/alpha-tf141/second-brain-major-project/tree/main/backend/app/websocket): `backend/app/websocket`

### Other components

- **Desktop user**

## Connections

- Desktop user → React workspaces: uses workspaces (evidence: `README.md`)
- React workspaces → Electron shell: runs in shell (evidence: `README.md`)
- React workspaces → Backend context: mounts provider
- Backend context → API client: calls (evidence: `src/context/BackendContext.jsx`)
- Backend context → Live WebSockets: opens live socket (evidence: `src/context/BackendContext.jsx`)
- React workspaces → API client: requests API
- API client → FastAPI routes: calls documented endpoints (evidence: `README.md`)
- FastAPI routes → Live capture: routes capture APIs (evidence: `README.md`)
- Live capture → Activity capture: captures activity (evidence: `README.md`)
- Activity capture → OCR processing: feeds screenshots (evidence: `README.md`)
- OCR processing → Memory archive: provides chunks (evidence: `README.md`)
- Memory archive → Memory records: stores memories (evidence: `README.md`)
- Memory records → Embedding indexer: queues indexing (evidence: `backend/app/workers/embedding_worker.py`)
- Embedding indexer → Vector store: writes vectors (evidence: `backend/app/workers/embedding_worker.py`)
- Semantic memory → Vector store: queries vectors (evidence: `backend/app/semantic_search/search_engine.py`)
- Semantic memory → Keyword search: runs keyword search (evidence: `backend/app/semantic_search/search_engine.py`)
- Semantic memory → Memory records: hydrates results (evidence: `backend/app/semantic_search/search_engine.py`)
- Adaptive research → Vector store: retrieves candidates (evidence: `backend/app/research/pipeline.py`)
- Adaptive research → Memory records: ranks memories (evidence: `backend/app/research/pipeline.py`)
- RAG chat → Semantic memory: retrieves context (evidence: `backend/app/rag/pipeline.py`)
- RAG chat → LLM client: streams response (evidence: `backend/app/rag/pipeline.py`)
- RAG chat → Memory records: stores conversation (evidence: `backend/app/rag/pipeline.py`)
- FastAPI routes → RAG chat: serves chat APIs (evidence: `README.md`)
- FastAPI routes → Voice assistant: serves voice APIs (evidence: `README.md`)
- FastAPI routes → Mail and social: serves mail features (evidence: `backend/app/agents/mail_ingestion_agent.py`)
- React workspaces → Knowledge graph: offers graph workspace (evidence: `README.md`)
- FastAPI routes → SQLite models: persists application data (evidence: `README.md`)
