# sondosahmed1/academic-paper-assistant architecture

> Architecture diagram of the GitHub repository sondosahmed1/academic-paper-assistant, 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/sondosahmed1/academic-paper-assistant
- Repository: https://github.com/sondosahmed1/academic-paper-assistant

## Overview

This is a local academic-paper RAG assistant: users ask questions in a Streamlit chat and receive answers grounded in retrieved paper passages with citations. The README also documents a separate corpus-preparation workflow—PDF extraction, chunking, embeddings, and page-layout analysis—though its implementation is not represented by the sampled Python modules; the notebook is present in the tree. Runtime retrieval and generation are visible in the excerpts. The layout detector excerpt is a mock, so its production layout-analysis capability is documented rather than verified in code.

Main entry points: [`rag-assistant-project/main.py`](https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/main.py) (App startup), [`rag-assistant-project/app/services/rag_service.py`](https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/app/services/rag_service.py) (RAG service), [`rag-assistant-project/app/api/routes/query.py`](https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/app/api/routes/query.py) (Query route), [`rag-assistant-project/app/db/vector_store.py`](https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/app/db/vector_store.py) (Chroma store)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Chat client"]
  node_chat["Chat UI<br/>[app.py]"]
  node_api_client["API client<br/>[api_client.py]"]
end

subgraph group_api["Query API"]
  node_query_route["Query route<br/>[query.py]"]
  node_query_schema["Query schema<br/>[query.py]"]
  node_runtime["App startup<br/>[main.py]"]
end

subgraph group_rag["Retrieval and answers"]
  node_rag_service["RAG service<br/>[rag_service.py]"]
  node_retrieval["Passage retrieval<br/>[rag_service.py]"]
  node_layout_context["Layout context<br/>[layout_detector.py]"]
  node_vector_store[("Chroma store<br/>[vector_store.py]")]
  node_grounding["Grounded prompt<br/>[rag_service.py]"]
  node_ollama_client["Ollama client<br/>[ollama_client.py]"]
end

subgraph group_corpus["Corpus preparation"]
  node_pdf_corpus["Academic PDFs"]
  node_preparation["PDF preparation<br/>[rag_pipeline.ipynb]"]
  node_sample_indexer["Sample indexer<br/>[index_samples.py]"]
end

node_researcher(("Researcher"))
node_ollama["Ollama model"]

node_researcher -->|"asks"| node_chat
node_chat -->|"calls"| node_api_client
node_api_client -->|"POSTs query"| node_query_route
node_runtime -->|"registers route"| node_query_route
node_runtime -->|"initializes"| node_rag_service
node_runtime -->|"initializes"| node_vector_store
node_runtime -->|"initializes"| node_layout_context
node_runtime -->|"initializes"| node_ollama_client
node_query_route -->|"returns response"| node_query_schema
node_query_route -->|"invokes"| node_rag_service
node_rag_service -->|"uses"| node_retrieval
node_retrieval -->|"queries"| node_vector_store
node_retrieval -->|"gets page context"| node_layout_context
node_rag_service -->|"builds prompt"| node_grounding
node_rag_service -->|"requests completion"| node_ollama_client
node_ollama_client -->|"sends prompt"| node_ollama
node_pdf_corpus -.->|"provides PDFs"| node_preparation
node_preparation -.->|"indexes chunks"| node_vector_store
node_preparation -.->|"analyzes pages"| node_layout_context
node_sample_indexer -->|"adds samples"| node_vector_store

