# ayushsaini9156/astrarag-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/ayushsaini9156/astrarag-chatbot
- Repository: https://github.com/ayushsaini9156/astrarag-chatbot

## Overview

1. **Repository purpose**
   - This is a Python-based chatbot system centered on a **RAG + agent** architecture. The repo name and module layout indicate a question-answering assistant built over local documents in `docs_dir/`.

2. **Top-level shape**
   - The code is split into four main runtime areas under `src/`:
     - `frontend_src` for the user-facing app
     - `backend_src` for the API and orchestration layer
     - `agents_src` for the LLM/agent logic
     - `rag_doc_ingestion` for preparing source documents
   - This separation suggests clear boundaries between presentation, request handling, AI reasoning, and offline document processing.

3. **User interaction layer**
   - `src/frontend_src/app.py` is the entry point for the client-facing application.
   - `frontend_settings.py` implies frontend-specific environment/config values.
   - The frontend likely sends chat requests to the backend rather than calling the model directly, keeping the UI thin.

4. **Backend API and service boundary**
   - `src/backend_src/main.py` is the backend entry point.
   - `src/backend_src/api/chat.py` exposes the chat endpoint surface.
   - `src/backend_src/services/chat.py` holds chat orchestration/business logic, which likely mediates between incoming requests and the agent subsystem.
   - This creates a clean separation between transport concerns and AI execution.

5. **Agent orchestration core**
   - `src/agents_src/crew.py` indicates a crew/task style orchestration pattern, likely coordinating one or more agent roles.
   - `agents/question_answer_agent.py` defines the QA-focused agent behavior.
   - `tasks/question_answer_task.py` defines the work item the agent performs.
   - This layer is where the system likely decides how to reason over user queries before returning an answer.

6. **LLM abstraction**
   - `src/agents_src/llm/get_llm.py` and `llm_configuration.py` encapsulate model selection and setup.
   - This suggests the repository is designed to switch LLM backends or parameters without touching the rest of the agent logic.
   - The LLM layer is a distinct dependency boundary between application logic and the model provider.

7. **RAG and tool integration**
   - `src/agents_src/tools/rag_qa_tool.py` is the main clue that the agent is augmented with retrieval.
   - The agent likely uses this tool to pull relevant context from indexed documents before answering.
   - The architecture therefore combines generative reasoning with document-grounded lookup, rather than relying on the model alone.

8. **Document ingestion pipeline**
   - `src/rag_doc_ingestion/ingest_docs.py` is the offline/preprocessing entry point for loading documents into the RAG corpus.
   - The presence of `docs_dir/12. Ecosystem.pdf` and `docs_dir/6. Evolution.pdf` shows the system is already wired to answer from a fixed document set.
   - `doc_ingestion_settings.py` likely controls ingestion paths and indexing parameters.
   - The ingestion pipeline is a separate boundary from runtime chat handling.

9. **Configuration layering**
   - Each major subsystem has its own settings module:
     - `backend_settings.py`
     - `frontend_settings.py`
     - `agent_settings.py`
     - `doc_ingestion_settings.py`
   - `env_template.txt` suggests the system is environment-driven and expects external configuration for secrets, endpoints, and model settings.

10. **Probable data flow**
   - Offline flow: PDFs in `docs_dir/` -> ingestion script -> retrieval index/store -> available to `rag_qa_tool`.
   - Online flow: user question in frontend -> backend chat API -> service layer -> crew/agent/task -> LLM + retrieval tool -> answer returned to frontend.
   - The main architectural value is that documents are prepared once, then reused at query time for grounded responses.

11. **Technology/runtime signals**
   - The project is clearly Python-based, with `requirements.txt` and package-style `src/` modules.
   - The code organization suggests a modular service rather than a monolith with one entry point.
   - The use of “crew,” agents, and tools points to an agent framework or a custom orchestration abstraction, but the repo structure alone does not show the exact vendor dependency.

12. **Useful diagram boundaries**
   - A good architecture diagram should show four boxes: **Frontend**, **Backend API/Service**, **Agent + LLM/RAG Core**, and **Document Ingestion/Corpus**.
   - The key arrows are:
     - user requests into frontend
     - frontend requests to backend chat API
     - backend to agent orchestration
     - agent to LLM and retrieval tool
     - ingestion feeding the retrieval store used by the tool
   - The document corpus should be drawn as an external input to runtime chat, not as part of the request path.

