# dsanh14/ai_secondbrain architecture

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

- Interactive diagram: https://gitdiagram.com/dsanh14/ai_secondbrain
- Repository: https://github.com/dsanh14/ai_secondbrain

## Overview

AI Second Brain turns user-provided knowledge into summaries, extracted tasks, searchable answers with citations, and semantically linked notes. The main workflow runs from the frontend’s upload and note interfaces through FastAPI routes to LLM, retrieval, and persistence services; the graph view presents stored note relationships. The README documents audio transcription and the frontend/API capabilities, but the supplied excerpts do not show all wiring, so those links are attributed to the README rather than inferred from unsampled code.

Main entry points: [`backend/main.py`](https://github.com/dsanh14/ai_secondbrain/blob/main/backend/main.py) (FastAPI application), [`backend/services/database.py`](https://github.com/dsanh14/ai_secondbrain/blob/main/backend/services/database.py) (Persistence operations), [`frontend/lib/api.ts`](https://github.com/dsanh14/ai_secondbrain/blob/main/frontend/lib/api.ts) (API client), [`backend/routers/notes.py`](https://github.com/dsanh14/ai_secondbrain/blob/main/backend/routers/notes.py) (Notes routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_upload_ui["Upload interface<br/>[UploadForm.tsx]"]
  node_notes_ui["Notes interface<br/>[page.tsx]"]
  node_search_ui["Search interface<br/>[SearchBox.tsx]"]
  node_tasks_ui["Task interface<br/>[TaskList.tsx]"]
  node_graph_ui["Graph view<br/>[GraphView.tsx]"]
  node_api_client["API client<br/>[api.ts]"]
  node_app_routes["App pages"]
end

subgraph group_api["API"]
  node_api_app["FastAPI application<br/>[main.py]"]
  node_notes_api["Notes routes<br/>[notes.py]"]
  node_search_api["Search routes<br/>[search.py]"]
  node_summarize_api["Summarize routes<br/>[summarize.py]"]
  node_tasks_api["Task routes<br/>[tasks.py]"]
  node_schemas["API schemas<br/>[schemas.py]"]
end

subgraph group_ai["AI services"]
  node_llm["LLM chains<br/>[llm.py]"]
  node_speech["Audio transcription<br/>[speech.py]"]
  node_retriever["Semantic retrieval<br/>[retriever.py]"]
  node_embeddings["Embeddings and index<br/>[embeddings.py]"]
  node_graph_service["Semantic linking<br/>[graph.py]"]
end

subgraph group_data["Knowledge data"]
  node_database_service["Persistence operations<br/>[database.py]"]
  node_orm["Note and task records<br/>[orm.py]"]
  node_database[("PostgreSQL")]
  node_vector_store[("Vector store")]
end

node_user(("Knowledge user"))

node_user -->|"uploads content"| node_upload_ui
node_user -->|"manages notes"| node_notes_ui
node_user -->|"asks questions"| node_search_ui
node_upload_ui -->|"sends requests"| node_api_client
node_notes_ui -->|"sends requests"| node_api_client
node_search_ui -->|"sends requests"| node_api_client
node_tasks_ui -->|"sends requests"| node_api_client
node_api_client -->|"calls API"| node_api_app
node_app_routes -->|"renders"| node_upload_ui
node_app_routes -->|"renders"| node_notes_ui
node_app_routes -->|"renders"| node_search_ui
node_app_routes -->|"renders"| node_graph_ui
node_api_app -->|"registers routes"| node_notes_api
node_api_app -->|"registers routes"| node_search_api
node_api_app -->|"registers routes"| node_summarize_api
node_api_app -->|"registers routes"| node_tasks_api
node_api_app -->|"initializes tables"| node_database_service
node_summarize_api -->|"builds summary chain"| node_llm
node_tasks_api -->|"builds task chain"| node_llm
node_tasks_api -->|"saves tasks"| node_database_service
node_search_api -->|"creates retriever"| node_retriever
node_search_api -->|"builds QA chain"| node_llm
node_notes_api -->|"indexes note"| node_retriever
node_notes_api -->|"links notes"| node_graph_service
node_notes_api -->|"reads and saves"| node_database_service
node_retriever -->|"indexes and retrieves"| node_embeddings
node_graph_service -->|"finds neighbors"| node_retriever
node_graph_service -->|"stores links"| node_database_service
node_database_service -->|"persists records"| node_orm
node_database_service -->|"reads and writes"| node_database
node_embeddings -->|"indexes chunks"| node_vector_store
node_graph_ui -->|"loads graph data"| node_api_client
node_upload_ui -.->|"transcribes audio"| node_speech
node_schemas -.->|"defines payloads"| node_notes_api

click node_upload_ui "https://github.com/dsanh14/ai_secondbrain/blob/main/frontend/components/UploadForm.tsx"
click node_notes_ui "https://github.com/dsanh14/ai_secondbrain/blob/main/frontend/app/notes/page.tsx"
click node_search_ui "https://github.com/dsanh14/ai_secondbrain/blob/main/frontend/components/SearchBox.tsx"
click node_tasks_ui "https://github.com/dsanh14/ai_secondbrain/blob/main/frontend/components/TaskList.tsx"
click node_graph_ui "https://github.com/dsanh14/ai_secondbrain/blob/main/frontend/components/GraphView.tsx"
click node_api_client "https://github.com/dsanh14/ai_secondbrain/blob/main/frontend/lib/api.ts"
click node_app_routes "https://github.com/dsanh14/ai_secondbrain/tree/main/frontend/app"
click node_api_app "https://github.com/dsanh14/ai_secondbrain/blob/main/backend/main.py"
click node_notes_api "https://github.com/dsanh14/ai_secondbrain/blob/main/backend/routers/notes.py"
click node_search_api "https://github.com/dsanh14/ai_secondbrain/blob/main/backend/routers/search.py"
click node_summarize_api "https://github.com/dsanh14/ai_secondbrain/blob/main/backend/routers/summarize.py"
click node_tasks_api "https://github.com/dsanh14/ai_secondbrain/blob/main/backend/routers/tasks.py"
click node_schemas "https://github.com/dsanh14/ai_secondbrain/blob/main/backend/models/schemas.py"
click node_llm "https://github.com/dsanh14/ai_secondbrain/blob/main/backend/services/llm.py"
click node_speech "https://github.com/dsanh14/ai_secondbrain/blob/main/backend/services/speech.py"
click node_retriever "https://github.com/dsanh14/ai_secondbrain/blob/main/backend/services/retriever.py"
click node_embeddings "https://github.com/dsanh14/ai_secondbrain/blob/main/backend/services/embeddings.py"
click node_graph_service "https://github.com/dsanh14/ai_secondbrain/blob/main/backend/services/graph.py"
click node_database_service "https://github.com/dsanh14/ai_secondbrain/blob/main/backend/services/database.py"
click node_orm "https://github.com/dsanh14/ai_secondbrain/blob/main/backend/models/orm.py"

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_upload_ui,node_notes_ui,node_search_ui,node_tasks_ui,node_graph_ui,node_api_client,node_app_routes,node_user toneBlue
class node_api_app,node_notes_api,node_search_api,node_summarize_api,node_tasks_api,node_schemas toneAmber
class node_llm,node_speech,node_retriever,node_embeddings,node_graph_service toneMint
class node_database_service,node_orm,node_database,node_vector_store toneRose
```

## Components

### Frontend

- [Upload interface](https://github.com/dsanh14/ai_secondbrain/blob/main/frontend/components/UploadForm.tsx): `frontend/components/UploadForm.tsx`
- [Notes interface](https://github.com/dsanh14/ai_secondbrain/blob/main/frontend/app/notes/page.tsx): `frontend/app/notes/page.tsx`
- [Search interface](https://github.com/dsanh14/ai_secondbrain/blob/main/frontend/components/SearchBox.tsx): `frontend/components/SearchBox.tsx`
- [Task interface](https://github.com/dsanh14/ai_secondbrain/blob/main/frontend/components/TaskList.tsx): `frontend/components/TaskList.tsx`
- [Graph view](https://github.com/dsanh14/ai_secondbrain/blob/main/frontend/components/GraphView.tsx): `frontend/components/GraphView.tsx`
- [API client](https://github.com/dsanh14/ai_secondbrain/blob/main/frontend/lib/api.ts): `frontend/lib/api.ts`
- [App pages](https://github.com/dsanh14/ai_secondbrain/tree/main/frontend/app): `frontend/app`

### API

- [FastAPI application](https://github.com/dsanh14/ai_secondbrain/blob/main/backend/main.py): `backend/main.py`
- [Notes routes](https://github.com/dsanh14/ai_secondbrain/blob/main/backend/routers/notes.py): `backend/routers/notes.py`
- [Search routes](https://github.com/dsanh14/ai_secondbrain/blob/main/backend/routers/search.py): `backend/routers/search.py`
- [Summarize routes](https://github.com/dsanh14/ai_secondbrain/blob/main/backend/routers/summarize.py): `backend/routers/summarize.py`
- [Task routes](https://github.com/dsanh14/ai_secondbrain/blob/main/backend/routers/tasks.py): `backend/routers/tasks.py`
- [API schemas](https://github.com/dsanh14/ai_secondbrain/blob/main/backend/models/schemas.py): `backend/models/schemas.py`

### AI services

- [LLM chains](https://github.com/dsanh14/ai_secondbrain/blob/main/backend/services/llm.py): `backend/services/llm.py`
- [Audio transcription](https://github.com/dsanh14/ai_secondbrain/blob/main/backend/services/speech.py): `backend/services/speech.py`
- [Semantic retrieval](https://github.com/dsanh14/ai_secondbrain/blob/main/backend/services/retriever.py): `backend/services/retriever.py`
- [Embeddings and index](https://github.com/dsanh14/ai_secondbrain/blob/main/backend/services/embeddings.py): `backend/services/embeddings.py`
- [Semantic linking](https://github.com/dsanh14/ai_secondbrain/blob/main/backend/services/graph.py): `backend/services/graph.py`

### Knowledge data

- [Persistence operations](https://github.com/dsanh14/ai_secondbrain/blob/main/backend/services/database.py): `backend/services/database.py`
- [Note and task records](https://github.com/dsanh14/ai_secondbrain/blob/main/backend/models/orm.py): `backend/models/orm.py`
- **PostgreSQL**
- **Vector store**

### Other components

- **Knowledge user**

## Connections

- Knowledge user → Upload interface: uploads content (evidence: `README.md`)
- Knowledge user → Notes interface: manages notes (evidence: `README.md`)
- Knowledge user → Search interface: asks questions (evidence: `README.md`)
- Upload interface → API client: sends requests (evidence: `README.md`)
- Notes interface → API client: sends requests (evidence: `README.md`)
- Search interface → API client: sends requests (evidence: `README.md`)
- Task interface → API client: sends requests (evidence: `README.md`)
- API client → FastAPI application: calls API (evidence: `README.md`)
- App pages → Upload interface: renders (evidence: `README.md`)
- App pages → Notes interface: renders (evidence: `README.md`)
- App pages → Search interface: renders (evidence: `README.md`)
- App pages → Graph view: renders (evidence: `README.md`)
- FastAPI application → Notes routes: registers routes (evidence: `backend/main.py`)
- FastAPI application → Search routes: registers routes (evidence: `backend/main.py`)
- FastAPI application → Summarize routes: registers routes (evidence: `backend/main.py`)
- FastAPI application → Task routes: registers routes (evidence: `backend/main.py`)
- FastAPI application → Persistence operations: initializes tables (evidence: `backend/main.py`)
- Summarize routes → LLM chains: builds summary chain (evidence: `README.md`)
- Task routes → LLM chains: builds task chain (evidence: `backend/routers/tasks.py`)
- Task routes → Persistence operations: saves tasks (evidence: `backend/routers/tasks.py`)
- Search routes → Semantic retrieval: creates retriever (evidence: `backend/routers/search.py`)
- Search routes → LLM chains: builds QA chain (evidence: `backend/routers/search.py`)
- Notes routes → Semantic retrieval: indexes note (evidence: `backend/routers/notes.py`)
- Notes routes → Semantic linking: links notes (evidence: `backend/routers/notes.py`)
- Notes routes → Persistence operations: reads and saves (evidence: `backend/routers/notes.py`)
- Semantic retrieval → Embeddings and index: indexes and retrieves (evidence: `backend/services/retriever.py`)
- Semantic linking → Semantic retrieval: finds neighbors (evidence: `backend/services/graph.py`)
- Semantic linking → Persistence operations: stores links (evidence: `backend/services/graph.py`)
- Persistence operations → Note and task records: persists records (evidence: `backend/services/database.py`)
- Persistence operations → PostgreSQL: reads and writes (evidence: `backend/services/database.py`)
- Embeddings and index → Vector store: indexes chunks (evidence: `README.md`)
- Graph view → API client: loads graph data (evidence: `README.md`)
- Upload interface → Audio transcription: transcribes audio (evidence: `README.md`)
- API schemas → Notes routes: defines payloads (evidence: `backend/routers/notes.py`)
