# paarthexe/twinterrytao architecture

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

- Interactive diagram: https://gitdiagram.com/paarthexe/twinterrytao
- Repository: https://github.com/paarthexe/twinterrytao

## Overview

Terence Tao AI is a conversational digital twin whose main workflow retrieves mathematical literature, adds user memory, drafts an answer, and audits it before presentation. The React UI and alternate Streamlit dashboard expose chat, memory, concept exploration, and ingestion controls; Flask routes the primary API workflow. The graph also preserves blog/arXiv ingestion and hybrid search. Some backend and UI source excerpts are partial, so uncertain internal calls are omitted; documented product relationships are cited to the README.

Main entry points: [`frontend/src/App.tsx`](https://github.com/paarthexe/twinterrytao/blob/main/frontend/src/App.tsx) (React app), [`model.py`](https://github.com/paarthexe/twinterrytao/blob/main/model.py) (Draft and audit), [`server.py`](https://github.com/paarthexe/twinterrytao/blob/main/server.py) (Flask API), [`scraper.py`](https://github.com/paarthexe/twinterrytao/blob/main/scraper.py) (Source ingestion)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["User interfaces"]
  node_react_app["React app<br/>[App.tsx]"]
  node_chat_ui["Chat workspace<br/>[ChatWorkspace.tsx]"]
  node_markdown["Math renderer<br/>[MarkdownViewer.tsx]"]
  node_navbar["Navigation and sync<br/>[Navbar.tsx]"]
  node_memory_ui["Memory matrix<br/>[MemoryMatrix.tsx]"]
  node_explorer["Concept explorer"]
  node_force_graph["Graph renderer<br/>[ForceGraph.tsx]"]
  node_streamlit["Streamlit dashboard<br/>[app.py]"]
end

subgraph group_api["API and orchestration"]
  node_flask["Flask API<br/>[server.py]"]
end

subgraph group_knowledge["Knowledge and retrieval"]
  node_scraper["Source ingestion<br/>[scraper.py]"]
  node_documents[("Markdown corpus")]
  node_retriever["Hybrid retrieval<br/>[rag.py]"]
  node_vector_index[("Chroma vector index<br/>[rag.py]")]
end

subgraph group_reasoning["Answer generation"]
  node_answer_pipeline["Draft and audit<br/>[model.py]"]
  node_prompt_defs["Prompt definitions<br/>[prompts.py]"]
end

subgraph group_memory["Persistent memory"]
  node_memory_logic["Memory operations<br/>[memory.py]"]
  node_memory_store[("Long-term memory<br/>[memory.py]")]
end

node_user(("User"))
node_wordpress["WordPress blog"]
node_arxiv["arXiv API"]
node_ollama["Ollama"]

node_user -->|"uses"| node_react_app
node_react_app -->|"calls API"| node_flask
node_react_app -->|"renders"| node_chat_ui
node_react_app -->|"renders"| node_navbar
node_react_app -->|"renders"| node_memory_ui
node_react_app -->|"renders"| node_explorer
node_chat_ui -->|"renders"| node_markdown
node_explorer -->|"renders"| node_force_graph
node_explorer -->|"renders"| node_markdown
node_navbar -->|"triggers sync"| node_flask
node_flask -->|"runs chat"| node_answer_pipeline
node_flask -->|"reads and updates"| node_memory_logic
node_flask -->|"triggers ingestion"| node_scraper
node_streamlit -->|"runs chat"| node_answer_pipeline
node_streamlit -->|"uses memory"| node_memory_logic
node_streamlit -->|"triggers ingestion"| node_scraper
node_scraper -->|"fetches posts"| node_wordpress
node_scraper -->|"fetches papers"| node_arxiv
node_scraper -->|"saves documents"| node_documents
node_retriever -->|"indexes corpus"| node_documents
node_retriever -->|"reads and writes"| node_vector_index
node_answer_pipeline -->|"retrieves sources"| node_retriever
node_answer_pipeline -->|"uses prompts"| node_prompt_defs
node_answer_pipeline -->|"requests generation"| node_ollama
node_answer_pipeline -->|"adds user context"| node_memory_logic
node_memory_logic -->|"reads and writes"| node_memory_store

click node_react_app "https://github.com/paarthexe/twinterrytao/blob/main/frontend/src/App.tsx"
click node_chat_ui "https://github.com/paarthexe/twinterrytao/blob/main/frontend/src/components/ChatWorkspace.tsx"
click node_markdown "https://github.com/paarthexe/twinterrytao/blob/main/frontend/src/components/MarkdownViewer.tsx"
click node_navbar "https://github.com/paarthexe/twinterrytao/blob/main/frontend/src/components/Navbar.tsx"
click node_memory_ui "https://github.com/paarthexe/twinterrytao/blob/main/frontend/src/components/MemoryMatrix.tsx"
click node_explorer "https://github.com/paarthexe/twinterrytao/blob/main/frontend/src/components/ConceptExplorer.tsx"
click node_force_graph "https://github.com/paarthexe/twinterrytao/blob/main/frontend/src/components/ForceGraph.tsx"
click node_streamlit "https://github.com/paarthexe/twinterrytao/blob/main/app.py"
click node_flask "https://github.com/paarthexe/twinterrytao/blob/main/server.py"
click node_scraper "https://github.com/paarthexe/twinterrytao/blob/main/scraper.py"
click node_documents "https://github.com/paarthexe/twinterrytao/tree/main/documents"
click node_retriever "https://github.com/paarthexe/twinterrytao/blob/main/rag.py"
click node_vector_index "https://github.com/paarthexe/twinterrytao/blob/main/rag.py"
click node_answer_pipeline "https://github.com/paarthexe/twinterrytao/blob/main/model.py"
click node_prompt_defs "https://github.com/paarthexe/twinterrytao/blob/main/prompts.py"
click node_memory_logic "https://github.com/paarthexe/twinterrytao/blob/main/memory.py"
click node_memory_store "https://github.com/paarthexe/twinterrytao/blob/main/memory.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_react_app,node_chat_ui,node_markdown,node_navbar,node_memory_ui,node_explorer,node_force_graph,node_streamlit,node_user toneBlue
class node_flask toneAmber
class node_scraper,node_documents,node_retriever,node_vector_index,node_arxiv toneMint
class node_answer_pipeline,node_prompt_defs toneRose
class node_memory_logic,node_memory_store,node_wordpress,node_ollama toneIndigo
```

## Components

### User interfaces

- [React app](https://github.com/paarthexe/twinterrytao/blob/main/frontend/src/App.tsx): `frontend/src/App.tsx`
- [Chat workspace](https://github.com/paarthexe/twinterrytao/blob/main/frontend/src/components/ChatWorkspace.tsx): `frontend/src/components/ChatWorkspace.tsx`
- [Math renderer](https://github.com/paarthexe/twinterrytao/blob/main/frontend/src/components/MarkdownViewer.tsx): `frontend/src/components/MarkdownViewer.tsx`
- [Navigation and sync](https://github.com/paarthexe/twinterrytao/blob/main/frontend/src/components/Navbar.tsx): `frontend/src/components/Navbar.tsx`
- [Memory matrix](https://github.com/paarthexe/twinterrytao/blob/main/frontend/src/components/MemoryMatrix.tsx): `frontend/src/components/MemoryMatrix.tsx`
- [Concept explorer](https://github.com/paarthexe/twinterrytao/blob/main/frontend/src/components/ConceptExplorer.tsx): `frontend/src/components/ConceptExplorer.tsx`
- [Graph renderer](https://github.com/paarthexe/twinterrytao/blob/main/frontend/src/components/ForceGraph.tsx): `frontend/src/components/ForceGraph.tsx`
- [Streamlit dashboard](https://github.com/paarthexe/twinterrytao/blob/main/app.py): `app.py`

### API and orchestration

- [Flask API](https://github.com/paarthexe/twinterrytao/blob/main/server.py): `server.py`

### Knowledge and retrieval

- [Source ingestion](https://github.com/paarthexe/twinterrytao/blob/main/scraper.py): `scraper.py`
- [Markdown corpus](https://github.com/paarthexe/twinterrytao/tree/main/documents): `documents`
- [Hybrid retrieval](https://github.com/paarthexe/twinterrytao/blob/main/rag.py): `rag.py`
- [Chroma vector index](https://github.com/paarthexe/twinterrytao/blob/main/rag.py): `rag.py`

### Answer generation

- [Draft and audit](https://github.com/paarthexe/twinterrytao/blob/main/model.py): `model.py`
- [Prompt definitions](https://github.com/paarthexe/twinterrytao/blob/main/prompts.py): `prompts.py`

### Persistent memory

- [Memory operations](https://github.com/paarthexe/twinterrytao/blob/main/memory.py): `memory.py`
- [Long-term memory](https://github.com/paarthexe/twinterrytao/blob/main/memory.py): `memory.py`

### Other components

- **User**
- **WordPress blog**
- **arXiv API**
- **Ollama**

## Connections

- User → React app: uses (evidence: `README.md`)
- React app → Flask API: calls API (evidence: `frontend/src/App.tsx`)
- React app → Chat workspace: renders (evidence: `frontend/src/App.tsx`)
- React app → Navigation and sync: renders (evidence: `frontend/src/App.tsx`)
- React app → Memory matrix: renders (evidence: `frontend/src/App.tsx`)
- React app → Concept explorer: renders (evidence: `frontend/src/App.tsx`)
- Chat workspace → Math renderer: renders (evidence: `frontend/src/components/ChatWorkspace.tsx`)
- Concept explorer → Graph renderer: renders (evidence: `frontend/src/components/ConceptExplorer.tsx`)
- Concept explorer → Math renderer: renders (evidence: `frontend/src/components/ConceptExplorer.tsx`)
- Navigation and sync → Flask API: triggers sync (evidence: `README.md`)
- Flask API → Draft and audit: runs chat (evidence: `README.md`)
- Flask API → Memory operations: reads and updates (evidence: `server.py`)
- Flask API → Source ingestion: triggers ingestion (evidence: `server.py`)
- Streamlit dashboard → Draft and audit: runs chat (evidence: `README.md`)
- Streamlit dashboard → Memory operations: uses memory (evidence: `app.py`)
- Streamlit dashboard → Source ingestion: triggers ingestion (evidence: `README.md`)
- Source ingestion → WordPress blog: fetches posts (evidence: `README.md`)
- Source ingestion → arXiv API: fetches papers (evidence: `README.md`)
- Source ingestion → Markdown corpus: saves documents (evidence: `README.md`)
- Hybrid retrieval → Markdown corpus: indexes corpus (evidence: `README.md`)
- Hybrid retrieval → Chroma vector index: reads and writes (evidence: `rag.py`)
- Draft and audit → Hybrid retrieval: retrieves sources (evidence: `model.py`)
- Draft and audit → Prompt definitions: uses prompts (evidence: `model.py`)
- Draft and audit → Ollama: requests generation (evidence: `model.py`)
- Draft and audit → Memory operations: adds user context (evidence: `README.md`)
- Memory operations → Long-term memory: reads and writes (evidence: `memory.py`)