Main entry points: [`src/agents_src/agents/question_answer_agent.py`](https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/agents_src/agents/question_answer_agent.py) (QA agent), [`src/backend_src/api/chat.py`](https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/backend_src/api/chat.py) (Chat API), [`src/backend_src/services/chat.py`](https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/backend_src/services/chat.py) (Chat service), [`src/agents_src/crew.py`](https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/agents_src/crew.py) (Crew)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Frontend"]
  node_frontend_app["Chat UI<br/>entrypoint<br/>[app.py]"]
  node_frontend_settings["Frontend config"]
end

subgraph group_backend["Backend API"]
  node_backend_main["Backend app<br/>entrypoint<br/>[main.py]"]
  node_backend_chat_api["Chat API<br/>route<br/>[chat.py]"]
  node_backend_chat_service["Chat service<br/>[chat.py]"]
  node_backend_settings["Backend config"]
end

subgraph group_agent_core["Agent Core"]
  node_crew["Crew<br/>orchestrator<br/>[crew.py]"]
  node_qa_agent["QA agent"]
  node_qa_task["QA task"]
  node_rag_tool["RAG tool<br/>[rag_qa_tool.py]"]
  node_llm_getter["LLM loader<br/>factory<br/>[get_llm.py]"]
  node_llm_config["LLM config"]
  node_agent_settings["Agent config<br/>[agent_settings.py]"]
end

subgraph group_ingestion["Ingestion"]
  node_ingest_docs["Ingest docs<br/>pipeline<br/>[ingest_docs.py]"]
  node_doc_settings["Ingest config"]
  node_docs_dir[("Document corpus<br/>content")]
end

node_frontend_app -->|"chat requests"| node_backend_chat_api
node_frontend_app -.->|"loads"| node_frontend_settings
node_backend_main -->|"serves"| node_backend_chat_api
node_backend_chat_api -->|"delegates"| node_backend_chat_service
node_backend_chat_service -->|"invokes"| node_crew
node_backend_chat_service -.->|"loads"| node_backend_settings
node_crew -->|"assigns"| node_qa_task
node_qa_task -->|"runs on"| node_qa_agent
node_qa_agent -->|"uses"| node_rag_tool
node_qa_agent -->|"gets model"| node_llm_getter
node_llm_getter -.->|"configured by"| node_llm_config
node_qa_agent -.->|"loads"| node_agent_settings
node_rag_tool -->|"retrieves from"| node_docs_dir
node_ingest_docs -->|"ingests"| node_docs_dir
node_ingest_docs -.->|"configured by"| node_doc_settings
node_doc_settings -.->|"feeds index"| node_rag_tool
node_backend_chat_api -->|"routes to"| node_crew

