# aws-samples/aws-genai-conversational-rag-reference architecture

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

- Interactive diagram: https://gitdiagram.com/aws-samples/aws-genai-conversational-rag-reference
- Repository: https://github.com/aws-samples/aws-genai-conversational-rag-reference

## Overview

##### Project type and purpose
- This is a monorepo for “Galileo,” an end-to-end reference implementation of a conversational RAG (Retrieval-Augmented Generation) application.
- It provides a full-stack solution: AWS CDK infrastructure, serverless back-end (REST & WebSocket APIs, corpus ingestion pipeline, inference engine Lambdas), a React-based front-end, plus a CLI and SDK for programmatic access.

##### File structure
- Top level:
- packages/ – reusable libraries:
– galileo-cdk (IaC constructs)
– galileo-sdk (TypeScript/JS SDK)
– galileo-cli (CLI tool)
- demo/ – self-contained reference deployment:
– infra/ (CDK entrypoint, stacks for presentation, AI, corpus, networking, identity, CICD)
– api/ (Smithy-generated REST API client & infra)
– ws-api/ (Smithy-generated WebSocket API client & infra)
– corpus/ (document ingestion, embedding, vector-store indexer Lambdas)
– website/ (React SPA)
– sample-dataset/
– overrides/
- Infrastructure code uses AWS CDK in TypeScript, with logical layers: application, networking, identity, data, monitoring, tooling, CICD.
- Corpus pipeline: event-driven Lambdas (inventory, task, vectorstore worker).
- Inference engine: REST and WS Lambdas orchestrating calls to LLMs (Bedrock, SageMaker, HuggingFace).
- Presentation: API Gateway (REST & WS) fronting Lambda handlers; React front-end calling these endpoints.
- Generated code: Smithy models → clients/infrastructure/stacks for both REST & WS APIs.

##### Core README insights
- Three-tier reference application: ingestion pipeline, vector store, inference engine + aligned LLM, UI with session persistence and auth.
- Use case: virtual legal research assistant.

##### Main components & their interactions (to be
a. Clients:
– Browser (React SPA)
– CLI tool
– SDK library
b. API Layer:
– REST API Gateway → Lambda handlers (chat management, LLM inventory)
– WebSocket API Gateway → Lambda handlers for streaming LLM responses
c. Business Logic:
– Corpus ingestion pipeline (inventory, embedding, indexing Lambdas)
– Inference engine Lambdas (wrapper around LLM calls & result formatting)
d. Data Layer:
– Vector store (e.g. PGVector on RDS)
– Document store (S3 or similar)
– Metadata DB (e.g. DynamoDB or RDS)
e. External Services:
– AWS Cognito (authN)
– AWS S3, RDS, DynamoDB (for data storage)
– AWS Bedrock / SageMaker / HuggingFace (LLM endpoints)
– CloudWatch (logging, tracing, metrics)
– CI/CD Pipeline (CodePipeline/CodeBuild)

