# idanrozin/basic-llm-agent-app-demo architecture

> Architecture diagram of the GitHub repository idanrozin/basic-llm-agent-app-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/idanrozin/basic-llm-agent-app-demo
- Repository: https://github.com/idanrozin/basic-llm-agent-app-demo

## Overview

##### Main Components
- Core Application Entry: Represent the main entry point (src/index.ts) that bootstraps the application.
- ReAct Agent: Include a component for the ReAct Agent (src/Agent.ts) that orchestrates the decision-making process.
- Tools:
- Google Search Tool (src/GoogleSearchTool.ts) for handling search queries.
- Chat LLM (src/ChatLLM.ts) for managing conversational interactions with an AI large language model.
- Code Runner Tool (src/CodeRunner.ts) for executing JavaScript code and performing dynamic evaluations.
- Type Definitions: A note on shared types located in the src/types directory, which support type safety and component interfaces.
- Environment Configuration: Include a configuration component that represents the environment setup (e.g., .env file that provides API keys for AI21 and SerpApi).

##### Relationships and Data Flows
- The Application Entry (index.ts) serves as the orchestrator that initiates and ties these components together.
- The ReAct Agent drives the decision-making process, calling on the specific tool components (Google Search, Chat LLM, Code Runner) as needed.
- Each tool interacts with external APIs (for instance, the Google Search Tool interacts with SerpApi) or services (for Chat LLM interactions).
- There is a logical flow from receiving a user query (or a test command in the playground mode) to processing it via the agent, delegating specific tasks to the respective tool, and then returning the output.

##### Architectural Patterns and Design Principles
- The project uses a modular design: each tool is in its own file and the types are explicitly defined in the types folder.
- Separation of concerns: the Agent handles decision-making, while each tool focuses on its specialized task.
- The code structure leverages dependency injection and clear interface definitions (via TypeScript types) for extensibility.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Components
    A["Application Bootstrapping (src/index.ts)"]:::core
    B["ReAct Agent (src/Agent.ts)"]:::core
    
    %% Tools Subgraph
    subgraph "Tools Layer"
        C["Google Search Tool (src/GoogleSearchTool.ts)"]:::tools
        D["Chat LLM (src/ChatLLM.ts)"]:::tools
        E["Code Runner Tool (src/CodeRunner.ts)"]:::tools
    end

    %% Supporting Components
    F["Type Definitions (src/types)"]:::config
    G["Environment Configuration (.env.example)"]:::config

    %% External Services
    H["SerpApi External Service"]:::external
    I["AI21 API Service"]:::external

    %% Connections
    A -->|"initiates"| B
    B -->|"calls"| C
    B -->|"calls"| D
    B -->|"calls"| E

    %% External API interactions
    C -->|"searchQuery"| H
    D -->|"LLMQuery"| I

    %% Environment configuration feeds API keys
    G -->|"configures"| C
    G -->|"configures"| D

    %% Type Definitions support
    F -->|"defines types"| B
    F -->|"defines types"| C
    F -->|"defines types"| D
    F -->|"defines types"| E

    %% Click Events
    click A "https://github.com/idanrozin/basic-llm-agent-app-demo/blob/main/src/index.ts"
    click B "https://github.com/idanrozin/basic-llm-agent-app-demo/blob/main/src/Agent.ts"
    click C "https://github.com/idanrozin/basic-llm-agent-app-demo/blob/main/src/GoogleSearchTool.ts"
    click D "https://github.com/idanrozin/basic-llm-agent-app-demo/blob/main/src/ChatLLM.ts"
    click E "https://github.com/idanrozin/basic-llm-agent-app-demo/blob/main/src/CodeRunner.ts"
    click F "https://github.com/idanrozin/basic-llm-agent-app-demo/tree/main/src/types"
    click G "https://github.com/idanrozin/basic-llm-agent-app-demo/blob/main/.env.example"

    %% Styles
    classDef core fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef tools fill:#98FB98,stroke:#000,stroke-width:2px;
    classDef external fill:#FFD700,stroke:#000,stroke-width:2px;
    classDef config fill:#FFDEAD,stroke:#000,stroke-width:2px;
```
