# uniabhi/pdf-chat-with-bedrock architecture

> Architecture diagram of the GitHub repository uniabhi/pdf-chat-with-bedrock, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-09). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/uniabhi/pdf-chat-with-bedrock
- Repository: https://github.com/uniabhi/pdf-chat-with-bedrock

## Overview

##### Project Type & Purpose
- The project is a full-stack application with two distinct components: the Admin Application and the User Application.
- It aims to allow administrators to upload and process PDF documents (transforming them into vector embeddings) and enable end users to query these documents conversationally.
- Key external dependencies include Amazon Bedrock (for LLM inferencing and embeddings), AWS S3 (for storing FAISS vector indices), LangChain (for RAG orchestration), and FAISS for efficient semantic search.

##### Main Components
- Admin Application:
- Containerized as specified by its Dockerfile.
- Responsible for PDF upload, text chunking, generating vector embeddings using the Amazon Titan Embedding Model, and storing indices (in FAISS format) to Amazon S3.
- User Application:
- Also containerized.
- Downloads vector indices from S3, converts user queries to vectors (again using the Titan Embedding Model), performs similarity search to retrieve relevant document chunks, and uses an LLM (Meta LLama 3 [8B]) for generating responses.
- Interfaces with the user via a Streamlit-based front-end.
- External Systems & Services:
- Amazon Bedrock for both embeddings-generation tasks and LLM inference.
- AWS S3 for storing and retrieving the FAISS indices.
- Infrastructure services like IAM for secured AWS access.
- Docker containers representing deployment units for both apps.

- For the Admin Application:
- For the User Application:
- “User Query Input (via Streamlit UI)” → “Query Embedding Generation via Titan Embedding Model” → “Retrieve FAISS Indices from S3” → “Similarity Search to Fetch Relevant Chunks” → “Provide Context and Call LLama 3 (8B)” → “Generate & Return Response”.
- Both applications will have secure API or environment variable-based access to AWS (with the recommendation to switch to IAM roles for production).

##### Architectural Patterns & Design Principles
- Follow a microservices or modular approach by clearly separating responsibilities between the Admin and User applications.
- Containerization (using Docker) to encapsulate and deploy these services independently.
- Decoupling between document processing and query processing; they interact mainly via the shared persistence layer (S3).

##### Technology and Framework Integration
- Labels for key technologies: Amazon Bedrock, FAISS, LangChain, Streamlit, Docker, and AWS S3.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Admin Application Subgraph
    subgraph "Admin Application (Port 8083)"
        A0["Admin Container"]:::admin
        A1["PDF Input (Admin UI)"]:::admin
        A2["PDF Chunking"]:::admin
        A3["Embedding Generation (Titan)"]:::admin
        A4["S3 Upload (FAISS Index)"]:::admin
        A0 --> A1
        A1 --> A2
        A2 --> A3
        A3 --> A4
        %% Additional Admin components for click events
        A5["Dockerfile"]:::admin
        A6["Main App"]:::admin
        A0 -.-> A5
        A0 -.-> A6
    end

    %% User Application Subgraph
    subgraph "User Application (Port 8084)"
        U0["User Container"]:::user
        U1["User Query (Streamlit UI)"]:::user
        U2["Query Embedding (Titan)"]:::user
        U3["S3 Download (FAISS Indices)"]:::user
        U4["Similarity Search"]:::user
        U5["LLM Inference (Meta LLama 3 [8B])"]:::user
        U6["Response Generation"]:::user
        U0 --> U1
        U1 --> U2
        U2 --> U3
        U3 --> U4
        U4 --> U5
        U5 --> U6
        %% Additional User components for click events
        U7["Dockerfile"]:::user
        U8["Main App"]:::user
        U0 -.-> U7
        U0 -.-> U8
    end

    %% External Systems
    E1["Amazon Bedrock"]:::external
    E2["AWS S3"]:::external
    E3["LangChain"]:::orchestration

    %% Connections between Admin and External
    A3 -->|"embedding_generation"| E1
    A4 -->|"upload_index"| E2

    %% Connections between External and User
    U2 -->|"embedding_generation"| E1
    U5 -->|"LLM_inference"| E1
    E2 -->|"download_index"| U3
    U4 -->|"orchestration"| E3
    E3 -->|"context_enrichment"| U5

    %% Click Events for Admin Components
    click A0 "https://github.com/uniabhi/pdf-chat-with-bedrock/tree/main/Admin/"
    click A5 "https://github.com/uniabhi/pdf-chat-with-bedrock/tree/main/Admin/Dockerfile"
    click A6 "https://github.com/uniabhi/pdf-chat-with-bedrock/blob/main/Admin/admin.py"

    %% Click Events for User Components
    click U0 "https://github.com/uniabhi/pdf-chat-with-bedrock/tree/main/User/"
    click U7 "https://github.com/uniabhi/pdf-chat-with-bedrock/tree/main/User/Dockerfile"
    click U8 "https://github.com/uniabhi/pdf-chat-with-bedrock/blob/main/User/app.py"

    %% Styles
    classDef admin fill:#f4cccc,stroke:#aa0000,stroke-width:2px;
    classDef user fill:#c9daf8,stroke:#0b5394,stroke-width:2px;
    classDef external fill:#d9ead3,stroke:#38761d,stroke-width:2px,stroke-dasharray: 5 5;
    classDef orchestration fill:#fff2cc,stroke:#bf9000,stroke-width:2px;
    
    %% Legend (as annotation)
    subgraph "Legend"
        L1["Rectangle = Application Component"]
        L2["Cloud/Cylinder = External Service"]
        L3["Dashed Arrow = Auxiliary/Orchestration Flow"]
    end
    L1 --- L2
    L2 --- L3
    style Legend fill:#eeeeee,stroke:#333,stroke-dasharray: 3 3
```
