# aws-samples/aws-genai-llm-chatbot architecture

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

- Interactive diagram: https://gitdiagram.com/aws-samples/aws-genai-llm-chatbot
- Repository: https://github.com/aws-samples/aws-genai-llm-chatbot

## Overview

Based on our analysis of the file tree and the README, this project is a full-scale AWS cloud solution that implements a GenAI Chatbot with retrieval augmented generation (RAG) capabilities. It uses AWS CDK to provision and manage infrastructure, integrates with multiple LLM providers (including Amazon Bedrock, Amazon SageMaker, third-party APIs), and includes both a robust backend API (with REST and GraphQL endpoints) and a modern React-based frontend. The overall solution is clearly segmented into infrastructure (CDK), backend logic (multiple Lambda functions and API routing), and a user interface.

##### Main Components
- AWS Infrastructure & Deployment Layer:
- AWS CDK constructs (referenced in files such as “cdk.json”, “lib/aws-genai-llm-chatbot-stack.ts”).
- Deployment configurations (CI/CD workflows under .github/workflows and CLI tools in the “cli” directory).
- Backend API & Business Logic:
- Chatbot API implemented under “lib/chatbot-api” with multiple Lambda functions handling different routes (applications, sessions, health checks, role management, etc.). Include the API handler, routes, resolvers, and integrations (GraphQL and REST endpoints).
- Model Interfaces and Language Model Adapters layered in “lib/model-interfaces” (with separate adapters for Amazon Bedrock, SageMaker, etc.).
- RAG Engines modules (found in “lib/rag-engines”) that support different retrieval engines (Aurora-PGVector, Kendra, OpenSearch, etc.) with functions to create workspaces and workflows.
- Authentication & Security:
- Authentication logic in “lib/authentication” including Lambda functions for updating OIDC secrets, user pool client management, etc.
- Access control tests, configurations, and supporting integration tests.
- Frontend/User Interface:
- A React application (located in “lib/user-interface/react-app”) that serves as the chatbot’s public interface. It handles pages (chat, admin, RAG-related screens) and integrates with backend API clients (API client modules in “lib/user-interface/react-app/src/common/api-client”).
- Shared and Utility Layers:
- Shared libraries, common types, utility functions and python SDK layers (under “lib/shared”), which encapsulate cross-cutting concerns such as file handling, zip bundling, and integration routines.
- Testing and Integration:
- End-to-end tests, integration tests, and various snapshot tests provided under “integtests” and “tests” directories.

##### Relationships and Interactions
- Directional data flows from the Frontend (React App) to the API Gateway (or directly to Lambda functions via the “chatbot-api”) to process user requests.
- How the API layer invokes various backend Lambda functions that interact with AWS services (e.g., DynamoDB tables, S3 buckets, API Gateway for GraphQL endpoints) and external AI/LLM providers.
- Interactions between the business logic and the RAG engine modules – highlighting how data import functions, workspace management, and search/retrieval workflows are triggered.
- CDK infrastructure layer that provisions these services (including Lambda functions, API endpoints, and IAM policies).

##### Architectural Patterns and Design Principles
- Modular and layered architecture – separate components for infrastructure management (CDK), API handling (chatbot-api), shuttling between user interface and backend services, and adapter patterns for interfacing with different LLM providers.
- Clear separation of concerns: UI components are isolated from backend logic, while backend components are segregated into authentication, message processing, and RAG engine integrations.
- Use of serverless components (Lambda functions) and microservice-like patterns for scalability and maintainability.
- Emphasis on multi-modal support as hinted by integration with both text and image/video models (Amazon Nova models support).

##### Relevant Technologies, Frameworks, and Libraries
- AWS CDK (for deployment and infrastructure provisioning).
- AWS Lambda, API Gateway, DynamoDB, S3, and other managed AWS services.
- React (frontend, via Vite configuration, TypeScript and modern web development practices).
- GraphQL (schema located under “lib/chatbot-api/schema”) and RESTful API patterns.
- LangChain-style integrations in “lib/model-interfaces/langchain” for language model interactions.
- Various adapter implementations for different LLM providers (Amazon Bedrock, SageMaker, etc.).

