# tuanduy35399/agent_rag_langchain architecture

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

- Interactive diagram: https://gitdiagram.com/tuanduy35399/agent_rag_langchain
- Repository: https://github.com/tuanduy35399/agent_rag_langchain

## Overview

This is a Streamlit document-Q&A application using retrieval-augmented generation. Users upload files, which are parsed and chunked into a PostgreSQL vector store; questions invoke a DeepAgent that searches for relevant chunks, saves them as Markdown in its virtual filesystem, delegates chunk analysis, and synthesizes an answer. The repository also has a PDF-based indexing path. The excerpts show the principal calls and configuration; unsampled portions of the UI and framework internals are not mapped.

Main entry points: [`agent.py`](https://github.com/tuanduy35399/agent_rag_langchain/blob/main/agent.py) (DeepAgent), [`main.py`](https://github.com/tuanduy35399/agent_rag_langchain/blob/main/main.py) (Streamlit Q&A), [`indexing.py`](https://github.com/tuanduy35399/agent_rag_langchain/blob/main/indexing.py) (PDF indexer), [`tools.py`](https://github.com/tuanduy35399/agent_rag_langchain/blob/main/tools.py) (Documentation search)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Document ingestion"]
  node_upload_parse["Upload parsing<br/>[main.py]"]
  node_splitter["Chunk splitting<br/>[main.py]"]
  node_pdf_reader["PDF reader<br/>[file_reader.py]"]
  node_pdf_index["PDF indexer<br/>[indexing.py]"]
end

subgraph group_retrieve["Retrieval and storage"]
  node_vector[("Vector store<br/>[indexing.py]")]
  node_search["Documentation search<br/>[tools.py]"]
  node_backend["Agent file backend<br/>[tools.py]"]
end

subgraph group_agent["Agent answering"]
  node_agent_runtime["DeepAgent<br/>[agent.py]"]
  node_instructions["Workflow prompts<br/>[prompts.py]"]
  node_analyst["Chunk analyst<br/>[agent.py]"]
  node_model{{"Chat model"}}
end

subgraph group_interface["User interface"]
  node_ui["Streamlit Q&amp;A<br/>[main.py]"]
  node_answer["Answer display<br/>[main.py]"]
end

node_user(("Document user"))

node_user -->|"uploads and asks"| node_ui
node_ui -->|"parses uploads"| node_upload_parse
node_upload_parse -->|"produces documents"| node_splitter
node_splitter -->|"indexes chunks"| node_vector
node_ui -->|"uses indexing resources"| node_pdf_index
node_pdf_index -->|"reads PDFs"| node_pdf_reader
node_pdf_index -->|"stores chunks"| node_vector
node_ui -->|"invokes agent"| node_agent_runtime
node_agent_runtime -->|"registers search tool"| node_search
node_search -->|"similarity searches"| node_vector
node_search -->|"uploads Markdown chunks"| node_backend
node_agent_runtime -->|"loads prompts"| node_instructions
node_agent_runtime -->|"registers subagent"| node_analyst
node_analyst -->|"reads retrieved files"| node_backend
node_agent_runtime -->|"configures chat model"| node_model
node_ui -->|"displays response"| node_answer

click node_ui "https://github.com/tuanduy35399/agent_rag_langchain/blob/main/main.py"
click node_upload_parse "https://github.com/tuanduy35399/agent_rag_langchain/blob/main/main.py"
click node_splitter "https://github.com/tuanduy35399/agent_rag_langchain/blob/main/main.py"
click node_pdf_reader "https://github.com/tuanduy35399/agent_rag_langchain/blob/main/file_reader.py"
click node_pdf_index "https://github.com/tuanduy35399/agent_rag_langchain/blob/main/indexing.py"
click node_vector "https://github.com/tuanduy35399/agent_rag_langchain/blob/main/indexing.py"
click node_search "https://github.com/tuanduy35399/agent_rag_langchain/blob/main/tools.py"
click node_backend "https://github.com/tuanduy35399/agent_rag_langchain/blob/main/tools.py"
click node_agent_runtime "https://github.com/tuanduy35399/agent_rag_langchain/blob/main/agent.py"
click node_instructions "https://github.com/tuanduy35399/agent_rag_langchain/blob/main/prompts.py"
click node_analyst "https://github.com/tuanduy35399/agent_rag_langchain/blob/main/agent.py"
click node_answer "https://github.com/tuanduy35399/agent_rag_langchain/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_upload_parse,node_splitter,node_pdf_reader,node_pdf_index,node_user toneBlue
class node_vector,node_search,node_backend toneAmber
class node_agent_runtime,node_instructions,node_analyst,node_model toneMint
class node_ui,node_answer toneRose
```

## Components

### Document ingestion

- [Upload parsing](https://github.com/tuanduy35399/agent_rag_langchain/blob/main/main.py): `main.py`
- [Chunk splitting](https://github.com/tuanduy35399/agent_rag_langchain/blob/main/main.py): `main.py`
- [PDF reader](https://github.com/tuanduy35399/agent_rag_langchain/blob/main/file_reader.py): `file_reader.py`
- [PDF indexer](https://github.com/tuanduy35399/agent_rag_langchain/blob/main/indexing.py): `indexing.py`

### Retrieval and storage

- [Vector store](https://github.com/tuanduy35399/agent_rag_langchain/blob/main/indexing.py): `indexing.py`
- [Documentation search](https://github.com/tuanduy35399/agent_rag_langchain/blob/main/tools.py): `tools.py`
- [Agent file backend](https://github.com/tuanduy35399/agent_rag_langchain/blob/main/tools.py): `tools.py`

### Agent answering

- [DeepAgent](https://github.com/tuanduy35399/agent_rag_langchain/blob/main/agent.py): `agent.py`
- [Workflow prompts](https://github.com/tuanduy35399/agent_rag_langchain/blob/main/prompts.py): `prompts.py`
- [Chunk analyst](https://github.com/tuanduy35399/agent_rag_langchain/blob/main/agent.py): `agent.py`
- **Chat model**

### User interface

- [Streamlit Q&A](https://github.com/tuanduy35399/agent_rag_langchain/blob/main/main.py): `main.py`
- [Answer display](https://github.com/tuanduy35399/agent_rag_langchain/blob/main/main.py): `main.py`

### Other components

- **Document user**

## Connections

- Document user → Streamlit Q&A: uploads and asks (evidence: `main.py`)
- Streamlit Q&A → Upload parsing: parses uploads (evidence: `main.py`)
- Upload parsing → Chunk splitting: produces documents (evidence: `main.py`)
- Chunk splitting → Vector store: indexes chunks (evidence: `main.py`)
- Streamlit Q&A → PDF indexer: uses indexing resources (evidence: `main.py`)
- PDF indexer → PDF reader: reads PDFs (evidence: `indexing.py`)
- PDF indexer → Vector store: stores chunks (evidence: `indexing.py`)
- Streamlit Q&A → DeepAgent: invokes agent (evidence: `main.py`)
- DeepAgent → Documentation search: registers search tool (evidence: `agent.py`)
- Documentation search → Vector store: similarity searches (evidence: `tools.py`)
- Documentation search → Agent file backend: uploads Markdown chunks (evidence: `tools.py`)
- DeepAgent → Workflow prompts: loads prompts (evidence: `agent.py`)
- DeepAgent → Chunk analyst: registers subagent (evidence: `agent.py`)
- Chunk analyst → Agent file backend: reads retrieved files (evidence: `agent.py`)
- DeepAgent → Chat model: configures chat model (evidence: `agent.py`)
- Streamlit Q&A → Answer display: displays response (evidence: `main.py`)
