# deepset-ai/haystack architecture

> Architecture diagram of the GitHub repository deepset-ai/haystack, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-08). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/deepset-ai/haystack
- Repository: https://github.com/deepset-ai/haystack

## Overview

Haystack is a Python framework for composing LLM applications from reusable components and agent workflows. A representative RAG flow accepts documents or a query, prepares and embeds content, stores and retrieves relevant documents, then builds a prompt and generates an answer. The Pipeline orchestrates component execution; agents extend workflows with tools and lifecycle hooks. The README documents broader routing, ranking, evaluation, multimodal, and async capabilities. Some subsystem links below are README-level descriptions rather than inspected call sites.

Main entry points: [`haystack/core/pipeline/pipeline.py`](https://github.com/deepset-ai/haystack/blob/main/haystack/core/pipeline/pipeline.py) (Pipeline), [`haystack/components/agents/agent.py`](https://github.com/deepset-ai/haystack/blob/main/haystack/components/agents/agent.py) (Agent), [`haystack/components/generators/chat/openai.py`](https://github.com/deepset-ai/haystack/blob/main/haystack/components/generators/chat/openai.py) (Chat Generators), [`haystack/core/component/component.py`](https://github.com/deepset-ai/haystack/blob/main/haystack/core/component/component.py) (Component Runtime)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_orchestration["Orchestration"]
  node_pipeline["Pipeline<br/>[pipeline.py]"]
  node_component["Component Runtime<br/>[component.py]"]
end

subgraph group_ingestion["Document Ingestion"]
  node_converters["Document Converters<br/>[json.py]"]
  node_preprocessors["Preprocessors"]
  node_embedders["Embedders"]
  node_document_store[("Document Store<br/>[document_store.py]")]
end

subgraph group_retrieval["Retrieval Context"]
  node_query_expander["Query Expansion<br/>[query_expander.py]"]
  node_retrievers["Retrievers"]
  node_rankers["Rankers"]
  node_routers["Routers"]
end

subgraph group_generation["Generation Agents"]
  node_prompt_builder["Prompt Builder<br/>[prompt_builder.py]"]
  node_chat_generator["Chat Generators<br/>[openai.py]"]
  node_answer_builder["Answer Builder<br/>[answer_builder.py]"]
  node_agent["Agent<br/>[agent.py]"]
  node_tools["Tools<br/>[tool.py]"]
  node_hooks["Agent Hooks"]
end

subgraph group_operations["Evaluation Operations"]
  node_evaluators["Evaluators"]
  node_telemetry["Telemetry"]
end

node_user(("Application User"))

node_user -->|"configures and runs"| node_pipeline
node_pipeline -->|"executes components"| node_component
node_pipeline -.->|"orchestrates ingestion"| node_converters
node_pipeline -.->|"orchestrates preparation"| node_preprocessors
node_pipeline -.->|"orchestrates embedding"| node_embedders
node_pipeline -.->|"orchestrates storage"| node_document_store
node_pipeline -.->|"orchestrates retrieval"| node_query_expander
node_pipeline -->|"orchestrates retrieval"| node_retrievers
node_pipeline -->|"orchestrates ranking"| node_rankers
node_pipeline -->|"orchestrates routing"| node_routers
node_pipeline -.->|"orchestrates prompting"| node_prompt_builder
node_pipeline -.->|"orchestrates generation"| node_chat_generator
node_pipeline -.->|"orchestrates answers"| node_answer_builder
node_pipeline -.->|"orchestrates evaluation"| node_evaluators
node_agent -->|"invokes tools"| node_tools
node_agent -->|"runs lifecycle hooks"| node_hooks
node_pipeline -->|"supports workflows"| node_agent
node_user -.->|"starts workflow"| node_agent
node_pipeline -.->|"emits telemetry"| node_telemetry
node_chat_generator -.->|"returns generated output"| node_user

click node_pipeline "https://github.com/deepset-ai/haystack/blob/main/haystack/core/pipeline/pipeline.py"
click node_component "https://github.com/deepset-ai/haystack/blob/main/haystack/core/component/component.py"
click node_converters "https://github.com/deepset-ai/haystack/blob/main/haystack/components/converters/json.py"
click node_preprocessors "https://github.com/deepset-ai/haystack/tree/main/haystack/components/preprocessors"
click node_embedders "https://github.com/deepset-ai/haystack/tree/main/haystack/components/embedders"
click node_document_store "https://github.com/deepset-ai/haystack/blob/main/haystack/document_stores/in_memory/document_store.py"
click node_query_expander "https://github.com/deepset-ai/haystack/blob/main/haystack/components/query/query_expander.py"
click node_retrievers "https://github.com/deepset-ai/haystack/tree/main/haystack/components/retrievers"
click node_rankers "https://github.com/deepset-ai/haystack/tree/main/haystack/components/rankers"
click node_routers "https://github.com/deepset-ai/haystack/tree/main/haystack/components/routers"
click node_prompt_builder "https://github.com/deepset-ai/haystack/blob/main/haystack/components/builders/prompt_builder.py"
click node_chat_generator "https://github.com/deepset-ai/haystack/blob/main/haystack/components/generators/chat/openai.py"
click node_answer_builder "https://github.com/deepset-ai/haystack/blob/main/haystack/components/builders/answer_builder.py"
click node_agent "https://github.com/deepset-ai/haystack/blob/main/haystack/components/agents/agent.py"
click node_tools "https://github.com/deepset-ai/haystack/blob/main/haystack/tools/tool.py"
click node_hooks "https://github.com/deepset-ai/haystack/tree/main/haystack/hooks"
click node_evaluators "https://github.com/deepset-ai/haystack/tree/main/haystack/components/evaluators"
click node_telemetry "https://github.com/deepset-ai/haystack/tree/main/haystack/telemetry"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_pipeline,node_component,node_user toneBlue
class node_converters,node_preprocessors,node_embedders,node_document_store toneAmber
class node_query_expander,node_retrievers,node_rankers,node_routers toneMint
class node_prompt_builder,node_chat_generator,node_answer_builder,node_agent,node_tools,node_hooks toneRose
class node_evaluators,node_telemetry toneIndigo
```

## Components

### Orchestration

- [Pipeline](https://github.com/deepset-ai/haystack/blob/main/haystack/core/pipeline/pipeline.py): `haystack/core/pipeline/pipeline.py`
- [Component Runtime](https://github.com/deepset-ai/haystack/blob/main/haystack/core/component/component.py): `haystack/core/component/component.py`

### Document Ingestion

- [Document Converters](https://github.com/deepset-ai/haystack/blob/main/haystack/components/converters/json.py): `haystack/components/converters/json.py`
- [Preprocessors](https://github.com/deepset-ai/haystack/tree/main/haystack/components/preprocessors): `haystack/components/preprocessors`
- [Embedders](https://github.com/deepset-ai/haystack/tree/main/haystack/components/embedders): `haystack/components/embedders`
- [Document Store](https://github.com/deepset-ai/haystack/blob/main/haystack/document_stores/in_memory/document_store.py): `haystack/document_stores/in_memory/document_store.py`

### Retrieval Context

- [Query Expansion](https://github.com/deepset-ai/haystack/blob/main/haystack/components/query/query_expander.py): `haystack/components/query/query_expander.py`
- [Retrievers](https://github.com/deepset-ai/haystack/tree/main/haystack/components/retrievers): `haystack/components/retrievers`
- [Rankers](https://github.com/deepset-ai/haystack/tree/main/haystack/components/rankers): `haystack/components/rankers`
- [Routers](https://github.com/deepset-ai/haystack/tree/main/haystack/components/routers): `haystack/components/routers`

### Generation Agents

- [Prompt Builder](https://github.com/deepset-ai/haystack/blob/main/haystack/components/builders/prompt_builder.py): `haystack/components/builders/prompt_builder.py`
- [Chat Generators](https://github.com/deepset-ai/haystack/blob/main/haystack/components/generators/chat/openai.py): `haystack/components/generators/chat/openai.py`
- [Answer Builder](https://github.com/deepset-ai/haystack/blob/main/haystack/components/builders/answer_builder.py): `haystack/components/builders/answer_builder.py`
- [Agent](https://github.com/deepset-ai/haystack/blob/main/haystack/components/agents/agent.py): `haystack/components/agents/agent.py`
- [Tools](https://github.com/deepset-ai/haystack/blob/main/haystack/tools/tool.py): `haystack/tools/tool.py`
- [Agent Hooks](https://github.com/deepset-ai/haystack/tree/main/haystack/hooks): `haystack/hooks`

### Evaluation Operations

- [Evaluators](https://github.com/deepset-ai/haystack/tree/main/haystack/components/evaluators): `haystack/components/evaluators`
- [Telemetry](https://github.com/deepset-ai/haystack/tree/main/haystack/telemetry): `haystack/telemetry`

### Other components

- **Application User**

## Connections

- Application User → Pipeline: configures and runs
- Pipeline → Component Runtime: executes components (evidence: `haystack/core/pipeline/pipeline.py`)
- Pipeline → Document Converters: orchestrates ingestion
- Pipeline → Preprocessors: orchestrates preparation
- Pipeline → Embedders: orchestrates embedding
- Pipeline → Document Store: orchestrates storage
- Pipeline → Query Expansion: orchestrates retrieval
- Pipeline → Retrievers: orchestrates retrieval (evidence: `haystack/core/pipeline/pipeline.py`)
- Pipeline → Rankers: orchestrates ranking
- Pipeline → Routers: orchestrates routing
- Pipeline → Prompt Builder: orchestrates prompting (evidence: `haystack/core/pipeline/pipeline.py`)
- Pipeline → Chat Generators: orchestrates generation
- Pipeline → Answer Builder: orchestrates answers (evidence: `haystack/core/pipeline/pipeline.py`)
- Pipeline → Evaluators: orchestrates evaluation
- Agent → Tools: invokes tools
- Agent → Agent Hooks: runs lifecycle hooks
- Pipeline → Agent: supports workflows
- Application User → Agent: starts workflow
- Pipeline → Telemetry: emits telemetry (evidence: `haystack/core/pipeline/pipeline.py`)
- Chat Generators → Application User: returns generated output
