# spidy20/aws-assistant-rag-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/spidy20/aws-assistant-rag-chatbot
- Repository: https://github.com/spidy20/aws-assistant-rag-chatbot

## Overview

##### Project type and purpose
- This is a full-stack, serverless RAG (retrieval-augmented generation) ChatBot.
- Frontend: Streamlit app for demo (`app.py`).
- Backend: AWS Lambda function (Langchain GPT-4 handler) exposed via API Gateway, deployed via AWS SAM (`Lambda-App/template.yaml`).
- Vector DB: PostgreSQL + PGVector on an EC2 instance.
- Auxiliary scripts: data ingestion (`DataIngestion.py`) and connectivity test (`connect.py`).

##### File structure
- Top level:
- `app.py` – Streamlit UI
- `DataIngestion.py` – loads `aws_sample_qa.csv` into PGVector DB
- `connect.py` – verifies DB connectivity
- `aws_sample_qa.csv` – sample Q&A data
- `Lambda-App/` (SAM app)
- `template.yaml` – defines AWS::Serverless::Function (Lambda) and API Gateway
- `Backend/`
– `Lambda_Response_App.py` – Lambda handler implementing Langchain + DB calls
– `requirements.txt` – Lambda dependencies (langchain, psycopg2, etc.)

##### Insights from the README
- Architecture uses AWS SAM to deploy a Lambda + API Gateway REST endpoint.
- EC2 hosts the PostgreSQL with PGVector extension.
- Data flow: ingest → query via REST → Lambda → VectorDB → (optionally OpenAI GPT-4) → response.

## Diagram (Mermaid)

```mermaid
graph TD
    %% Client/Browser Layer
    subgraph "Client/Browser"
        direction TB
        User["User"]:::client
        UI["Streamlit App\n(app.py)"]:::frontend
    end

    %% Ingestion Pipeline
    subgraph "Ingestion Pipeline"
        direction TB
        IngestScript["Data Ingestion Script\n(DataIngestion.py)"]:::script
        ConnectScript["DB Connectivity Test\n(connect.py)"]:::script
        CSV["Sample Q&A Data\n(aws_sample_qa.csv)"]:::script
    end

    %% Serverless Infrastructure
    subgraph "Serverless Infrastructure"
        direction TB
        SAM["SAM Template\n(template.yaml)"]:::compute
        APIGW["API Gateway"]:::compute
        Lambda["Lambda_Response_App\n(Lambda-App/Backend/Lambda_Response_App.py)"]:::compute
        Requirements["Lambda Dependencies\n(requirements.txt)"]:::script
    end

    %% Database Layer
    subgraph "Vector Database on EC2"
        direction TB
        Postgres["PostgreSQL + PGVector"]:::database
    end

    %% External Services
    subgraph "External Services"
        direction TB
        LLM["OpenAI GPT-4 API"]:::externalService
    end

    %% Data Flow - Chat
    User --> UI
    UI --> APIGW
    APIGW -->|"Invoke"| Lambda
    Lambda -->|"Query"| Postgres
    Postgres --> Lambda
    Lambda -->|"Call"| LLM
    LLM --> Lambda
    Lambda -->|"Response"| APIGW
    APIGW --> UI
    UI --> User

    %% Data Flow - Ingestion
    IngestScript --> CSV
    IngestScript -->|"Writes Data"| Postgres
    ConnectScript -->|"Test Conn"| Postgres

    %% Click Events
    click UI "https://github.com/spidy20/aws-assistant-rag-chatbot/blob/master/app.py"
    click IngestScript "https://github.com/spidy20/aws-assistant-rag-chatbot/blob/master/DataIngestion.py"
    click ConnectScript "https://github.com/spidy20/aws-assistant-rag-chatbot/blob/master/connect.py"
    click CSV "https://github.com/spidy20/aws-assistant-rag-chatbot/blob/master/aws_sample_qa.csv"
    click SAM "https://github.com/spidy20/aws-assistant-rag-chatbot/blob/master/Lambda-App/template.yaml"
    click Lambda "https://github.com/spidy20/aws-assistant-rag-chatbot/blob/master/Lambda-App/Backend/Lambda_Response_App.py"
    click Requirements "https://github.com/spidy20/aws-assistant-rag-chatbot/blob/master/Lambda-App/Backend/requirements.txt"

    %% Styles
    classDef compute fill:#cce5ff,stroke:#333,stroke-width:1px
    classDef database fill:#d4edda,stroke:#333,stroke-width:1px
    classDef externalService fill:#ffebcc,stroke:#333,stroke-width:1px
    classDef script fill:#f5f5f5,stroke:#333,stroke-width:1px
    classDef client fill:#f0f0f0,stroke:#333,stroke-width:1px
    classDef frontend fill:#d9edf7,stroke:#333,stroke-width:1px
```
