# aws-samples/artifacts-and-tools-for-bedrock architecture

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

- Interactive diagram: https://gitdiagram.com/aws-samples/artifacts-and-tools-for-bedrock
- Repository: https://github.com/aws-samples/artifacts-and-tools-for-bedrock

## Overview

##### Main components
- Frontend/User Interface:
– Found in “lib/playground/user-interface”.
– Built with Typescript/React (TSX, HTML, SCSS, etc.).
– Downloads configuration (aws-exports.json) at runtime and interacts with backend endpoints.
- API/Backend Services:
– Organized in “lib/playground/functions”.
– Split across several modules and responsibilities including “api-handler” (handling routes for files, health, sessions), “message-handler” for handling interactive chat/messaging features, “authorizer” for access control, and “connection-handler”.
- AWS Deployment/Infrastructure:
– Infrastructure described in CDK-related files (e.g., “cdk.json”, “lib/stack.ts”) and deployment scripts (bin/artifacts-and-tools.ts).
– Components such as API Gateway, Lambda functions, AWS Cognito (for user authentication), CloudFront distribution, and others are provisioned as part of the deployment.
- Tools and External Services:
– Code Interpreter (under “lib/tools/code-interpreter”) – includes its own Dockerfile, Python logic, and dependencies.
– Web Search Tool (under “lib/tools/web-search”) – integrates externally via the Brave Search API; it includes its own Dockerfile and TypeScript/Node based logic.
– Artifacts functionality for content visualization.

##### And represent relationships and interactions
- The user accesses the web application (CloudFront distribution serving static files and the UI) and logs in via Cognito.
- The UI interacts with the backend APIs (exposed via API routes, as organized in the “api-handler” module) for retrieving data, managing sessions, and uploading/fetching files.
- Serverless functions (Lambda functions or containers for Code Interpreter and Web Search) provide the dynamic backend logic; they interact with each other when orchestrating tasks.
- The AWS CDK stack encapsulates the provisioning of these components, ensuring that the various services are instantiated with correct inter-dependencies.

##### Architectural patterns and design principles
- Modular microservices/serverless pattern: the backend is separated into distinct functions (such as message handling, authorization, and connection management), each with its own directory and responsibilities.
- Separation of concerns between the presentation layer (UI) and the business logic/engine (Lambda functions and tools).
- Infrastructure-as-Code (using AWS CDK) that allows reproducible deployment setups.

##### Relevant technologies and tools
- Frontend: React, Typescript, Vite (as seen from vite.config.ts), SCSS for styling, and various UI components for chat and sessions.
- Backend: Python for some functions (especially in “api-handler”) and Node/Typescript in others (e.g., “user-interface”, “web-search”).
- AWS Services: Lambda, Cognito, CloudFront, and AWS CDK for deployment orchestration.
- Docker: Used for building container images for Code Interpreter and Web Search tools.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend Layer"
        UI["User Interface (React App)"]:::frontend
        Artifacts["Artifacts Visualizer"]:::frontend
    end

    %% Backend Services Layer
    subgraph "Backend Services"
        APIHandler["API Handler (Sessions, Files, Health)"]:::backend
        MessageHandler["Message Handler"]:::backend
        Authorizer["Authorizer Function"]:::backend
        ConnectionHandler["Connection Handler"]:::backend
    end

    %% Tools Layer
    subgraph "Tools"
        CodeInterpreter["Code Interpreter Tool"]:::tools
        WebSearch["Web Search Tool"]:::tools
    end

    %% AWS Infrastructure Layer
    subgraph "AWS Infrastructure"
        AWSCDK["AWS CDK Deployment"]:::infra
    end

    %% Dataflow and relationships
    UI -->|"API_Calls"| APIHandler
    UI -->|"uses"| Artifacts
    APIHandler -->|"invokes"| MessageHandler
    APIHandler -->|"calls"| Authorizer
    APIHandler -->|"triggers"| ConnectionHandler
    APIHandler -->|"integrates"| CodeInterpreter
    APIHandler -->|"integrates"| WebSearch

    %% Provisioning from AWS Infrastructure
    AWSCDK -->|"provisions"| UI
    AWSCDK -->|"provisions"| APIHandler
    AWSCDK -->|"provisions"| MessageHandler
    AWSCDK -->|"provisions"| Authorizer
    AWSCDK -->|"provisions"| ConnectionHandler
    AWSCDK -->|"provisions"| CodeInterpreter
    AWSCDK -->|"provisions"| WebSearch

    %% Click Events for Component Mapping
    click UI "https://github.com/aws-samples/artifacts-and-tools-for-bedrock/tree/main/lib/playground/user-interface"
    click Artifacts "https://github.com/aws-samples/artifacts-and-tools-for-bedrock/tree/main/lib/playground/user-interface/src/components/artifacts"
    click APIHandler "https://github.com/aws-samples/artifacts-and-tools-for-bedrock/tree/main/lib/playground/functions/api-handler"
    click MessageHandler "https://github.com/aws-samples/artifacts-and-tools-for-bedrock/tree/main/lib/playground/functions/message-handler"
    click Authorizer "https://github.com/aws-samples/artifacts-and-tools-for-bedrock/tree/main/lib/playground/functions/authorizer"
    click ConnectionHandler "https://github.com/aws-samples/artifacts-and-tools-for-bedrock/tree/main/lib/playground/functions/connection-handler"
    click AWSCDK "https://github.com/aws-samples/artifacts-and-tools-for-bedrock/blob/main/cdk.json"
    click AWSCDK "https://github.com/aws-samples/artifacts-and-tools-for-bedrock/blob/main/lib/stack.ts"
    click AWSCDK "https://github.com/aws-samples/artifacts-and-tools-for-bedrock/blob/main/bin/artifacts-and-tools.ts"
    click CodeInterpreter "https://github.com/aws-samples/artifacts-and-tools-for-bedrock/tree/main/lib/tools/code-interpreter"
    click WebSearch "https://github.com/aws-samples/artifacts-and-tools-for-bedrock/tree/main/lib/tools/web-search"

    %% Styles
    classDef frontend fill:#a9d0f5,stroke:#333,stroke-width:2px;
    classDef backend fill:#c2f0c2,stroke:#333,stroke-width:2px;
    classDef infra fill:#f5f5a9,stroke:#333,stroke-width:2px;
    classDef tools fill:#f7c5a0,stroke:#333,stroke-width:2px;
```
