# sanjeevsranjan/customchatbot architecture

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

- Interactive diagram: https://gitdiagram.com/sanjeevsranjan/customchatbot
- Repository: https://github.com/sanjeevsranjan/customchatbot

## Overview

#### Purpose and entry points
This is a Python medical-document RAG chatbot. It indexes `data/Medical_book.pdf` into Pinecone, then serves a Flask chat UI that answers questions with an OpenAI GPT model using retrieved medical-book context.

Primary commands:
- Build the vector index: `store_index.py`
- Run the web server: `app.py`
- Containerize/run the service: `Dockerfile`

#### Document ingestion and indexing
`store_index.py` is the offline ingestion entry point. It loads the medical PDF, splits its text into retrieval-sized chunks, creates embeddings, and persists them to Pinecone.

Core paths:
- `store_index.py`
- `src/helper.py`
- `data/Medical_book.pdf`

This stage establishes the external vector-store boundary: source document content is transformed into embeddings and uploaded, rather than stored locally by the application.

#### Shared RAG utilities
`src/helper.py` centralizes reusable document-processing and vector-store setup logic used by the indexing and/or serving paths. It is the likely boundary for PDF loading, chunking, embedding creation, and Pinecone connection configuration.

Core paths:
- `src/helper.py`
- `src/__init__.py`
- `requirements.txt`

The runtime depends on LangChain-style orchestration, OpenAI embeddings/LLM access, and Pinecone retrieval. Credentials are supplied through root `.env` variables, not hardcoded.

#### Prompt and answer generation
`src/prompt.py` defines the chatbot’s prompt contract. The serving path combines a user question with retrieved Pinecone context and sends that assembled prompt to the GPT provider.

Core paths:
- `src/prompt.py`
- `app.py`
- `src/helper.py`

The important control boundary is retrieval versus generation: Pinecone provides grounding context; OpenAI generates the final natural-language response.

#### Flask application and chat delivery
`app.py` is the online application entry point. It initializes Flask, connects the RAG chain/components, renders the chat page, accepts user input, and returns generated answers.

Core paths:
- `app.py`
- `templates/chat.html`
- `Static/style.css`

There are two chat-template locations, `templates/chat.html` and `data/templates/chat.html`; Flask convention favors the root `templates/` copy, while the `data/` copy may be legacy or duplicated content.

#### Runtime, infrastructure, and deployment
The application targets Python 3.10 and is containerized with `Dockerfile`. GitHub Actions supports CI/CD, building an image, pushing it to AWS ECR, and deploying/running it on an EC2 self-hosted runner.

Core paths:
- `Dockerfile`
- `.github/workflows/cicd.yaml`
- `requirements.txt`

Material external services are OpenAI, Pinecone, AWS ECR, and AWS EC2. Deployment requires AWS credentials plus `PINECONE_API_KEY` and `OPENAI_API_KEY` as GitHub secrets/environment variables.

