# olehxch/llm-code-examples architecture

> Architecture diagram of the GitHub repository olehxch/llm-code-examples, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-08-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/olehxch/llm-code-examples
- Repository: https://github.com/olehxch/llm-code-examples

## Overview

##### Project Type and Purpose
- This is an educational “code-examples” repository, not a running product. It demonstrates patterns for working with large language models (LLMs).
- It comprises three logical sub-projects:
- LLM-Book Examples: OpenAI API + ChromaDB vector store.
- AutoGEN Examples: agent orchestration with Ollama + code executors (local/Docker).
- Nvidia Examples: integration with NVIDIA NIM inference microservices.

##### File Structure Analysis
- Top-level directories:
- autogen-examples/
- llm-book-examples/
- nvidia-examples/
- Supporting files:
- pyproject.toml, uv.lock → Python project metadata + uv package-manager lock.
- .python-version → Python runtime version.
- .gitignore, README.md → documentation + ignore rules.
- Each example directory contains Python scripts, a requirements file (req.txt) and expects a .env with API keys.
- Patterns:
- Each sub-project is self-contained, follows a consistent naming convention for numbered examples.
- The AutoGEN examples introduce sub-components: agents, human-input handlers, code executors.

##### Key Architectural Insights from README
- LLM-Book: uses OpenAI Chat or Completion API, optional embeddings & vector DB calls.
- AutoGEN: uses Microsoft’s Autogen framework + Ollama as local LLM host; supports two agent types (AssistantAgent, UserProxyAgent), multiple execution modes (local vs Docker, CLI vs Jupyter).
- Nvidia: calls NVIDIA NIM inference microservices via OpenAI-compatible API endpoints.

##### Components
a. Local Environment Layer
– Python 3.12 runtime
– uv package manager + installed dependencies
– .env files for API keys
– LLM-Book Examples
– AutoGEN Examples
– Nvidia Examples
c. External Services Layer
– OpenAI API (chat, completion, embeddings)
– ChromaDB vector database
– Ollama local LLM host
– Docker engine (for containerized code execution)
– Jupyter kernel (for Jupyter executor)
– NVIDIA NIM inference microservices
d. Data Stores
– embeddings.json / data.txt in some examples
– vector DB (ChromaDB)
– function‐library vector DB

##### Relationships and Data Flows
- Python script ► loads dependencies ► reads .env ► builds prompt or agent configuration.
- LLM-Book examples:
- call OpenAI API ► receive text or embeddings ► optionally write/read ChromaDB.
- AutoGEN examples:
- instantiate agents ► orchestrate conversation patterns ► for code messages call code executor (local or Docker or Jupyter) ► return output to agent conversation.
- Nvidia examples:
- call NVIDIA NIM API ► receive response (streaming or full) ► process/display.

