# chaithz/thinktree architecture

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

- Interactive diagram: https://gitdiagram.com/chaithz/thinktree
- Repository: https://github.com/chaithz/thinktree

## Overview

This is a PDF-backed knowledge-graph application. Users upload a PDF, whose extracted text is chunked into ChromaDB; they then submit a question, receive retrieved context distilled by Ollama into graph-shaped JSON, and view an interactive graph. The graph covers the documented-by-code workflow and visualization; no README capabilities were provided. Backend and frontend request relationships are explicit in their callers; the LLM and vector-store internals are represented only where main.py invokes them.

Main entry points: [`frontend/src/app/knowledge-graph/page.jsx`](https://github.com/chaithz/thinktree/blob/main/frontend/src/app/knowledge-graph/page.jsx) (Graph page), [`main.py`](https://github.com/chaithz/thinktree/blob/main/main.py) (Query handler), [`frontend/src/components/KnowledgeGraph.jsx`](https://github.com/chaithz/thinktree/blob/main/frontend/src/components/KnowledgeGraph.jsx) (Graph renderer)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ui["Graph interface"]
  node_graph_page["Graph page<br/>[page.jsx]"]
  node_graph_view["Graph renderer<br/>[KnowledgeGraph.jsx]"]
end

subgraph group_api["Knowledge API"]
  node_api["FastAPI app<br/>[main.py]"]
  node_pdf_parse["PDF extraction<br/>[main.py]"]
  node_query_handler["Query handler<br/>[main.py]"]
end

subgraph group_knowledge["Retrieval and generation"]
  node_chunking["Text chunking<br/>[main.py]"]
  node_retrieval["Vector retrieval<br/>[main.py]"]
  node_llm["Ollama generation<br/>[main.py]"]
end

subgraph group_storage["Document storage"]
  node_vector_store[("ChromaDB collection<br/>[main.py]")]
end

node_user(("User"))
node_pdf["PDF file"]

node_user -->|"submits query"| node_graph_page
node_user -->|"selects PDF"| node_graph_page
node_pdf -->|"provides upload"| node_graph_page
node_graph_page -->|"POST query"| node_api
node_graph_page -->|"POST PDF"| node_api
node_api -->|"routes upload"| node_pdf_parse
node_pdf_parse -->|"chunks extracted text"| node_chunking
node_pdf_parse -->|"upserts chunks"| node_vector_store
node_api -->|"routes query"| node_query_handler
node_query_handler -->|"queries collection"| node_retrieval
node_retrieval -->|"retrieves context"| node_vector_store
node_query_handler -->|"sends context and prompt"| node_llm
node_query_handler -->|"returns answer"| node_graph_page
node_graph_page -->|"renders parsed graph"| node_graph_view

click node_graph_page "https://github.com/chaithz/thinktree/blob/main/frontend/src/app/knowledge-graph/page.jsx"
click node_graph_view "https://github.com/chaithz/thinktree/blob/main/frontend/src/components/KnowledgeGraph.jsx"
click node_api "https://github.com/chaithz/thinktree/blob/main/main.py"
click node_pdf_parse "https://github.com/chaithz/thinktree/blob/main/main.py"
click node_query_handler "https://github.com/chaithz/thinktree/blob/main/main.py"
click node_chunking "https://github.com/chaithz/thinktree/blob/main/main.py"
click node_retrieval "https://github.com/chaithz/thinktree/blob/main/main.py"
click node_llm "https://github.com/chaithz/thinktree/blob/main/main.py"
click node_vector_store "https://github.com/chaithz/thinktree/blob/main/main.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_graph_page,node_graph_view,node_user toneBlue
class node_api,node_pdf_parse,node_query_handler toneAmber
class node_chunking,node_retrieval,node_llm toneMint
class node_vector_store toneRose
class node_pdf toneIndigo
```

## Components

### Graph interface

- [Graph page](https://github.com/chaithz/thinktree/blob/main/frontend/src/app/knowledge-graph/page.jsx): `frontend/src/app/knowledge-graph/page.jsx`
- [Graph renderer](https://github.com/chaithz/thinktree/blob/main/frontend/src/components/KnowledgeGraph.jsx): `frontend/src/components/KnowledgeGraph.jsx`

### Knowledge API

- [FastAPI app](https://github.com/chaithz/thinktree/blob/main/main.py): `main.py`
- [PDF extraction](https://github.com/chaithz/thinktree/blob/main/main.py): `main.py`
- [Query handler](https://github.com/chaithz/thinktree/blob/main/main.py): `main.py`

### Retrieval and generation

- [Text chunking](https://github.com/chaithz/thinktree/blob/main/main.py): `main.py`
- [Vector retrieval](https://github.com/chaithz/thinktree/blob/main/main.py): `main.py`
- [Ollama generation](https://github.com/chaithz/thinktree/blob/main/main.py): `main.py`

### Document storage

- [ChromaDB collection](https://github.com/chaithz/thinktree/blob/main/main.py): `main.py`

### Other components

- **User**
- **PDF file**

## Connections

- User → Graph page: submits query (evidence: `frontend/src/app/knowledge-graph/page.jsx`)
- User → Graph page: selects PDF (evidence: `frontend/src/app/knowledge-graph/page.jsx`)
- PDF file → Graph page: provides upload (evidence: `frontend/src/app/knowledge-graph/page.jsx`)
- Graph page → FastAPI app: POST query (evidence: `frontend/src/app/knowledge-graph/page.jsx`)
- Graph page → FastAPI app: POST PDF (evidence: `frontend/src/app/knowledge-graph/page.jsx`)
- FastAPI app → PDF extraction: routes upload (evidence: `main.py`)
- PDF extraction → Text chunking: chunks extracted text (evidence: `main.py`)
- PDF extraction → ChromaDB collection: upserts chunks (evidence: `main.py`)
- FastAPI app → Query handler: routes query (evidence: `main.py`)
- Query handler → Vector retrieval: queries collection (evidence: `main.py`)
- Vector retrieval → ChromaDB collection: retrieves context (evidence: `main.py`)
- Query handler → Ollama generation: sends context and prompt (evidence: `main.py`)
- Query handler → Graph page: returns answer (evidence: `frontend/src/app/knowledge-graph/page.jsx`)
- Graph page → Graph renderer: renders parsed graph (evidence: `frontend/src/app/knowledge-graph/page.jsx`)
