# monocle2ai/monocle architecture

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

- Interactive diagram: https://gitdiagram.com/monocle2ai/monocle
- Repository: https://github.com/monocle2ai/monocle

## Overview

##### Main Components

a) Core Instrumentation Layer
- Common instrumentation components from src/monocle_apptrace/instrumentation/common
- Metamodel system which handles different frameworks

b) Framework Integration Layer
- Supported frameworks (Langchain, LlamaIndex, Haystack, etc.)
- To the core instrumentation layer
- Framework-specific adapters and helpers

c) Export System
- Various exporters (File, AWS S3, Azure Blob)
- Base exporter and processor architecture

##### Relationships and Data Flow

**[GenAI Application] → [Framework Integration Layer] → [Core Instrumentation] → [Export System] → [Storage Destinations]**

##### Component Details

Core Instrumentation:
**┌─ Core Instrumentation ─────┐**
- Span Handler            │
- Instrumentor            │
- Wrapper                 │
- Constants & Utils       │
- ┘

Metamodel System:
**┌─ Metamodel ──────────────┐**
- Botocore              │
- Haystack              │
- Langchain             │
- LlamaIndex            │
- ┘

Export System:
**┌─ Export System ──────────┐**
- Base Exporter         │
- File Exporter         │
- S3 Exporter          │
- Azure Blob Exporter   │
- Okahu Exporter        │
- ┘

##### Implementation Details

- Use rectangles for main components

##### Additional Elements

Supporting elements:
- Version compatibility notes
- Supported frameworks list
- Storage backend options
- Main configuration points

