# anujjandhyala12/langgraph-rag-agent architecture

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

- Interactive diagram: https://gitdiagram.com/anujjandhyala12/langgraph-rag-agent
- Repository: https://github.com/anujjandhyala12/langgraph-rag-agent

## Overview

This is a credit-risk assistant combining natural-language answers and report summaries, document ingestion, and loan-default prediction. Users submit queries or applicant details through FastAPI; queries pass through LangGraph routing to RAG, summarization, or direct-answer tools, while predictions use the separate prediction endpoint. The RAG subsystem chunks and embeds documents for Pinecone retrieval, and training/report-generation scripts prepare model and knowledge-base artifacts. The README documents some capabilities beyond the sampled implementation; arrows reflect shown calls or explicit documentation.

Main entry points: [`app/rag.py`](https://github.com/anujjandhyala12/langgraph-rag-agent/blob/main/app/rag.py) (Retrieval and ingestion), [`app/main.py`](https://github.com/anujjandhyala12/langgraph-rag-agent/blob/main/app/main.py) (FastAPI endpoints), [`app/graph.py`](https://github.com/anujjandhyala12/langgraph-rag-agent/blob/main/app/graph.py) (LangGraph router), [`app/tools.py`](https://github.com/anujjandhyala12/langgraph-rag-agent/blob/main/app/tools.py) (RAG answers)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_api["API"]
  node_fastapi["FastAPI endpoints<br/>[main.py]"]
end

subgraph group_agent["Agent"]
  node_router["LangGraph router<br/>[graph.py]"]
  node_ragtool["RAG answers<br/>[tools.py]"]
  node_summarytool["Report summaries<br/>[tools.py]"]
  node_directtool["Direct answers<br/>[tools.py]"]
end

subgraph group_knowledge["Knowledge"]
  node_retrieval["Retrieval and ingestion<br/>[rag.py]"]
  node_embeddings["Text embeddings<br/>[rag.py]"]
  node_pinecone[("Pinecone index")]
  node_reportgen["Risk report generation<br/>[summarize_data.py]"]
  node_report["Knowledge report"]
end

subgraph group_risk["Risk Modeling"]
  node_prediction["Risk prediction<br/>[tools.py]"]
  node_model["XGBoost model<br/>[model.pkl]"]
  node_training["Model training<br/>[train.py]"]
end

node_user(("User"))
node_claude["Claude LLM"]

node_user -->|"submits request"| node_fastapi
node_fastapi -->|"invokes query"| node_router
node_router -->|"routes RAG"| node_ragtool
node_router -->|"routes summary"| node_summarytool
node_router -->|"routes direct"| node_directtool
node_fastapi -->|"calls prediction"| node_prediction
node_fastapi -->|"ingests file"| node_retrieval
node_ragtool -->|"retrieves context"| node_retrieval
node_summarytool -->|"retrieves context"| node_retrieval
node_retrieval -->|"embeds chunks"| node_embeddings
node_retrieval -->|"reads and writes"| node_pinecone
node_ragtool -->|"generates answer"| node_claude
node_summarytool -->|"generates summary"| node_claude
node_directtool -->|"generates answer"| node_claude
node_prediction -->|"scores applicant"| node_model
node_prediction -->|"explains result"| node_claude
node_training -->|"saves model"| node_model
node_reportgen -->|"writes report"| node_report
node_reportgen -.->|"uploads report"| node_pinecone

click node_fastapi "https://github.com/anujjandhyala12/langgraph-rag-agent/blob/main/app/main.py"
click node_router "https://github.com/anujjandhyala12/langgraph-rag-agent/blob/main/app/graph.py"
click node_ragtool "https://github.com/anujjandhyala12/langgraph-rag-agent/blob/main/app/tools.py"
click node_summarytool "https://github.com/anujjandhyala12/langgraph-rag-agent/blob/main/app/tools.py"
click node_directtool "https://github.com/anujjandhyala12/langgraph-rag-agent/blob/main/app/tools.py"
click node_retrieval "https://github.com/anujjandhyala12/langgraph-rag-agent/blob/main/app/rag.py"
click node_embeddings "https://github.com/anujjandhyala12/langgraph-rag-agent/blob/main/app/rag.py"
click node_prediction "https://github.com/anujjandhyala12/langgraph-rag-agent/blob/main/app/tools.py"
click node_model "https://github.com/anujjandhyala12/langgraph-rag-agent/blob/main/ml/model.pkl"
click node_training "https://github.com/anujjandhyala12/langgraph-rag-agent/blob/main/ml/train.py"
click node_reportgen "https://github.com/anujjandhyala12/langgraph-rag-agent/blob/main/ml/summarize_data.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_fastapi,node_user toneBlue
class node_router,node_ragtool,node_summarytool,node_directtool toneAmber
class node_retrieval,node_embeddings,node_pinecone,node_reportgen,node_report toneMint
class node_prediction,node_model,node_training toneRose
class node_claude toneIndigo
```

## Components

### API

- [FastAPI endpoints](https://github.com/anujjandhyala12/langgraph-rag-agent/blob/main/app/main.py): `app/main.py`

### Agent

- [LangGraph router](https://github.com/anujjandhyala12/langgraph-rag-agent/blob/main/app/graph.py): `app/graph.py`
- [RAG answers](https://github.com/anujjandhyala12/langgraph-rag-agent/blob/main/app/tools.py): `app/tools.py`
- [Report summaries](https://github.com/anujjandhyala12/langgraph-rag-agent/blob/main/app/tools.py): `app/tools.py`
- [Direct answers](https://github.com/anujjandhyala12/langgraph-rag-agent/blob/main/app/tools.py): `app/tools.py`

### Knowledge

- [Retrieval and ingestion](https://github.com/anujjandhyala12/langgraph-rag-agent/blob/main/app/rag.py): `app/rag.py`
- [Text embeddings](https://github.com/anujjandhyala12/langgraph-rag-agent/blob/main/app/rag.py): `app/rag.py`
- **Pinecone index**
- [Risk report generation](https://github.com/anujjandhyala12/langgraph-rag-agent/blob/main/ml/summarize_data.py): `ml/summarize_data.py`
- **Knowledge report**

### Risk Modeling

- [Risk prediction](https://github.com/anujjandhyala12/langgraph-rag-agent/blob/main/app/tools.py): `app/tools.py`
- [XGBoost model](https://github.com/anujjandhyala12/langgraph-rag-agent/blob/main/ml/model.pkl): `ml/model.pkl`
- [Model training](https://github.com/anujjandhyala12/langgraph-rag-agent/blob/main/ml/train.py): `ml/train.py`

### Other components

- **User**
- **Claude LLM**

## Connections

- User → FastAPI endpoints: submits request (evidence: `README.md`)
- FastAPI endpoints → LangGraph router: invokes query (evidence: `app/main.py`)
- LangGraph router → RAG answers: routes RAG (evidence: `app/graph.py`)
- LangGraph router → Report summaries: routes summary (evidence: `app/graph.py`)
- LangGraph router → Direct answers: routes direct (evidence: `app/graph.py`)
- FastAPI endpoints → Risk prediction: calls prediction (evidence: `app/main.py`)
- FastAPI endpoints → Retrieval and ingestion: ingests file (evidence: `app/main.py`)
- RAG answers → Retrieval and ingestion: retrieves context (evidence: `app/tools.py`)
- Report summaries → Retrieval and ingestion: retrieves context (evidence: `app/tools.py`)
- Retrieval and ingestion → Text embeddings: embeds chunks (evidence: `app/rag.py`)
- Retrieval and ingestion → Pinecone index: reads and writes (evidence: `app/rag.py`)
- RAG answers → Claude LLM: generates answer (evidence: `app/tools.py`)
- Report summaries → Claude LLM: generates summary (evidence: `app/tools.py`)
- Direct answers → Claude LLM: generates answer (evidence: `app/tools.py`)
- Risk prediction → XGBoost model: scores applicant (evidence: `app/tools.py`)
- Risk prediction → Claude LLM: explains result (evidence: `app/tools.py`)
- Model training → XGBoost model: saves model (evidence: `ml/train.py`)
- Risk report generation → Knowledge report: writes report (evidence: `ml/summarize_data.py`)
- Risk report generation → Pinecone index: uploads report (evidence: `README.md`)