click node_frontend_app "https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/frontend_src/app.py"
click node_frontend_settings "https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/frontend_src/config/frontend_settings.py"
click node_backend_main "https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/backend_src/main.py"
click node_backend_chat_api "https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/backend_src/api/chat.py"
click node_backend_chat_service "https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/backend_src/services/chat.py"
click node_backend_settings "https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/backend_src/config/backend_settings.py"
click node_crew "https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/agents_src/crew.py"
click node_qa_agent "https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/agents_src/agents/question_answer_agent.py"
click node_qa_task "https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/agents_src/tasks/question_answer_task.py"
click node_rag_tool "https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/agents_src/tools/rag_qa_tool.py"
click node_llm_getter "https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/agents_src/llm/get_llm.py"
click node_llm_config "https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/agents_src/llm/llm_configuration.py"
click node_agent_settings "https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/agents_src/config/agent_settings.py"
click node_ingest_docs "https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/rag_doc_ingestion/ingest_docs.py"
click node_doc_settings "https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/rag_doc_ingestion/config/doc_ingestion_settings.py"
click node_docs_dir "https://github.com/ayushsaini9156/astrarag-chatbot/tree/main/docs_dir"

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_frontend_app,node_frontend_settings toneBlue
class node_backend_main,node_backend_chat_api,node_backend_chat_service,node_backend_settings toneAmber
class node_crew,node_qa_agent,node_qa_task,node_rag_tool,node_llm_getter,node_llm_config,node_agent_settings toneMint
class node_ingest_docs,node_doc_settings,node_docs_dir toneRose
```

## Components

### Frontend

User-facing chat application

- [Chat UI](https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/frontend_src/app.py): entrypoint · Frontend application entry point · `src/frontend_src/app.py`
- [Frontend config](https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/frontend_src/config/frontend_settings.py): config · Frontend environment and runtime settings · `src/frontend_src/config/frontend_settings.py`

### Backend API

HTTP and chat orchestration boundary

- [Backend app](https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/backend_src/main.py): entrypoint · Backend service entry point · `src/backend_src/main.py`
- [Chat API](https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/backend_src/api/chat.py): route · Chat endpoint surface · `src/backend_src/api/chat.py`
- [Chat service](https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/backend_src/services/chat.py): service · Orchestrates chat request handling · `src/backend_src/services/chat.py`
- [Backend config](https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/backend_src/config/backend_settings.py): config · Backend environment and runtime settings · `src/backend_src/config/backend_settings.py`

### Agent Core

Crew, agent, task, LLM, and retrieval logic

- [Crew](https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/agents_src/crew.py): orchestrator · Coordinates agent execution · `src/agents_src/crew.py`
- [QA agent](https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/agents_src/agents/question_answer_agent.py): agent · Question-answering agent behavior · `src/agents_src/agents/question_answer_agent.py`
- [QA task](https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/agents_src/tasks/question_answer_task.py): task · Work item for the QA agent · `src/agents_src/tasks/question_answer_task.py`
- [RAG tool](https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/agents_src/tools/rag_qa_tool.py): tool · Retrieval-augmented QA tool · `src/agents_src/tools/rag_qa_tool.py`
- [LLM loader](https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/agents_src/llm/get_llm.py): factory · Builds or selects the active model backend · `src/agents_src/llm/get_llm.py`
- [LLM config](https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/agents_src/llm/llm_configuration.py): config · Model and provider configuration · `src/agents_src/llm/llm_configuration.py`
- [Agent config](https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/agents_src/config/agent_settings.py): config · Agent subsystem settings · `src/agents_src/config/agent_settings.py`

### Ingestion

Offline document preparation for retrieval

- [Ingest docs](https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/rag_doc_ingestion/ingest_docs.py): pipeline · Offline document ingestion entry point · `src/rag_doc_ingestion/ingest_docs.py`
- [Ingest config](https://github.com/ayushsaini9156/astrarag-chatbot/blob/main/src/rag_doc_ingestion/config/doc_ingestion_settings.py): config · Document ingestion settings · `src/rag_doc_ingestion/config/doc_ingestion_settings.py`
- [Document corpus](https://github.com/ayushsaini9156/astrarag-chatbot/tree/main/docs_dir): content · Source PDFs used for retrieval · `docs_dir`

## Connections

- Chat UI → Chat API: chat requests · Frontend sends user messages to backend API
- Chat UI → Frontend config: loads · Frontend reads its runtime configuration
- Backend app → Chat API: serves · Backend mounts the chat API
- Chat API → Chat service: delegates · API hands off request handling to service logic
- Chat service → Crew: invokes · Chat service triggers agent orchestration
- Chat service → Backend config: loads · Backend service uses backend configuration
- Crew → QA task: assigns · Crew coordinates the QA task
- QA task → QA agent: runs on · Task is executed by the QA agent
- QA agent → RAG tool: uses · Agent consults retrieval tool for grounded answers
- QA agent → LLM loader: gets model · Agent resolves the active LLM backend
- LLM loader → LLM config: configured by · Model loader is driven by LLM configuration
- QA agent → Agent config: loads · Agent behavior is configured separately
- RAG tool → Document corpus: retrieves from · Retrieval tool queries the indexed document corpus
- Ingest docs → Document corpus: ingests · Offline pipeline reads source PDFs
- Ingest docs → Ingest config: configured by · Ingestion pipeline uses document settings
- Ingest config → RAG tool: feeds index · Ingestion settings shape the retrieval store used at query time
- Chat API → Crew: routes to · API requests flow into the agent runtime