- High-level: Show frontend → API layer → backend services → AWS managed services and external LLM providers.
- Drill-down: For the backend, show separate flows for handling chatbot messaging, RAG processing, authentication flows, and model interfacing.
- Significant components discussed in the file structure (like “lib/chatbot-api”, “lib/model-interfaces”, “lib/rag-engines”, “lib/user-interface”) are represented.
- Optionally, include key deployment paths and CI/CD pipelines (referenced in .github/workflows) to capture the operational aspect.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        UI["React Chatbot UI"]:::frontend
    end

    %% API Layer
    subgraph "API Layer"
        API["Chatbot API (REST & GraphQL)"]:::api
    end

    %% Backend Services
    subgraph "Backend Services"
        LB["Lambda Functions"]:::backend
        MI["Model Interfaces & LLM Adapters"]:::backend
        RE["RAG Engines"]:::backend
        AU["Authentication"]:::backend
        SHARED["Shared & Utility Functions"]:::shared
    end

    %% Infrastructure & Deployment
    subgraph "Infrastructure & Deployment"
        INFRA["AWS CDK Constructs"]:::infra
        CI["CI/CD Workflows"]:::infra
        CLI["CLI Tools"]:::infra
    end

    %% Testing & Integration
    subgraph "Testing & Integration"
        TEST["E2E & Integration Tests"]:::testing
    end

    %% Data Flows
    UI -->|"API_requests"| API
    API -->|"invoke"| LB
    LB -->|"calls"| MI
    LB -->|"triggers"| RE
    LB -->|"validates"| AU
    LB -->|"utilizes"| SHARED

    %% Infrastructure provisioning relationships
    INFRA -->|"provisions"| API
    INFRA -->|"provisions"| LB
    INFRA -->|"provisions"| AU
    INFRA -->|"provisions"| MI
    INFRA -->|"provisions"| RE
    INFRA --- CI
    INFRA --- CLI

    %% Testing relationships
    TEST -->|"tests_UI"| UI
    TEST -->|"tests_API"| API
    TEST -->|"tests_Backend"| LB
    TEST -->|"tests_Auth"| AU

    %% Click Events
    click UI "https://github.com/aws-samples/aws-genai-llm-chatbot/tree/main/lib/user-interface/react-app"
    click API "https://github.com/aws-samples/aws-genai-llm-chatbot/tree/main/lib/chatbot-api"
    click LB "https://github.com/aws-samples/aws-genai-llm-chatbot/tree/main/lib/chatbot-api/functions/api-handler"
    click MI "https://github.com/aws-samples/aws-genai-llm-chatbot/tree/main/lib/model-interfaces"
    click RE "https://github.com/aws-samples/aws-genai-llm-chatbot/tree/main/lib/rag-engines"
    click AU "https://github.com/aws-samples/aws-genai-llm-chatbot/tree/main/lib/authentication"
    click SHARED "https://github.com/aws-samples/aws-genai-llm-chatbot/tree/main/lib/shared"
    click INFRA "https://github.com/aws-samples/aws-genai-llm-chatbot/blob/main/lib/aws-genai-llm-chatbot-stack.ts"
    click CI "https://github.com/aws-samples/aws-genai-llm-chatbot/tree/main/.github/workflows"
    click CLI "https://github.com/aws-samples/aws-genai-llm-chatbot/tree/main/cli"
    click TEST "https://github.com/aws-samples/aws-genai-llm-chatbot/tree/main/integtests"

    %% Styles
    classDef frontend fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef api fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef backend fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef infra fill:#FFB6C1,stroke:#000,stroke-width:2px;
    classDef shared fill:#D3D3D3,stroke:#000,stroke-width:2px;
    classDef testing fill:#FFA07A,stroke:#000,stroke-width:2px;
```