This system design should effectively communicate Monocle's architecture as a GenAI application tracing framework while highlighting its extensibility and integration capabilities with various frameworks and storage solutions.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef core fill:#3498db,stroke:#2980b9,color:white
    classDef framework fill:#2ecc71,stroke:#27ae60,color:white
    classDef export fill:#e67e22,stroke:#d35400,color:white
    classDef storage fill:#9b59b6,stroke:#8e44ad,color:white
    classDef entity fill:#95a5a6,stroke:#7f8c8d,color:white
    classDef helper fill:#1abc9c,stroke:#16a085,color:white

    %% Main Application
    APP[GenAI Application]

    %% Core Instrumentation Layer
    subgraph CoreInst[Core Instrumentation Layer]
        SpanHandler[Span Handler]:::core
        Instrumentor[Instrumentor]:::core
        Wrapper[Wrapper]:::core
        Constants[Constants]:::core
        Utils[Utils]:::core
    end

    %% Framework Integration Layer
    subgraph Frameworks[Framework Integration Layer]
        subgraph MetaModel[Metamodel System]
            Langchain[Langchain]:::framework
            LlamaIndex[LlamaIndex]:::framework
            Haystack[Haystack]:::framework
            Botocore[Botocore]:::framework
        end

        subgraph Entities[Framework Entities]
            LangchainEnt[Langchain Entities]:::entity
            LlamaIndexEnt[LlamaIndex Entities]:::entity
            HaystackEnt[Haystack Entities]:::entity
            BotocoreEnt[Botocore Entities]:::entity
        end

        subgraph Helpers[Framework Helpers]
            LangchainHelper[Langchain Helper]:::helper
            LlamaIndexHelper[LlamaIndex Helper]:::helper
            HaystackHelper[Haystack Helper]:::helper
            BotocoreHelper[Botocore Helper]:::helper
        end
    end

    %% Export System
    subgraph ExportSys[Export System]
        BaseExporter[Base Exporter]:::export
        FileExporter[File Exporter]:::export
        S3Exporter[S3 Exporter]:::export
        BlobExporter[Azure Blob Exporter]:::export
        OkahuExporter[Okahu Exporter]:::export
        ExporterProcessor[Exporter Processor]:::export
    end

    %% Storage Destinations
    FileSystem[File System]:::storage
    S3[AWS S3]:::storage
    AzureBlob[Azure Blob Storage]:::storage
    Okahu[Okahu Platform]:::storage

    %% Relationships
    APP --> Frameworks
    Frameworks --> CoreInst
    CoreInst --> ExportSys
    
    %% Framework Relationships
    Langchain --> LangchainEnt
    LlamaIndex --> LlamaIndexEnt
    Haystack --> HaystackEnt
    Botocore --> BotocoreEnt
    
    Langchain --> LangchainHelper
    LlamaIndex --> LlamaIndexHelper
    Haystack --> HaystackHelper
    Botocore --> BotocoreHelper
    
    %% Export Relationships
    BaseExporter --> ExporterProcessor
    FileExporter --> FileSystem
    S3Exporter --> S3
    BlobExporter --> AzureBlob
    OkahuExporter --> Okahu

    %% Click Events
    click CoreInst "https://github.com/monocle2ai/monocle/tree/main/src/monocle_apptrace/instrumentation/common/"
    click SpanHandler "https://github.com/monocle2ai/monocle/blob/main/src/monocle_apptrace/instrumentation/common/span_handler.py"
    click Instrumentor "https://github.com/monocle2ai/monocle/blob/main/src/monocle_apptrace/instrumentation/common/instrumentor.py"
    click Wrapper "https://github.com/monocle2ai/monocle/blob/main/src/monocle_apptrace/instrumentation/common/wrapper.py"
    click Constants "https://github.com/monocle2ai/monocle/blob/main/src/monocle_apptrace/instrumentation/common/constants.py"
    click Utils "https://github.com/monocle2ai/monocle/blob/main/src/monocle_apptrace/instrumentation/common/utils.py"
    
    click Langchain "https://github.com/monocle2ai/monocle/tree/main/src/monocle_apptrace/instrumentation/metamodel/langchain/"
    click LlamaIndex "https://github.com/monocle2ai/monocle/tree/main/src/monocle_apptrace/instrumentation/metamodel/llamaindex/"
    click Haystack "https://github.com/monocle2ai/monocle/tree/main/src/monocle_apptrace/instrumentation/metamodel/haystack/"
    click Botocore "https://github.com/monocle2ai/monocle/tree/main/src/monocle_apptrace/instrumentation/metamodel/botocore/"
    
    click BaseExporter "https://github.com/monocle2ai/monocle/blob/main/src/monocle_apptrace/exporters/base_exporter.py"
    click FileExporter "https://github.com/monocle2ai/monocle/blob/main/src/monocle_apptrace/exporters/file_exporter.py"
    click S3Exporter "https://github.com/monocle2ai/monocle/blob/main/src/monocle_apptrace/exporters/aws/s3_exporter.py"
    click BlobExporter "https://github.com/monocle2ai/monocle/blob/main/src/monocle_apptrace/exporters/azure/blob_exporter.py"
    click OkahuExporter "https://github.com/monocle2ai/monocle/blob/main/src/monocle_apptrace/exporters/okahu/okahu_exporter.py"
    click ExporterProcessor "https://github.com/monocle2ai/monocle/blob/main/src/monocle_apptrace/exporters/exporter_processor.py"
    
    click LangchainEnt "https://github.com/monocle2ai/monocle/tree/main/src/monocle_apptrace/instrumentation/metamodel/langchain/entities/"
    click LlamaIndexEnt "https://github.com/monocle2ai/monocle/tree/main/src/monocle_apptrace/instrumentation/metamodel/llamaindex/entities/"
    click HaystackEnt "https://github.com/monocle2ai/monocle/tree/main/src/monocle_apptrace/instrumentation/metamodel/haystack/entities/"
    click BotocoreEnt "https://github.com/monocle2ai/monocle/tree/main/src/monocle_apptrace/instrumentation/metamodel/botocore/entities/"
    
    click LangchainHelper "https://github.com/monocle2ai/monocle/blob/main/src/monocle_apptrace/instrumentation/metamodel/langchain/_helper.py"
    click LlamaIndexHelper "https://github.com/monocle2ai/monocle/blob/main/src/monocle_apptrace/instrumentation/metamodel/llamaindex/_helper.py"
    click HaystackHelper "https://github.com/monocle2ai/monocle/blob/main/src/monocle_apptrace/instrumentation/metamodel/haystack/_helper.py"
    click BotocoreHelper "https://github.com/monocle2ai/monocle/blob/main/src/monocle_apptrace/instrumentation/metamodel/botocore/_helper.py"
```
