# entbappy/build-a-complete-medical-chatbot-with-llms-langchain-pinecone-flask-aws architecture

> Architecture diagram of the GitHub repository entbappy/build-a-complete-medical-chatbot-with-llms-langchain-pinecone-flask-aws, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-23). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/entbappy/build-a-complete-medical-chatbot-with-llms-langchain-pinecone-flask-aws
- Repository: https://github.com/entbappy/build-a-complete-medical-chatbot-with-llms-langchain-pinecone-flask-aws

## Overview

##### Main architectural layers and components
a. Data Ingestion & Indexing
- store_index.py reads Medical_book.pdf, converts to embeddings via LangChain/OpenAI, and pushes vectors to Pinecone.
b. Backend/API Layer
- app.py (Flask app) exposes endpoints (e.g., `/chat`) that receive user messages, call the LangChain prompt logic, query Pinecone, and fetch OpenAI completions.
- src/helper.py & src/prompt.py encapsulate prompt templates and helper functions.
c. Frontend/UI Layer
- templates/chat.html renders the chat interface; static/style.css provides styling.
d. External Services
- OpenAI API for LLM completions
- Pinecone for vector database
e. Infrastructure & CI/CD
- Dockerfile builds a container image of the Flask app + dependencies.
- GitHub Actions workflow (.github/workflows/cicd.yaml) builds the image, pushes to AWS ECR, and triggers deployment on an EC2 self-hosted runner.

##### Relationships and data flows
- User → HTTP → Flask endpoint
- Flask → Pinecone (vector search)
- Flask → OpenAI (text completion)
- store_index.py → LangChain/OpenAI → Pinecone (initial indexing)
- GitHub Actions → build Docker → push to ECR → EC2 pulls image → Docker run

##### Architectural patterns & technologies
- Monolithic Flask service with modular helper/prompt packages (MVC-style separation).
- Batch indexing component separate from runtime (store_index script).
- Dockerized deployment with AWS ECR + EC2 (self-hosted runner).
- CI/CD via GitHub Actions.

##### Capturing essential details without overthinking
- Major modules: store_index.py, app.py, src/, templates/, static/, Dockerfile, GitHub Actions.
- Don’t dive into every helper function—group them logically.

- Reflects the separation of concerns (ingestion vs. runtime vs. UI).
- Illustrates interactions among modules and external services.
- Includes infrastructure and CI/CD elements.
This will ensure the architecture is both accurate and communicative for stakeholders and future contributors.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Ingestion & Indexing
    subgraph "Data Ingestion & Indexing"
        MedicalPDF["Medical_book.pdf"]:::datastore
        StoreIndex["store_index.py"]:::compute
        LangChain["LangChain/OpenAI Embedding"]:::external
        PineconeDB[(Pinecone Vector DB)]:::datastore
    end

    %% Backend/API Layer
    subgraph "Backend/API Layer"
        FlaskAPI["Flask API (app.py)"]:::compute
        Prompt["Prompt Templates (src/prompt.py)"]:::compute
        Helper["Helper Functions (src/helper.py)"]:::compute
        Requirements["requirements.txt"]:::compute
        Setup["setup.py"]:::compute
    end

    %% Frontend/UI Layer
    subgraph "Frontend/UI Layer"
        ChatHTML["Chat Interface (templates/chat.html)"]:::compute
        StyleCSS["Styling (static/style.css)"]:::compute
    end

    %% External Services
    subgraph "External Services"
        OpenAI["OpenAI API"]:::external
    end

    %% Infrastructure & CI/CD
    subgraph "Infrastructure & CI/CD"
        DockerfileNode["Dockerfile"]:::infra
        CICD["GitHub Actions (.github/workflows/cicd.yaml)"]:::infra
        ECR["AWS ECR"]:::infra
        EC2["EC2 Self-Hosted Runner"]:::infra
    end

    %% Data Ingestion Flow
    MedicalPDF -->|reads PDF| StoreIndex
    StoreIndex -->|embeds vectors| LangChain
    LangChain -->|push vectors| PineconeDB

    %% Runtime Flow
    ChatHTML -->|HTTP request| FlaskAPI
    FlaskAPI -->|load templates & helpers| Prompt
    FlaskAPI -->|call helper| Helper
    FlaskAPI -->|query| PineconeDB
    FlaskAPI -->|request| OpenAI
    OpenAI -->|response| FlaskAPI
    FlaskAPI -->|HTTP response| ChatHTML

    %% CI/CD & Deployment
    CICD -->|build image| DockerfileNode
    CICD -->|push image| ECR
    EC2 -->|pull & run| ECR
    EC2 -->|hosts| FlaskAPI

    %% Click Events
    click StoreIndex "https://github.com/entbappy/build-a-complete-medical-chatbot-with-llms-langchain-pinecone-flask-aws/blob/main/store_index.py"
    click MedicalPDF "https://github.com/entbappy/build-a-complete-medical-chatbot-with-llms-langchain-pinecone-flask-aws/blob/main/data/Medical_book.pdf"
    click FlaskAPI "https://github.com/entbappy/build-a-complete-medical-chatbot-with-llms-langchain-pinecone-flask-aws/blob/main/app.py"
    click Prompt "https://github.com/entbappy/build-a-complete-medical-chatbot-with-llms-langchain-pinecone-flask-aws/blob/main/src/prompt.py"
    click Helper "https://github.com/entbappy/build-a-complete-medical-chatbot-with-llms-langchain-pinecone-flask-aws/blob/main/src/helper.py"
    click ChatHTML "https://github.com/entbappy/build-a-complete-medical-chatbot-with-llms-langchain-pinecone-flask-aws/blob/main/templates/chat.html"
    click StyleCSS "https://github.com/entbappy/build-a-complete-medical-chatbot-with-llms-langchain-pinecone-flask-aws/blob/main/static/style.css"
    click DockerfileNode "https://github.com/entbappy/build-a-complete-medical-chatbot-with-llms-langchain-pinecone-flask-aws/tree/main/Dockerfile"
    click CICD "https://github.com/entbappy/build-a-complete-medical-chatbot-with-llms-langchain-pinecone-flask-aws/blob/main/.github/workflows/cicd.yaml"
    click Requirements "https://github.com/entbappy/build-a-complete-medical-chatbot-with-llms-langchain-pinecone-flask-aws/blob/main/requirements.txt"
    click Setup "https://github.com/entbappy/build-a-complete-medical-chatbot-with-llms-langchain-pinecone-flask-aws/blob/main/setup.py"

    %% Styles
    classDef compute fill:#ADD8E6,stroke:#333,stroke-width:1px
    classDef datastore fill:#90EE90,stroke:#333,stroke-width:1px
    classDef external fill:#FFA500,stroke:#333,stroke-width:1px
    classDef infra fill:#D3D3D3,stroke:#333,stroke-width:1px
```
