# pixegami/deploy-rag-to-aws architecture

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

- Interactive diagram: https://gitdiagram.com/pixegami/deploy-rag-to-aws
- Repository: https://github.com/pixegami/deploy-rag-to-aws

## Overview

##### Main Components
- Application Container (Dockerized): Based on the “image/” directory, this component is responsible for:
- Ingesting PDF documents (populate_database.py in image/).
- Processing queries: There are two main modes – interactive (using FastAPI via app_api_handler.py) and batch/worker mode (via app_work_handler.py).
- Executing RAG logic: The “rag_app” subdirectory includes modules for obtaining a Chroma database instance (get_chroma_db.py), for fetching an embedding function (get_embedding_function.py), and for querying the RAG system (query_rag.py).
- Query model orchestration: query_model.py likely ties together the query handling and retrieval workflow.
- Data Sources: Inside “image/src/data/source/” you have source PDFs (e.g., galaxy-design-client-guide.pdf). These are used to build the vector DB.
- External AWS Services:
- AWS Bedrock for LLM and embedding functionalities.
- DynamoDB for data storage (as indicated by environment variables and the mention of TABLE_NAME).
- Infrastructure Provisioning (rag-cdk-infra): AWS CDK scripts in this directory deploy the AWS resources that the application interacts with.

##### Relationships and Interactions
- User Interaction & Query Lifecycle:
- When a user sends a query, it is received via a FastAPI endpoint (app_api_handler.py) or executed via the work handler in Docker.
- The query passes to the query model logic (inside rag_app) where the system retrieves relevant content from the vector store (likely managed via Chroma and DynamoDB) and interacts with AWS Bedrock (or similar LLM service) to generate a response.
- Data Ingestion:
- A dedicated pipeline (populate_database.py) reads PDF files from the source directory, processes them, and populates the vector database.
- Deployment & Infrastructure:

##### Architectural Patterns/Design Principles
- Modular Design: The separation between data ingestion, query-processing, and API-handling is clear.
- Containerization: The application is containerized through Docker, ensuring portability across local and cloud environments.
- Infrastructure as Code: Use of AWS CDK indicates that provisioning is automated and version-controlled.
- Separation of Concerns: The clear split between application logic (in the “image/” directory) and deployment/infrastructure (in “rag-cdk-infra”) reinforces best practices.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client
    Client["Client/User"]:::client

    %% Containerized Application
    subgraph "Containerized Application (Docker)"
        AppContainer["Application Container (Dockerized)"]:::docker
        DockerFile["Docker Build File"]:::docker
        Ingestion["Data Ingestion Pipeline (populate_database.py)"]:::ingestion
        subgraph "Processing Components"
            API["Interactive API Handler (FastAPI) [app_api_handler.py]"]:::api
            Worker["Batch/Worker Query Handler [app_work_handler.py]"]:::api
            QueryModel["Query Model Orchestration [query_model.py]"]:::processor
            subgraph "RAG Logic Modules"
                Chroma["Chroma DB (get_chroma_db.py)"]:::processor
                Embed["Embedding Function (get_embedding_function.py)"]:::processor
                RAGQuery["RAG Query (query_rag.py)"]:::processor
            end
        end
    end

    %% Data Sources & Vector DB
    DataSources["Data Sources (PDF Documents)"]:::datasource
    VectorDB["Vector Database (Chroma)"]:::datasource

    %% AWS Cloud Services
    subgraph "AWS Cloud Services"
        AWSBedrock["AWS Bedrock (LLM)"]:::aws
        DynamoDB["DynamoDB"]:::aws
    end

    %% Infrastructure Provisioning
    Infra["Infrastructure Provisioning (AWS CDK)"]:::infra

    %% Connections
    Client -->|"query_request"| API
    API -->|"process_query"| QueryModel
    Worker -->|"process_batch_query"| QueryModel
    QueryModel -->|"retrieve_context"| VectorDB
    QueryModel -->|"invoke_LLM"| AWSBedrock
    DataSources -->|"provide_PDF"| Ingestion
    Ingestion -->|"populate_DB"| VectorDB
    AppContainer -->|"build_context"| DockerFile
    Infra -->|"deploy_resources"| AWSBedrock
    Infra -->|"deploy_resources"| DynamoDB

    %% Click Events
    click AppContainer "https://github.com/pixegami/deploy-rag-to-aws/tree/main/image/"
    click DockerFile "https://github.com/pixegami/deploy-rag-to-aws/tree/main/image/Dockerfile"
    click Ingestion "https://github.com/pixegami/deploy-rag-to-aws/blob/main/image/populate_database.py"
    click API "https://github.com/pixegami/deploy-rag-to-aws/blob/main/image/src/app_api_handler.py"
    click Worker "https://github.com/pixegami/deploy-rag-to-aws/blob/main/image/src/app_work_handler.py"
    click QueryModel "https://github.com/pixegami/deploy-rag-to-aws/blob/main/image/src/query_model.py"
    click Chroma "https://github.com/pixegami/deploy-rag-to-aws/blob/main/image/src/rag_app/get_chroma_db.py"
    click Embed "https://github.com/pixegami/deploy-rag-to-aws/blob/main/image/src/rag_app/get_embedding_function.py"
    click RAGQuery "https://github.com/pixegami/deploy-rag-to-aws/blob/main/image/src/rag_app/query_rag.py"
    click DataSources "https://github.com/pixegami/deploy-rag-to-aws/blob/main/image/src/data/source/galaxy-design-client-guide.pdf"
    click Infra "https://github.com/pixegami/deploy-rag-to-aws/blob/main/rag-cdk-infra/lib/rag-cdk-infra-stack.ts"

    %% Styles
    classDef client fill:#E8DAEF,stroke:#8E44AD,stroke-width:2px;
    classDef docker fill:#D1E8FF,stroke:#1F618D,stroke-width:2px;
    classDef ingestion fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef api fill:#82E0AA,stroke:#1E8449,stroke-width:2px;
    classDef processor fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef datasource fill:#D6EAF8,stroke:#2874A6,stroke-width:2px;
    classDef aws fill:#FADBD8,stroke:#C0392B,stroke-width:2px;
    classDef infra fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
```
