# aws-samples/bedrock-claude-chat architecture

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

- Interactive diagram: https://gitdiagram.com/aws-samples/bedrock-claude-chat
- Repository: https://github.com/aws-samples/bedrock-claude-chat

## Overview

##### Main Components

a. Client Layer:
- React Frontend Application (CloudFront + S3)
- Web Application Firewall (WAF)
- Authentication Layer (Cognito)

b. API Layer:
- API Gateway
- WebSocket API for real-time communication
- Lambda Functions with Web Adapter

c. Core Services:
- Amazon Bedrock (Claude Models)
- Bedrock Knowledge Bases
- OpenSearch Serverless
- DynamoDB for conversation storage

d. Processing Pipeline:
- EventBridge Pipes
- Step Functions for knowledge embedding
- Lambda Functions for various processors

##### User Flow
- User → CloudFront → React App → API Gateway → Lambda → Bedrock
- Authentication flow through Cognito
- WebSocket connections for real-time chat

##### Data Flow
- Knowledge Base ingestion pipeline
- Document processing and embedding flow
- Conversation storage and retrieval

##### Administrative Flow
- Analytics and monitoring pathways
- User management flows

##### Frontend Zone
- React application components
- i18n support
- UI components structure

##### Backend Zone
- FastAPI implementation
- Repository pattern
- Business logic layer

##### Infrastructure Zone
- AWS service configurations
- Security groups and IAM roles
- Network layout

##### Deployment Flow

CI/CD pipeline:
- GitHub Actions workflows
- CDK deployment process
- Infrastructure as Code components

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Client
        CF[CloudFront]
        WAF[WAF]
        REACT["React Frontend"]:::frontend
        COGN[Cognito]:::auth
    end

    subgraph APILayer
        APIG["API Gateway"]:::api
        WSG["WebSocket Gateway"]:::api
        LAMBDA_API["API Lambda"]:::lambda
        LAMBDA_WS["WebSocket Lambda"]:::lambda
    end

    subgraph CoreServices
        BEDROCK["Amazon Bedrock"]:::aws
        KB["Knowledge Bases"]:::aws
        OS["OpenSearch"]:::storage
        DYNAMO["DynamoDB"]:::storage
    end

    subgraph ProcessingPipeline
        EB["EventBridge Pipes"]:::processing
        SF["Step Functions"]:::processing
        LAMBDA_PROC["Processing Lambda"]:::lambda
    end

    %% Connections
    CF --> WAF
    WAF --> REACT
    REACT --> COGN
    COGN --> APIG
    COGN --> WSG

    APIG --> LAMBDA_API
    WSG --> LAMBDA_WS
    
    LAMBDA_API --> BEDROCK
    LAMBDA_API --> OS
    LAMBDA_API --> DYNAMO
    
    LAMBDA_WS --> BEDROCK
    LAMBDA_WS --> OS
    LAMBDA_WS --> DYNAMO
    
    KB --> EB
    EB --> SF
    SF --> LAMBDA_PROC
    LAMBDA_PROC --> OS

    %% Styles
    classDef aws fill:#1E88E5,color:white
    classDef frontend fill:#4CAF50,color:white
    classDef api fill:#FF9800,color:white
    classDef auth fill:#E91E63,color:white
    classDef lambda fill:#9C27B0,color:white
    classDef storage fill:#795548,color:white
    classDef processing fill:#FFC107,color:black

    %% Click Events
    click REACT "https://github.com/aws-samples/bedrock-claude-chat/tree/v2/frontend/src"
    click COGN "https://github.com/aws-samples/bedrock-claude-chat/tree/v2/backend/auth"
    click APIG "https://github.com/aws-samples/bedrock-claude-chat/tree/v2/backend/app/routes"
    click WSG "https://github.com/aws-samples/bedrock-claude-chat/blob/v2/backend/app/websocket.py"
    click LAMBDA_API "https://github.com/aws-samples/bedrock-claude-chat/blob/v2/cdk/lib/constructs/api.ts"
    click LAMBDA_WS "https://github.com/aws-samples/bedrock-claude-chat/blob/v2/cdk/lib/constructs/websocket.ts"
    click BEDROCK "https://github.com/aws-samples/bedrock-claude-chat/blob/v2/backend/app/bedrock.py"
    click KB "https://github.com/aws-samples/bedrock-claude-chat/blob/v2/cdk/lib/utils/bedrock-knowledge-base-args.ts"
    click OS "https://github.com/aws-samples/bedrock-claude-chat/tree/v2/backend/app/repositories"
    click DYNAMO "https://github.com/aws-samples/bedrock-claude-chat/blob/v2/cdk/lib/constructs/database.ts"
    click SF "https://github.com/aws-samples/bedrock-claude-chat/tree/v2/backend/embedding_statemachine"
    click LAMBDA_PROC "https://github.com/aws-samples/bedrock-claude-chat/blob/v2/cdk/lib/constructs/embedding.ts"

    %% Legend
    subgraph Legend
        L1[AWS Services]:::aws
        L2[Frontend]:::frontend
        L3[API Components]:::api
        L4[Auth Components]:::auth
        L5[Lambda Functions]:::lambda
        L6[Storage]:::storage
        L7[Processing]:::processing
    end
```
