# hussain-reddy/secondbrain architecture

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

- Interactive diagram: https://gitdiagram.com/hussain-reddy/secondbrain
- Repository: https://github.com/hussain-reddy/secondbrain

## Overview

SecondBrain is a Streamlit app for asking questions about uploaded PDFs. Its main workflow extracts PDF text, chunks it, builds a vector store, retrieves relevant chunks for a question, and sends context to Gemini for an answer. The repository also contains a separate reusable QA-chain builder and a PDF loader, but the sampled app does not call either. Evidence is limited to the README URL and the supplied source excerpts; the README itself documents no additional capabilities.

Main entry points: [`app.py`](https://github.com/hussain-reddy/secondbrain/blob/main/app.py) (Streamlit app), [`src/vectorstore.py`](https://github.com/hussain-reddy/secondbrain/blob/main/src/vectorstore.py) (Vector store), [`src/llm_chain.py`](https://github.com/hussain-reddy/secondbrain/blob/main/src/llm_chain.py) (QA chain builder), [`src/chunker.py`](https://github.com/hussain-reddy/secondbrain/blob/main/src/chunker.py) (Text chunker)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["User workflow"]
  node_app_ui["Streamlit app<br/>[app.py]"]
end

subgraph group_processing["Document processing"]
  node_chunker["Text chunker<br/>[chunker.py]"]
  node_vectorstore[("Vector store<br/>[vectorstore.py]")]
  node_pdf_loader["PDF loader<br/>[loader.py]"]
end

subgraph group_qa["Question answering"]
  node_retrieval["Context retrieval<br/>[app.py]"]
  node_llm_chain["QA chain builder<br/>[llm_chain.py]"]
end

node_user(("User"))
node_gemini["Google Gemini"]

node_user -->|"uploads PDF"| node_app_ui
node_app_ui -->|"chunks text"| node_chunker
node_app_ui -->|"builds index"| node_vectorstore
node_app_ui -->|"submits question"| node_retrieval
node_retrieval -->|"retrieves chunks"| node_vectorstore
node_retrieval -->|"sends context"| node_gemini
node_llm_chain -->|"configures model"| node_gemini

click node_app_ui "https://github.com/hussain-reddy/secondbrain/blob/main/app.py"
click node_chunker "https://github.com/hussain-reddy/secondbrain/blob/main/src/chunker.py"
click node_vectorstore "https://github.com/hussain-reddy/secondbrain/blob/main/src/vectorstore.py"
click node_retrieval "https://github.com/hussain-reddy/secondbrain/blob/main/app.py"
click node_llm_chain "https://github.com/hussain-reddy/secondbrain/blob/main/src/llm_chain.py"
click node_pdf_loader "https://github.com/hussain-reddy/secondbrain/blob/main/src/loader.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_app_ui,node_user toneBlue
class node_chunker,node_vectorstore,node_pdf_loader toneAmber
class node_retrieval,node_llm_chain toneMint
class node_gemini toneIndigo
```

## Components

### User workflow

- [Streamlit app](https://github.com/hussain-reddy/secondbrain/blob/main/app.py): `app.py`

### Document processing

- [Text chunker](https://github.com/hussain-reddy/secondbrain/blob/main/src/chunker.py): `src/chunker.py`
- [Vector store](https://github.com/hussain-reddy/secondbrain/blob/main/src/vectorstore.py): `src/vectorstore.py`
- [PDF loader](https://github.com/hussain-reddy/secondbrain/blob/main/src/loader.py): `src/loader.py`

### Question answering

- [Context retrieval](https://github.com/hussain-reddy/secondbrain/blob/main/app.py): `app.py`
- [QA chain builder](https://github.com/hussain-reddy/secondbrain/blob/main/src/llm_chain.py): `src/llm_chain.py`

### Other components

- **User**
- **Google Gemini**

## Connections

- User → Streamlit app: uploads PDF (evidence: `app.py`)
- Streamlit app → Text chunker: chunks text (evidence: `app.py`)
- Streamlit app → Vector store: builds index (evidence: `app.py`)
- Streamlit app → Context retrieval: submits question (evidence: `app.py`)
- Context retrieval → Vector store: retrieves chunks (evidence: `app.py`)
- Context retrieval → Google Gemini: sends context (evidence: `app.py`)
- QA chain builder → Google Gemini: configures model (evidence: `src/llm_chain.py`)
