# aws-samples/bedrock-serverless-workshop architecture

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

- Interactive diagram: https://gitdiagram.com/aws-samples/bedrock-serverless-workshop
- Repository: https://github.com/aws-samples/bedrock-serverless-workshop

## Overview

##### Project type and purpose
- This is a full-stack, serverless generative-AI chatbot application built as an AWS SAM (Serverless Application Model) solution.
- The frontend is a Vue.js/Amplify web UI; the backend is a set of AWS Lambda functions orchestrated via API Gateway, with authentication in Cognito, retrieval in Amazon Kendra, and text generation in Amazon Bedrock.

##### File structure
- Top-level:
- frontend/ – Vue.js + Amplify SPA
- lambdas/ – multiple Lambda handlers organized by function: bedrockFunc, llmFunctions, ragFunctions
- template.yaml – SAM template declaring AWS resources (API Gateway, Lambda, Cognito, etc.)
- prompt-engineering/ – prompt templates used by Lambdas
- Tools and scripts for account setup, deployment, and resizing are in tools/ and aws-creds.py.

##### README for additional insights
- The README confirms the use of RAG (Retrieval-Augmented Generation) with Amazon Kendra for indexing & retrieval, and Amazon Bedrock as the foundation-model API.
- Describes a Cognito user pool for auth, API Gateway endpoints for client-to-Lambda calls, and the use of SAM CLI to deploy.

a. Main components
- Client / Web UI (Vue.js + Amplify)
- AWS Cognito User Pool (authentication)
- Amazon API Gateway (REST endpoints)
- AWS Lambda functions (Auth, RAG, LLM, KB)
- Amazon Kendra (search & retrieve)
- Amazon Bedrock (foundation model inference)
- AWS SAM / CloudFormation (infrastructure as code)
b. Relationships & interactions
1. User opens UI → signs in via Amplify/Cognito
2. Authenticated requests → API Gateway endpoints
3. API Gateway routes to appropriate Lambda (e.g., /rag → ragfunction)
4. ragfunction calls Kendra to fetch context, then Bedrock to generate answer
5. LLM functions may call Bedrock directly; KB functions index or query Kendra
6. Lambda returns response → API Gateway → UI
c. Architectural patterns & principles
- Serverless microservices: each business function in its own Lambda
- Clear separation: UI vs. API vs. compute vs. external services
- Infrastructure as code via SAM for repeatable, versioned deployment
d. Key technologies & libraries
- Frontend: Vue, AWS Amplify, aws-exports.js, vue-router
- Backend: AWS Lambda (Python), boto3 (AWS SDK), prompt templates
- Services: AWS Cognito, API Gateway, Kendra, Bedrock, SAM

##### Essential details to capture
- Authentication handshake via Cognito
- API Gateway method endpoints (e.g., /rag, /llm, /kb)
- Individual Lambda “microservices” by folder grouping
- Interaction between RAG Lambda and Kendra + Bedrock
- Prompt-engineering folder as an internal library used by the Lambdas
- The SAM template as the single source of deployed resources

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    subgraph "Client Layer"
        UI["Web UI (Vue.js + Amplify)"]:::ui
        Cognito["Cognito User Pool"]:::aws
    end

    %% API Layer
    subgraph "API Layer"
        APIGW["API Gateway (REST)"]:::aws
    end

    %% Compute Layer
    subgraph "Compute Layer"
        subgraph "RAG Functions"
            Rag["RAG Lambda\n(ragfunction.py)"]:::lambda
            PromptHelper["Prompt Helper\n(promptfunction.py)"]:::lambda
        end
        subgraph "LLM Functions"
            LLM["LLM Lambda\n(llmfunction.py)"]:::lambda
            KB["KB Lambda\n(kbfunction.py)"]:::lambda
        end
        BedrockLambda["Bedrock Lambda\n(cognitouser.py)"]:::lambda
        PromptLib["Prompt-Engineering\n(template library)"]:::lib
    end

    %% External Services
    subgraph "AWS Services"
        Kendra["Amazon Kendra"]:::aws
        Bedrock["Amazon Bedrock"]:::aws
    end

    %% Infrastructure
    SAM["SAM Template\n(template.yaml)"]:::infra

    %% Flows
    UI -->|"SignIn via Amplify"| Cognito
    UI -->|"REST API Calls"| APIGW
    Cognito -->|JWT Token| APIGW

    APIGW -->|"/rag"| Rag
    APIGW -->|"/llm"| LLM
    APIGW -->|"/kb"| KB

    Rag -->|"boto3.search"| Kendra
    Kendra -->|"Context Data"| Rag
    Rag -->|"boto3.invokeBedrock"| Bedrock
    Bedrock -->|"Generated Text"| Rag
    Rag --> UI

    LLM -->|"boto3.invokeBedrock"| Bedrock
    Bedrock -->|"Response"| LLM
    LLM --> UI

    KB -->|"boto3.query"| Kendra
    Kendra -->|"Results"| KB
    KB --> UI

    Rag --> PromptHelper
    LLM --> PromptLib
    KB --> PromptLib

    %% Infra linkage
    SAM --- APIGW
    SAM --- Cognito
    SAM --- Rag
    SAM --- LLM
    SAM --- KB
    SAM --- BedrockLambda

    %% Click Events
    click UI "https://github.com/aws-samples/bedrock-serverless-workshop/tree/main/frontend/"
    click Cognito "https://github.com/aws-samples/bedrock-serverless-workshop/blob/main/frontend/src/utils/auth.js"
    click APIGW "https://github.com/aws-samples/bedrock-serverless-workshop/blob/main/template.yaml"
    click Rag "https://github.com/aws-samples/bedrock-serverless-workshop/blob/main/lambdas/ragFunctions/ragfunction.py"
    click PromptHelper "https://github.com/aws-samples/bedrock-serverless-workshop/blob/main/lambdas/ragFunctions/promptfunction.py"
    click LLM "https://github.com/aws-samples/bedrock-serverless-workshop/blob/main/lambdas/llmFunctions/llmfunction.py"
    click KB "https://github.com/aws-samples/bedrock-serverless-workshop/blob/main/lambdas/llmFunctions/kbfunction.py"
    click BedrockLambda "https://github.com/aws-samples/bedrock-serverless-workshop/blob/main/lambdas/bedrockFunc/cognitouser.py"
    click PromptLib "https://github.com/aws-samples/bedrock-serverless-workshop/tree/main/prompt-engineering/"
    click SAM "https://github.com/aws-samples/bedrock-serverless-workshop/blob/main/template.yaml"
    click tools "https://github.com/aws-samples/bedrock-serverless-workshop/tree/main/tools/"

    %% Styles
    classDef ui fill:#ADD8E6,stroke:#000,stroke-width:1px
    classDef aws fill:#FFA500,stroke:#000,stroke-width:1px
    classDef lambda fill:#9370DB,stroke:#000,stroke-width:1px
    classDef infra fill:#D3D3D3,stroke:#000,stroke-width:1px
    classDef lib fill:#90EE90,stroke:#000,stroke-width:1px
```