Main entry points: [`app.py`](https://github.com/sanjeevsranjan/customchatbot/blob/main/app.py) (Flask app), [`src/helper.py`](https://github.com/sanjeevsranjan/customchatbot/blob/main/src/helper.py) (RAG utilities), [`store_index.py`](https://github.com/sanjeevsranjan/customchatbot/blob/main/store_index.py) (Index builder), [`.github/workflows/cicd.yaml`](https://github.com/sanjeevsranjan/customchatbot/blob/main/.github/workflows/cicd.yaml) (GitHub Actions)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingestion["Offline Indexing"]
  node_pdf["Medical book PDF<br/>source document<br/>[Medical_book.pdf]"]
  node_indexer["Index builder<br/>Python entry point<br/>[store_index.py]"]
end

subgraph group_application["Chat Service"]
  node_flask["Flask app<br/>Python entry point<br/>[app.py]"]
  node_chat_template["Chat page<br/>HTML template<br/>[chat.html]"]
  node_styles["Chat styles<br/>CSS<br/>[style.css]"]
  node_prompt["Prompt contract<br/>prompt definition<br/>[prompt.py]"]
end

subgraph group_deployment["CI/CD and Hosting"]
  node_dockerfile["Container build<br/>Dockerfile"]
  node_cicd["GitHub Actions<br/>CI/CD workflow<br/>[cicd.yaml]"]
  node_ecr[("AWS ECR<br/>container registry")]
  node_ec2["AWS EC2 runner<br/>deployment host"]
end

node_helper["RAG utilities<br/>shared processing<br/>[helper.py]"]
node_pinecone[("Pinecone<br/>vector store")]
node_openai{{"OpenAI<br/>embedding and LLM provider"}}
node_requirements["Python dependencies<br/>dependency manifest<br/>[requirements.txt]"]

node_pdf -->|"loaded by"| node_indexer
node_indexer -->|"uses"| node_helper
node_helper -->|"creates embeddings"| node_openai
node_helper -->|"uploads vectors"| node_pinecone
node_flask -->|"renders"| node_chat_template
node_chat_template -->|"uses"| node_styles
node_flask -->|"initializes retrieval"| node_helper
node_flask -->|"retrieves context"| node_pinecone
node_flask -->|"assembles prompt"| node_prompt
node_flask -->|"generates answer"| node_openai
node_requirements -.->|"dependencies"| node_indexer
node_requirements -.->|"dependencies"| node_flask
node_dockerfile -->|"packages"| node_flask
node_cicd -->|"builds image"| node_dockerfile
node_cicd -->|"pushes image"| node_ecr
node_ecr -->|"deploys image"| node_ec2
node_ec2 -->|"runs container"| node_flask

click node_pdf "https://github.com/sanjeevsranjan/customchatbot/blob/main/data/Medical_book.pdf"
click node_indexer "https://github.com/sanjeevsranjan/customchatbot/blob/main/store_index.py"
click node_helper "https://github.com/sanjeevsranjan/customchatbot/blob/main/src/helper.py"
click node_flask "https://github.com/sanjeevsranjan/customchatbot/blob/main/app.py"
click node_chat_template "https://github.com/sanjeevsranjan/customchatbot/blob/main/templates/chat.html"
click node_styles "https://github.com/sanjeevsranjan/customchatbot/blob/main/Static/style.css"
click node_prompt "https://github.com/sanjeevsranjan/customchatbot/blob/main/src/prompt.py"
click node_requirements "https://github.com/sanjeevsranjan/customchatbot/blob/main/requirements.txt"
click node_dockerfile "https://github.com/sanjeevsranjan/customchatbot/blob/main/Dockerfile"
click node_cicd "https://github.com/sanjeevsranjan/customchatbot/blob/main/.github/workflows/cicd.yaml"

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_pdf,node_indexer toneBlue
class node_flask,node_chat_template,node_styles,node_prompt toneAmber
class node_dockerfile,node_cicd,node_ecr,node_ec2 toneMint
class node_helper,node_pinecone,node_openai,node_requirements toneNeutral
```

## Components

### Offline Indexing

Builds the searchable medical-book index.

- [Medical book PDF](https://github.com/sanjeevsranjan/customchatbot/blob/main/data/Medical_book.pdf): source document · `data/Medical_book.pdf`
- [Index builder](https://github.com/sanjeevsranjan/customchatbot/blob/main/store_index.py): Python entry point · `store_index.py`

### Chat Service

Online Flask RAG request path.

- [Flask app](https://github.com/sanjeevsranjan/customchatbot/blob/main/app.py): Python entry point · Handles chat requests and runs the RAG flow. · `app.py`
- [Chat page](https://github.com/sanjeevsranjan/customchatbot/blob/main/templates/chat.html): HTML template · `templates/chat.html`
- [Chat styles](https://github.com/sanjeevsranjan/customchatbot/blob/main/Static/style.css): CSS · `Static/style.css`
- [Prompt contract](https://github.com/sanjeevsranjan/customchatbot/blob/main/src/prompt.py): prompt definition · `src/prompt.py`

### CI/CD and Hosting

Builds and deploys the container.

- [Container build](https://github.com/sanjeevsranjan/customchatbot/blob/main/Dockerfile): Dockerfile · Packages the Python 3.10 chat service. · `Dockerfile`
- [GitHub Actions](https://github.com/sanjeevsranjan/customchatbot/blob/main/.github/workflows/cicd.yaml): CI/CD workflow · Builds, publishes, and deploys the image. · `.github/workflows/cicd.yaml`
- **AWS ECR**: container registry
- **AWS EC2 runner**: deployment host · Self-hosted runner that runs the deployed container.

### Other components

- [RAG utilities](https://github.com/sanjeevsranjan/customchatbot/blob/main/src/helper.py): shared processing · Loads, chunks, embeds documents, and configures Pinecone. · `src/helper.py`
- **Pinecone**: vector store · Stores medical-book embeddings and serves retrieval context.
- **OpenAI**: embedding and LLM provider · Creates embeddings and generates grounded answers.
- [Python dependencies](https://github.com/sanjeevsranjan/customchatbot/blob/main/requirements.txt): dependency manifest · Includes Flask, LangChain-style RAG, OpenAI, and Pinecone libraries. · `requirements.txt`

## Connections

- Medical book PDF → Index builder: loaded by
- Index builder → RAG utilities: uses
- RAG utilities → OpenAI: creates embeddings
- RAG utilities → Pinecone: uploads vectors
- Flask app → Chat page: renders
- Chat page → Chat styles: uses
- Flask app → RAG utilities: initializes retrieval
- Flask app → Pinecone: retrieves context
- Flask app → Prompt contract: assembles prompt
- Flask app → OpenAI: generates answer
- Python dependencies → Index builder: dependencies
- Python dependencies → Flask app: dependencies
- Container build → Flask app: packages
- GitHub Actions → Container build: builds image
- GitHub Actions → AWS ECR: pushes image
- AWS ECR → AWS EC2 runner: deploys image
- AWS EC2 runner → Flask app: runs container