##### Architectural patterns & principles
- Serverless microservices (Lambda + API Gateway)
- Event-driven ingestion pipeline
- Infrastructure as code (CDK constructs packaged in galileo-cdk)
- Client-library separation (SDK abstracts API + WS)
- Three-tier separation: Presentation → Logic → Data

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Clients Layer
    subgraph "Clients" 
        direction TB
        Browser["React SPA"]:::compute
        CLI["CLI Tool"]:::compute
        SDK["SDK Library"]:::compute
    end

    %% API Layer
    subgraph "API Layer" 
        direction TB
        RESTGW["API Gateway (REST)"]:::compute
        WS_GW["API Gateway (WebSocket)"]:::compute
        subgraph "Clients Codegen"
            direction TB
            REST_Client["Smithy REST Client"]:::compute
            WS_Client["Smithy WS Client"]:::compute
        end
    end

    %% Business Logic
    subgraph "Business Logic"
        direction TB
        subgraph "Corpus Ingestion Pipeline"
            direction TB
            Inventory["Lambda: inventory"]:::compute
            TaskWorker["Lambda: task"]:::compute
            VectorWorker["Lambda: vectorstore worker"]:::compute
        end
        subgraph "Inference Engine"
            direction TB
            InferenceRest["Lambda: rest-handler"]:::compute
            InferenceWS["Lambda: ws-handler"]:::compute
        end
    end

    %% Data Layer
    subgraph "Data Layer"
        direction TB
        VectorStore["Vector Store (PGVector on RDS)"]:::storage
        DocumentStore["Document Store (S3)"]:::storage
        MetadataDB["Metadata DB"]:::storage
    end

    %% External Services
    subgraph "External Services"
        direction TB
        Cognito["AWS Cognito"]:::external
        Bedrock["LLM Endpoints\n(Bedrock/SageMaker/HuggingFace)"]:::external
        CloudWatch["CloudWatch"]:::external
        CICD["CI/CD Pipeline"]:::external
    end

    %% CDK Stacks Boundary
    subgraph "CDK Infrastructure Stacks" 
        direction TB
        Networking["Networking Stack"]:::infra
        Identity["Identity Stack"]:::infra
        DataInfra["Data Layer Infra"]:::infra
        AI_Models["Foundation Models Stack"]:::infra
        InferenceStack["Inference Engine Stack"]:::infra
        CorpusPipelineStack["Corpus Pipeline Stack"]:::infra
        CICDStack["CICD Pipeline Stack"]:::infra
    end

    %% Connections - Clients to API
    Browser -->|calls REST| RESTGW
    Browser -->|opens WS| WS_GW
    CLI -->|calls REST| RESTGW
    CLI -->|opens WS| WS_GW
    SDK -->|uses REST| REST_Client
    SDK -->|uses WS| WS_Client

    %% API Clients mapping
    REST_Client --> RESTGW
    WS_Client --> WS_GW

    %% API to Lambdas
    RESTGW -->|"chat & inventory"| ChatHandler
    RESTGW -->|"inventory"| LLMInventory
    WS_GW -->|"stream"| WS_Handler
    WS_GW -->|"auth"| WS_Authorizer

    %% Lambdas mapping nodes
    ChatHandler["Lambda: chat handlers"]:::compute
    LLMInventory["Lambda: llm inventory"]:::compute
    WS_Handler["Lambda: ws-handler"]:::compute
    WS_Authorizer["Lambda: authorizer"]:::compute

    %% API Lambdas to Business Logic
    ChatHandler --> InferenceRest
    LLMInventory --> InferenceRest
    WS_Handler --> InferenceWS

    %% Corpus Pipeline event flow
    Inventory --> TaskWorker
    TaskWorker --> VectorWorker
    VectorWorker --> VectorStore

    %% Inference flows to LLMs
    InferenceRest --> Bedrock
    InferenceWS --> Bedrock

    %% Business Logic to Data Layer
    InferenceRest --> VectorStore
    InferenceRest --> MetadataDB

    %% Data Layer to External Infra
    DocumentStore --> S3Service
    VectorStore --> RDSService
    MetadataDB --> DynamoService

    %% External Services usage
    RESTGW --> CloudWatch
    WS_GW --> CloudWatch
    Inventory --> CloudWatch
    InferenceRest --> CloudWatch

    %% CDK stacks orchestrations
    Networking --> RESTGW
    Networking --> WS_GW
    Identity --> Cognito
    DataInfra --> VectorStore
    DataInfra --> DocumentStore
    DataInfra --> MetadataDB
    AI_Models --> Bedrock
    InferenceStack --> InferenceRest
    InferenceStack --> InferenceWS
    CorpusPipelineStack --> Inventory
    CorpusPipelineStack --> TaskWorker
    CorpusPipelineStack --> VectorWorker
    CICDStack --> CICD

    %% External resource placeholders
    S3Service["AWS S3"]:::external
    RDSService["AWS RDS"]:::external
    DynamoService["AWS DynamoDB"]:::external

    %% Click Events
    click Browser "https://github.com/aws-samples/aws-genai-conversational-rag-reference/tree/mainline/demo/website"
    click CLI "https://github.com/aws-samples/aws-genai-conversational-rag-reference/tree/mainline/packages/galileo-cli"
    click SDK "https://github.com/aws-samples/aws-genai-conversational-rag-reference/tree/mainline/packages/galileo-sdk"
    click REST_Client "https://github.com/aws-samples/aws-genai-conversational-rag-reference/tree/mainline/demo/api/generated"
    click WS_Client "https://github.com/aws-samples/aws-genai-conversational-rag-reference/tree/mainline/demo/ws-api/generated"
    click ChatHandler "https://github.com/aws-samples/aws-genai-conversational-rag-reference/tree/mainline/demo/infra/src/application/presentation/lambdas/chat"
    click LLMInventory "https://github.com/aws-samples/aws-genai-conversational-rag-reference/blob/mainline/demo/infra/src/application/presentation/lambdas/llm/inventory.ts"
    click WS_Handler "https://github.com/aws-samples/aws-genai-conversational-rag-reference/tree/mainline/demo/infra/src/application/presentation/lambdas/websocket"
    click WS_Authorizer "https://github.com/aws-samples/aws-genai-conversational-rag-reference/blob/mainline/demo/infra/src/application/presentation/lambdas/websocket/authorizer.ts"
    click InferenceRest "https://github.com/aws-samples/aws-genai-conversational-rag-reference/blob/mainline/demo/infra/src/application/ai/inference-engine/engine/handler/rest-handler/index.ts"
    click InferenceWS "https://github.com/aws-samples/aws-genai-conversational-rag-reference/blob/mainline/demo/infra/src/application/ai/inference-engine/engine/handler/ws-handler/index.ts"
    click InferenceStack "https://github.com/aws-samples/aws-genai-conversational-rag-reference/blob/mainline/demo/infra/src/application/ai/inference-engine/stack.ts"
    click Inventory "https://github.com/aws-samples/aws-genai-conversational-rag-reference/tree/mainline/demo/corpus/logic/src"
    click TaskWorker "https://github.com/aws-samples/aws-genai-conversational-rag-reference/tree/mainline/demo/corpus/logic/src"
    click VectorWorker "https://github.com/aws-samples/aws-genai-conversational-rag-reference/tree/mainline/demo/corpus/logic/src"
    click CorpusPipelineStack "https://github.com/aws-samples/aws-genai-conversational-rag-reference/tree/mainline/demo/infra/src/application/corpus/pipeline/handlers"
    click VectorStore "https://github.com/aws-samples/aws-genai-conversational-rag-reference/blob/mainline/packages/galileo-cdk/src/data/corpus/vectorstore/rds.ts"
    click DataInfra "https://github.com/aws-samples/aws-genai-conversational-rag-reference/blob/mainline/demo/infra/src/application/data/app-data-layer.ts"
    click DocumentStore "https://github.com/aws-samples/aws-genai-conversational-rag-reference/tree/mainline/packages/galileo-cdk/src/common/resources/secure-bucket"
    click MetadataDB "https://github.com/aws-samples/aws-genai-conversational-rag-reference/blob/mainline/demo/infra/src/application/data/index.ts"
    click Networking "https://github.com/aws-samples/aws-genai-conversational-rag-reference/blob/mainline/demo/infra/src/application/networking/stack.ts"
    click Identity "https://github.com/aws-samples/aws-genai-conversational-rag-reference/blob/mainline/demo/infra/src/application/identity/index.ts"
    click CICDStack "https://github.com/aws-samples/aws-genai-conversational-rag-reference/blob/mainline/demo/infra/src/cicd/pipeline-stack.ts"
    click AI_Models "https://github.com/aws-samples/aws-genai-conversational-rag-reference/blob/mainline/demo/infra/src/application/ai/foundation-models/stack.ts"

    %% Styles
    classDef compute fill:#D0E6FF,stroke:#003366,color:#003366
    classDef storage fill:#DFFFE0,stroke:#006600,color:#006600
    classDef external fill:#FFE6A0,stroke:#CC6600,color:#CC6600
    classDef infra fill:#F0F0F0,stroke:#999999,color:#333333,stroke-dasharray: 4 2
    class Browser,CLI,SDK,RESTGW,WS_GW,ChatHandler,LLMInventory,WS_Handler,WS_Authorizer,InferenceRest,InferenceWS,Inventory,TaskWorker,VectorWorker compute
    class VectorStore,DocumentStore,MetadataDB storage
    class Cognito,Bedrock,CloudWatch,S3Service,RDSService,DynamoService,CICD external
    class Networking,Identity,DataInfra,AI_Models,InferenceStack,CorpusPipelineStack,CICDStack infra
```
