# shoetree86usn/dspy architecture

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

- Interactive diagram: https://gitdiagram.com/shoetree86usn/dspy
- Repository: https://github.com/shoetree86usn/dspy

## Overview

##### Main Components

a) Core Framework Components:
- Language Model Clients Layer
- Primitives Layer
- Modules Layer
- Optimization Layer (Teleprompt)
- Evaluation Layer

b) Integration Components:
- Adapters System
- Retrieval Models
- External Services Integration

##### Detailed Component Breakdown

A. Foundation Layer (Bottom):
- Language Model Clients
- OpenAI
- Databricks
- Local Models (HF, VLLM, etc.)
- Embedding Models

B. Core Functionality Layer (Middle):
- Primitives
- Signatures
- Predictions
- Examples
- Programs
- Assertions

C. High-Level Components (Top):
- Modules
- Predict
- ChainOfThought
- ReAct
- ProgramOfThought
- MultiChainComparison

##### Integration Points

Connections for:
- Retrieval Systems
- Vector Stores (Chroma, Pinecone, etc.)
- Search Systems (ColBERT)
- External DBs (MongoDB, Neo4j)

##### Optimization Pipeline

Optimization flow:
**Teleprompt System**
- Bootstrap Optimizers
- MIPRO Optimizers
- Ensemble Methods
- Fine-tuning Integration

##### Key Relationships to Emphasize

- How Signatures flow through the system
- Optimization feedback loop
- Demonstrate the evaluation pipeline
- Modular nature of the framework

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Styles and Classes
    classDef core fill:#2374ab,color:white
    classDef integration fill:#57a773,color:white
    classDef optimization fill:#ff8c42,color:white
    classDef evaluation fill:#845ec2,color:white
    classDef foundation fill:#2c699a,color:white

    %% Legend
    subgraph Legend
        L1[Core Components]:::core
        L2[Integration Components]:::integration
        L3[Optimization Components]:::optimization
        L4[Evaluation Components]:::evaluation
    end

    %% High-Level Components (Modules Layer)
    subgraph ModulesLayer[Modules Layer]
        Predict["Predict"]:::core
        COT["ChainOfThought"]:::core
        ReAct["ReAct"]:::core
        POT["ProgramOfThought"]:::core
        MCC["MultiChainComparison"]:::core
    end

    %% Core Functionality Layer
    subgraph CoreLayer[Core Functionality Layer]
        subgraph Primitives[Primitives]
            Signatures["Signatures"]:::core
            Predictions["Predictions"]:::core
            Examples["Examples"]:::core
            Programs["Programs"]:::core
            Assertions["Assertions"]:::core
        end
    end

    %% Integration Layer
    subgraph IntegrationLayer[Integration Layer]
        subgraph Adapters[Adapters System]
            BaseAdapter["Base Adapter"]:::integration
            ChatAdapter["Chat Adapter"]:::integration
            JSONAdapter["JSON Adapter"]:::integration
        end

        subgraph Retrieval[Retrieval Systems]
            VectorStores["Vector Stores"]:::integration
            SearchSystems["Search Systems"]:::integration
            ExternalDBs["External DBs"]:::integration
        end
    end

    %% Optimization Layer
    subgraph OptimizationLayer[Optimization Layer]
        Bootstrap["Bootstrap Optimizers"]:::optimization
        MIPRO["MIPRO Optimizers"]:::optimization
        Ensemble["Ensemble Methods"]:::optimization
        FineTuning["Fine-tuning Integration"]:::optimization
    end

    %% Evaluation Layer
    subgraph EvalLayer[Evaluation Layer]
        CoreEval["Core Evaluation"]:::evaluation
        Metrics["Metrics"]:::evaluation
    end

    %% Foundation Layer
    subgraph FoundationLayer[Language Model Clients Layer]
        OpenAI["OpenAI"]:::foundation
        Databricks["Databricks"]:::foundation
        LocalModels["Local Models"]:::foundation
        EmbeddingModels["Embedding Models"]:::foundation
    end

    %% Relationships
    ModulesLayer --> CoreLayer
    CoreLayer --> IntegrationLayer
    IntegrationLayer --> FoundationLayer
    OptimizationLayer --> CoreLayer
    OptimizationLayer --> ModulesLayer
    EvalLayer --> CoreLayer
    EvalLayer --> ModulesLayer

    %% Click Events
    click OpenAI "https://github.com/shoetree86usn/dspy/blob/main/dspy/clients/openai.py"
    click Databricks "https://github.com/shoetree86usn/dspy/blob/main/dspy/clients/databricks.py"
    click Signatures "https://github.com/shoetree86usn/dspy/tree/main/dspy/signatures/"
    click Predictions "https://github.com/shoetree86usn/dspy/blob/main/dspy/primitives/prediction.py"
    click Examples "https://github.com/shoetree86usn/dspy/blob/main/dspy/primitives/example.py"
    click Programs "https://github.com/shoetree86usn/dspy/blob/main/dspy/primitives/program.py"
    click Assertions "https://github.com/shoetree86usn/dspy/blob/main/dspy/primitives/assertions.py"
    click COT "https://github.com/shoetree86usn/dspy/blob/main/dspy/predict/chain_of_thought.py"
    click ReAct "https://github.com/shoetree86usn/dspy/blob/main/dspy/predict/react.py"
    click POT "https://github.com/shoetree86usn/dspy/blob/main/dspy/predict/program_of_thought.py"
    click MCC "https://github.com/shoetree86usn/dspy/blob/main/dspy/predict/multi_chain_comparison.py"
    click Bootstrap "https://github.com/shoetree86usn/dspy/blob/main/dspy/teleprompt/bootstrap.py"
    click MIPRO "https://github.com/shoetree86usn/dspy/blob/main/dspy/teleprompt/mipro_optimizer_v2.py"
    click Ensemble "https://github.com/shoetree86usn/dspy/blob/main/dspy/teleprompt/ensemble.py"
    click CoreEval "https://github.com/shoetree86usn/dspy/blob/main/dspy/evaluate/evaluate.py"
    click Metrics "https://github.com/shoetree86usn/dspy/blob/main/dspy/evaluate/metrics.py"
    click BaseAdapter "https://github.com/shoetree86usn/dspy/blob/main/dspy/adapters/base.py"
    click ChatAdapter "https://github.com/shoetree86usn/dspy/blob/main/dspy/adapters/chat_adapter.py"
    click JSONAdapter "https://github.com/shoetree86usn/dspy/blob/main/dspy/adapters/json_adapter.py"
    click SearchSystems "https://github.com/shoetree86usn/dspy/blob/main/dspy/retrieve/colbertv2.py"
```