click node_chat "https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/frontend/app.py"
click node_api_client "https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/frontend/api_client.py"
click node_query_route "https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/app/api/routes/query.py"
click node_query_schema "https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/app/schemas/query.py"
click node_runtime "https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/main.py"
click node_rag_service "https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/app/services/rag_service.py"
click node_retrieval "https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/app/services/rag_service.py"
click node_layout_context "https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/app/core/layout_detector.py"
click node_vector_store "https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/app/db/vector_store.py"
click node_grounding "https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/app/services/rag_service.py"
click node_ollama_client "https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/app/services/ollama_client.py"
click node_preparation "https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/notebooks/rag_pipeline.ipynb"
click node_sample_indexer "https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/index_samples.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_chat,node_api_client toneBlue
class node_query_route,node_query_schema,node_runtime toneAmber
class node_rag_service,node_retrieval,node_layout_context,node_vector_store,node_grounding,node_ollama_client toneMint
class node_pdf_corpus,node_preparation,node_sample_indexer toneRose
class node_researcher,node_ollama toneIndigo
```

## Components

### Chat client

- [Chat UI](https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/frontend/app.py): `rag-assistant-project/frontend/app.py`
- [API client](https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/frontend/api_client.py): `rag-assistant-project/frontend/api_client.py`

### Query API

- [Query route](https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/app/api/routes/query.py): `rag-assistant-project/app/api/routes/query.py`
- [Query schema](https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/app/schemas/query.py): `rag-assistant-project/app/schemas/query.py`
- [App startup](https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/main.py): `rag-assistant-project/main.py`

### Retrieval and answers

- [RAG service](https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/app/services/rag_service.py): `rag-assistant-project/app/services/rag_service.py`
- [Passage retrieval](https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/app/services/rag_service.py): `rag-assistant-project/app/services/rag_service.py`
- [Layout context](https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/app/core/layout_detector.py): `rag-assistant-project/app/core/layout_detector.py`
- [Chroma store](https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/app/db/vector_store.py): `rag-assistant-project/app/db/vector_store.py`
- [Grounded prompt](https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/app/services/rag_service.py): `rag-assistant-project/app/services/rag_service.py`
- [Ollama client](https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/app/services/ollama_client.py): `rag-assistant-project/app/services/ollama_client.py`

### Corpus preparation

- **Academic PDFs**
- [PDF preparation](https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/notebooks/rag_pipeline.ipynb): `rag-assistant-project/notebooks/rag_pipeline.ipynb`
- [Sample indexer](https://github.com/sondosahmed1/academic-paper-assistant/blob/main/rag-assistant-project/index_samples.py): `rag-assistant-project/index_samples.py`

### Other components

- **Researcher**
- **Ollama model**

## Connections

- Researcher → Chat UI: asks (evidence: `rag-assistant-project/frontend/app.py`)
- Chat UI → API client: calls (evidence: `rag-assistant-project/frontend/app.py`)
- API client → Query route: POSTs query (evidence: `rag-assistant-project/frontend/api_client.py`)
- App startup → Query route: registers route (evidence: `rag-assistant-project/main.py`)
- App startup → RAG service: initializes (evidence: `rag-assistant-project/main.py`)
- App startup → Chroma store: initializes (evidence: `rag-assistant-project/main.py`)
- App startup → Layout context: initializes (evidence: `rag-assistant-project/main.py`)
- App startup → Ollama client: initializes (evidence: `rag-assistant-project/main.py`)
- Query route → Query schema: returns response (evidence: `rag-assistant-project/app/api/routes/query.py`)
- Query route → RAG service: invokes (evidence: `rag-assistant-project/app/api/routes/query.py`)
- RAG service → Passage retrieval: uses (evidence: `rag-assistant-project/app/services/rag_service.py`)
- Passage retrieval → Chroma store: queries (evidence: `rag-assistant-project/app/services/rag_service.py`)
- Passage retrieval → Layout context: gets page context (evidence: `rag-assistant-project/app/services/rag_service.py`)
- RAG service → Grounded prompt: builds prompt (evidence: `rag-assistant-project/app/services/rag_service.py`)
- RAG service → Ollama client: requests completion (evidence: `rag-assistant-project/app/services/rag_service.py`)
- Ollama client → Ollama model: sends prompt (evidence: `rag-assistant-project/app/services/ollama_client.py`)
- Academic PDFs → PDF preparation: provides PDFs (evidence: `README.md`)
- PDF preparation → Chroma store: indexes chunks (evidence: `README.md`)
- PDF preparation → Layout context: analyzes pages (evidence: `README.md`)
- Sample indexer → Chroma store: adds samples (evidence: `rag-assistant-project/index_samples.py`)
