# nikeyes/genai-security-demo architecture

> Architecture diagram of the GitHub repository nikeyes/genai-security-demo, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-30). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/nikeyes/genai-security-demo
- Repository: https://github.com/nikeyes/genai-security-demo

## Overview

##### Project Type and Purpose
- This is a Python-based chatbot project built to demonstrate and implement security defenses (leveraging Meta Llama tools) in a generative AI context.
- Its core functionality is to interact with various LLM providers (Amazon Bedrock, Groq, OpenAI, and Anthropic) while enforcing security policies via specialized security bot modules.

##### Analyzing the File Structure
- The primary source code resides in the "src" directory, which is sub-divided into:
- chatbot: Contains the main business logic, including different versions of bots (e.g., input guardrail bot, output guardrail bot, secure bot, unprotected bot, and a RAG implementation). These encapsulate different security or functionality aspects.
- config: Holds configuration modules for different LLM providers, overall LLM configuration (including security family switches), and logger configuration.
- data: Includes sample data and information (e.g., database_info.txt, jorge.txt) which might feed into the chatbot or help with testing the logic.
- ui: Provides the user interface components – different UI variations aligning with the chatbot modules (e.g., input_guardrail_ui, output_guardrail_ui, basic_ui, etc.).
- Additionally, there is a central entry point (chatbot_webui.py) in src that ties everything together.
- Top-level files like Makefile, pyproject.toml, and the README provide build, dependency management, and project usage instructions.

##### Key Components
a. Chatbot Logic:
- A "Chatbot Core" block that includes the various implementations:
- Input Guardrail Bot
- Output Guardrail Bot
- Secure Bot
- Unprotected Bot
- RAG (Retrieval-Augmented Generation) Bot
- That these modules manage the processing of incoming requests and security filtering mechanisms.

b. Configuration Layer:
- A "Configuration" block that encompasses the LLM configuration settings, provider-specific modules (Amazon Bedrock, Groq, OpenAI, Anthropic), and logger configurations.

c. User Interface (UI):
- Design a "User Interface" component that contains the various UI modules from the "src/ui" folder.
- This part handles user interactions and displays responses from the chatbot logic.

d. External LLM Providers:

e. Data and Prompts:
- A "Data Layer" that stores prompt definitions (src/prompts.py) and supporting data files from "src/data" which might be used for tailoring the responses or as reference material.

##### Architectural Relationships and Interactions
- From the UI to the Chatbot Core: Users input text which the chatbot processes.
- From Chatbot Core to Configuration: The core queries configuration for selecting security settings and provider-specific parameters.
- From Chatbot Core to External LLM Providers: Show API calls for generating responses.
- That security modules (Llama PromptGuard & Purple-Llama CodeShield) are integrated within the Chatbot Core to filter requests and responses.
- That the UI and core modules are decoupled from explicit provider implementations via the configuration, facilitating easier adaptation or replacement of LLM providers.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% UI Layer
    subgraph "User Interface Layer"
        ui["User Interface (UI)"]:::ui
    end

    %% Chatbot Core
    subgraph "Chatbot Core"
        direction TB
        entry["Entry Point (chatbot_webui.py)"]:::core
        bot1["Input Guardrail Bot"]:::core
        bot2["Output Guardrail Bot"]:::core
        bot3["Secure Bot"]:::core
        bot4["Unprotected Bot"]:::core
        bot5["RAG Bot"]:::core
        entry -->|"process"| bot1
        entry -->|"process"| bot2
        entry -->|"process"| bot3
        entry -->|"process"| bot4
        entry -->|"process"| bot5
    end

    %% Configuration Layer
    subgraph "Configuration Layer"
        direction TB
        config1["LLM Config (llm_config.py)"]:::config
        config2["Logger Config (logger_config.py)"]:::config
    end

    %% External LLM Providers
    subgraph "External LLM Providers"
        direction TB
        ext1["Anthropic"]:::provider
        ext2["Amazon Bedrock"]:::provider
        ext3["Groq"]:::provider
        ext4["OpenAI"]:::provider
    end

    %% Data and Prompts Layer
    subgraph "Data and Prompts"
        direction TB
        data1["Data Files (src/data)"]:::data
        prompt["Prompt Definitions (prompts.py)"]:::data
    end

    %% Interactions
    ui -->|"user_input"| entry
    entry -->|"reads_config"| config1
    entry -->|"reads_config"| config2
    entry -->|"fetch_prompt"| prompt
    entry -->|"load_data"| data1
    entry -->|"calls"| ext1
    entry -->|"calls"| ext2
    entry -->|"calls"| ext3
    entry -->|"calls"| ext4

    %% Click Events
    click bot1 "https://github.com/nikeyes/genai-security-demo/blob/main/src/chatbot/input_guardrail_bot.py"
    click bot2 "https://github.com/nikeyes/genai-security-demo/blob/main/src/chatbot/output_guardrail_bot.py"
    click bot3 "https://github.com/nikeyes/genai-security-demo/blob/main/src/chatbot/secure_bot.py"
    click bot4 "https://github.com/nikeyes/genai-security-demo/blob/main/src/chatbot/unprotected_bot.py"
    click bot5 "https://github.com/nikeyes/genai-security-demo/blob/main/src/chatbot/rag.py"
    click entry "https://github.com/nikeyes/genai-security-demo/blob/main/src/chatbot_webui.py"
    
    click config1 "https://github.com/nikeyes/genai-security-demo/blob/main/src/config/llm_config.py"
    click config2 "https://github.com/nikeyes/genai-security-demo/blob/main/src/config/logger_config.py"
    
    click ext1 "https://github.com/nikeyes/genai-security-demo/blob/main/src/config/anthropic_provider.py"
    click ext2 "https://github.com/nikeyes/genai-security-demo/blob/main/src/config/bedrock_provider.py"
    click ext3 "https://github.com/nikeyes/genai-security-demo/blob/main/src/config/groq_provider.py"
    click ext4 "https://github.com/nikeyes/genai-security-demo/blob/main/src/config/openai_provider.py"
    
    click ui "https://github.com/nikeyes/genai-security-demo/tree/main/src/ui"
    click data1 "https://github.com/nikeyes/genai-security-demo/tree/main/src/data"
    click prompt "https://github.com/nikeyes/genai-security-demo/blob/main/src/prompts.py"

    %% Styles
    classDef ui fill:#ccffcc,stroke:#000,stroke-width:1px;
    classDef core fill:#ffcccc,stroke:#000,stroke-width:1px;
    classDef config fill:#ccccff,stroke:#000,stroke-width:1px;
    classDef provider fill:#ffcc99,stroke:#000,stroke-width:1px;
    classDef data fill:#ffffcc,stroke:#000,stroke-width:1px;
```