##### Architectural Patterns and Design Principles
- Modularity: examples grouped by capabilities.
- Layered external integrations: clear separation of API calls, vector DB, code execution.
- Agent-based orchestration (AutoGEN): ConversableAgent pattern, strategy for human input and termination.
- Vector retrieval pattern: store embeddings, query DB by cosine similarity.
- Function calling optimization: selective retrieval of functions from vector DB.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Local Environment Layer
    subgraph "Local Environment Layer"
        LN1["Python Runtime 3.12"]:::localEnv
        LN2["uv Package Manager"]:::localEnv
        LN3[".env Files"]:::localEnv
        LN4["pyproject.toml"]:::localEnv
        LN5["uv.lock"]:::localEnv
        LN6[".python-version"]:::localEnv
    end

    %% Example Modules Layer - LLM-Book
    subgraph "LLM-Book Examples" 
        LB_root["llm-book-examples/"]:::llm
        LB0["0-basic-prompt-execution.py"]:::llm
        LB6["6-embeddings"]:::llm
        LB7["7-vector-database"]:::llm
    end

    %% Example Modules Layer - AutoGEN
    subgraph "AutoGEN Examples"
        AG_root["autogen-examples/"]:::autogen
        AG0["0-basic-prompt-execution.py"]:::autogen
        AG4["4-code-executors"]:::autogen
    end

    %% Example Modules Layer - NVIDIA
    subgraph "Nvidia Examples"
        NV_root["nvidia-examples/"]:::nvidia
        NV0["0-basic-prompt-execution"]:::nvidia
        NV2["2-recognize-images"]:::nvidia
    end

    %% Data Stores
    subgraph "Data Stores"
        DS1["ChromaDB Vector DB"]:::datastore
        DS2["embeddings.json"]:::datastore
        DS3["data.txt"]:::datastore
    end

    %% External Services
    subgraph "External Services"
        EX1(["OpenAI API"]):::external
        EX2(["ChromaDB Service"]):::external
        EX3(["Ollama LLM Host"]):::external
        EX4(["Docker Engine"]):::external
        EX5(["Jupyter Kernel"]):::external
        EX6(["NVIDIA NIM API"]):::external
    end

    %% Relationships
    LN1 -->|loads deps| LB_root
    LN2 -->|installs| LB_root
    LN3 -->|provides keys| LB_root
    LB0 -->|calls| EX1
    LB6 -->|creates embeddings| DS2
    LB6 -->|stores| EX2
    LB7 -->|queries vectors| DS1
    LB7 -->|calls| EX1

    AG_root -->|initializes| EX3
    AG_root -->|executes code| EX4
    AG_root -->|orchestrates| EX5

    NV_root -->|calls| EX6
    NV0 -->|streams or not| EX6
    NV2 -->|process images| EX6

    %% Modules to Data Stores
    LB6 --> DS2
    LB7 --> DS1
    LB7 --> DS3

    %% Click Events
    click LN4 "https://github.com/olehxch/llm-code-examples/blob/main/.pyproject.toml"
    click LN5 "https://github.com/olehxch/llm-code-examples/blob/main/uv.lock"
    click LN6 "https://github.com/olehxch/llm-code-examples/blob/main/.python-version"

    click LB_root "https://github.com/olehxch/llm-code-examples/tree/main/llm-book-examples/"
    click LB0 "https://github.com/olehxch/llm-code-examples/blob/main/llm-book-examples/0-basic-prompt-execution/basic-prompt-execution.py"
    click LB6 "https://github.com/olehxch/llm-code-examples/tree/main/llm-book-examples/6-embeddings/"
    click LB7 "https://github.com/olehxch/llm-code-examples/tree/main/llm-book-examples/7-vector-database/"

    click AG_root "https://github.com/olehxch/llm-code-examples/tree/main/autogen-examples/"
    click AG0 "https://github.com/olehxch/llm-code-examples/blob/main/autogen-examples/0-basic-prompt-execution/basic-prompt-execution.py"
    click AG4 "https://github.com/olehxch/llm-code-examples/tree/main/autogen-examples/4-code-executors/"

    click NV_root "https://github.com/olehxch/llm-code-examples/tree/main/nvidia-examples/"
    click NV0 "https://github.com/olehxch/llm-code-examples/blob/main/nvidia-examples/0-basic-prompt-execution/streaming-false.py"
    click NV2 "https://github.com/olehxch/llm-code-examples/blob/main/nvidia-examples/2-recognize-images/recognize-images-deplot.py"

    %% Styles
    classDef localEnv fill:#e0f7fa,stroke:#006064,color:#004d40
    classDef llm fill:#e8eaf6,stroke:#3f51b5,color:#1a237e
    classDef autogen fill:#e8f5e9,stroke:#388e3c,color:#1b5e20
    classDef nvidia fill:#f3e5f5,stroke:#6a1b9a,color:#4a148c
    classDef external fill:#fff3e0,stroke:#fb8c00,color:#e65100
    classDef datastore fill:#f1f8e9,stroke:#8bc34a,color:#33691e
```
