# moritalous/bedrock-mcp-streamlit architecture

> Architecture diagram of the GitHub repository moritalous/bedrock-mcp-streamlit, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-04-11). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/moritalous/bedrock-mcp-streamlit
- Repository: https://github.com/moritalous/bedrock-mcp-streamlit

## Overview

##### Project Overview
- This project is a chat application built with Streamlit. Its key features are integration with Langchain (for handling LLM chat models) and with an external MCP (Model Context Protocol) server.
- The application's behavior is configured via two JSON files – one for LLM settings (config.json) and another for MCP server settings (mcp_config.json). Chat history is persisted in YAML files under the “chat_history” directory.

##### Identifying the Main Components
- Frontend (Chat Interface): Constructed using Streamlit and rendered in the UI provided by src/main.py. In the sidebar, users can select LLM models, adjust settings, and load past chat history.
- Chat Engine / Business Logic: Found in the “src” directory — mainly in files like main.py, prompts.py, trace.py, and util.py. This area handles:
– Invoking the Langchain chat model (configured in config.json).
– Processing and formatting messages (via modules like util.py’s MessageProcessor and its subclasses).
– Managing flow control (the orchestration between receiving user input and invoking external services).
- External Services & Protocol Integration:
– LLM Providers: Specific models (e.g., “Claude 3.7 Sonnet” and “Amazon Nova Pro”) are configured in config.json and used via the Langchain integration.
– MCP Server: Configuration in mcp_config.json defines how to interact with the MCP tool, including required transport details and environment settings.
- Persistence / Storage: Chat history is stored in YAML files (in the “chat_history” directory).

##### Relationships and Interactions
- The user interacts with the chat interface (Streamlit UI) which sends messages into the chat engine.
- The chat engine uses Langchain to initialize and interact with an LLM (as configured in config.json).
- After processing user input and responses, the application might contact or utilize MCP tools as specified in mcp_config.json to add context or trigger specialized operations.
- Each conversation is archived in a YAML file under chat_history for later retrieval, which can be selected via the sidebar.
- Configurations (from config.json and mcp_config.json) are loaded at the start and flow throughout the application to configure runtime behavior.

##### Architectural Patterns and Important Design Notes
- Modularity: The code is split into multiple modules (for prompts, trace, and utility functions) that abstract away specific concerns.
- Configuration Driven: Behavior and integrations are determined by external JSON configuration files.
- Separation of Concerns: The UI (streamlit) is separated from the business logic (LLM and MCP integrations) and the persistence layer.
- External Integrations: Uses third-party libraries like Langchain and Bedrock to encapsulate chat model functionalities.

##### Final Review – Ensure
- Each component is clearly labeled.
- Use annotations (or legends) if needed to explain configuration files and communication protocols.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Frontend Layer
    subgraph "Frontend"
        UI["Streamlit Chat UI"]:::ui
    end

    %% Backend Layer
    subgraph "Backend"
        BL["Chat Engine / Business Logic"]:::backend
    end

    %% External Services
    subgraph "External Services"
        LLM["Langchain & Bedrock Chat Model"]:::external
        MCP["MCP Server"]:::external
    end

    %% Persistence Layer
    subgraph "Persistence"
        Storage["Chat History Storage (YAML Files)"]:::storage
    end

    %% Configuration Files
    subgraph "Configurations"
        LLMConfig["LLM Config (config.json)"]:::config
        MCPConfig["MCP Config (mcp_config.json)"]:::config
    end

    %% Data Flow
    UI -->|"UserMessageInput"| BL
    BL -->|"init_chat_model"| LLM
    BL -->|"Tool&context_requests"| MCP
    BL -->|"SavingConversationHistory"| Storage

    LLMConfig -->|"configuration"| LLM
    MCPConfig -->|"configuration"| MCP

    %% Click Events
    click UI "https://github.com/moritalous/bedrock-mcp-streamlit/blob/main/src/main.py"
    click BL "https://github.com/moritalous/bedrock-mcp-streamlit/tree/main/src/"
    click LLM "https://github.com/moritalous/bedrock-mcp-streamlit/blob/main/config.json"
    click MCP "https://github.com/moritalous/bedrock-mcp-streamlit/blob/main/mcp_config.json"
    click Storage "https://github.com/moritalous/bedrock-mcp-streamlit/tree/main/chat_history"

    %% Styles
    classDef ui fill:#f9c,stroke:#333,stroke-width:2px,rx:5,ry:5
    classDef backend fill:#ff9,stroke:#333,stroke-width:2px
    classDef external fill:#9f9,stroke:#333,stroke-width:2px
    classDef storage fill:#9ff,stroke:#333,stroke-width:2px
    classDef config fill:#f99,stroke:#333,stroke-width:2px,stroke-dasharray: 5 5
```
