# dev-arctik/langgraph_learning architecture

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

- Interactive diagram: https://gitdiagram.com/dev-arctik/langgraph_learning
- Repository: https://github.com/dev-arctik/langgraph_learning

## Overview

##### Project type and purpose
- This is an open-source learning repository (“LangGraph Learning”) composed of standalone Python scripts demonstrating incremental LangChain graph patterns and techniques (simple graphs, tool graphs, agent graphs, memory patterns, checkpointing, parallelism, etc.).
- Each numbered file (1-SimpleGraph.py through 13-MemoryBetweenThreads.py) is a self-contained example; there’s a utility module for image generation, a config directory for API keys, and GraphImages for outputs.

##### File structure
- Top-level example scripts: 1-*.py … 13-*.py
- config/secret_keys.py holds API key placeholders loaded at runtime via a `.env` file
- utils/graph_img_generation.py encapsulates common logic to render or save graph visuals
- GraphImages/ stores generated graph images
- requirements.txt lists dependencies (LangChain, OpenAI, pymongo or motor, etc.)

##### Main architectural components
a. Example-Graph Runner Layer (“Scripts”)
- Each numbered file imports config, utils, LangChain constructs, and external services
b. Configuration Layer
- secret_keys.py (reads `.env` via python-dotenv)
c. Graph Utilities Layer
- graph_img_generation.py
d. External Services
- OpenAI API (via LangChain LLM wrappers)
- LangSmith tracing endpoint
- Tavily API
- MongoDB (synchronous or async) for checkpointing
e. Output/Storage
- GraphImages directory for PNG/SVG outputs
- MongoDB collections for state persistence

##### Relationships and interactions
- Each Script → loads API keys from Config
- Script → initializes a LangChain Graph or Agent
- Script ↔ External LLM services (OpenAI, optional Tavily)
- Script → (optional) LangSmith tracing endpoint for experiment telemetry
- Some scripts → MongoDBCheckpointer (sync or async) for saving graph runs
- Script → utils.graph_img_generation to render graph structure → writes to GraphImages/

##### Architectural patterns and principles
- Modular example approach: each file is an independent use case
- Separation of concerns: config isolated from code; rendering utility factored out
- Optional persistence layer via checkpointers abstracts database interaction
- Concurrency patterns demonstrated (thread-based memory, async checkpointing)
- Extensibility: new graph examples can be added by following the numbered naming convention

##### Technologies, frameworks, and libraries
- Python 3
- LangChain and its Graph API
- OpenAI Python SDK / Tavily
- python-dotenv for configuration
- pymongo / motor for MongoDB
- graphviz or networkx in graph_img_generation (depending on implementation)

- Clear, human-readable labels for each component (“1-SimpleGraph.py,” “config/secret_keys.py,” “MongoDB”)

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Runner Scripts Layer
    subgraph "Runner Scripts" 
        direction TB
        SG1["1-SimpleGraph.py"]:::scripts
        SG2["2-ToolGraph.py"]:::scripts
        SG3["3-AgentGraph.py"]:::scripts
        SG4["4-AgentGraph_withMemory.py"]:::scripts
        SG5["5-SummaryInputGraph.py"]:::scripts
        SG6["6-BreakpointGraph.py"]:::scripts
        SG7["7-EditBreakpointGraph.py"]:::scripts
        SG8["8-ParallelWebSearchGraph.py"]:::scripts
        SG9["9-StreamingChatGraph.py"]:::scripts
        SG10["10-MongoDBCheckpointer.py"]:::scripts
        SG11["11-AsynMongoDBCheckpointer.py"]:::scripts
        SG13["13-MemoryBetweenThreads.py"]:::scripts
        SGNew["New Example N+1"]:::scripts
    end

    %% Configuration Layer
    subgraph "Configuration" 
        direction TB
        Config["config/secret_keys.py"]:::config
    end

    %% Utilities Layer
    subgraph "Graph Utilities" 
        direction TB
        Utils["utils/graph_img_generation.py"]:::utils
    end

    %% External Services and Persistence Layer
    subgraph "External Services & Persistence"
        direction TB
        OpenAI["OpenAI API"]:::external
        Tavily["Tavily API"]:::external
        LangSmith["LangSmith Tracing"]:::external
        MongoDB["MongoDB"]:::storage
    end

    %% Output Storage Layer
    subgraph "Output / Storage"
        direction TB
        Images["GraphImages/"]:::storage
    end

    %% Connections from each script
    SG1 -->|"load config"| Config
    SG2 -->|"load config"| Config
    SG3 -->|"load config"| Config
    SG4 -->|"load config"| Config
    SG5 -->|"load config"| Config
    SG6 -->|"load config"| Config
    SG7 -->|"load config"| Config
    SG8 -->|"load config"| Config
    SG9 -->|"load config"| Config
    SG10 -->|"load config"| Config
    SG11 -->|"load config"| Config
    SG13 -->|"load config"| Config
    SGNew -->|"load config"| Config

    SG1 -->|"call LLM"| OpenAI
    SG2 -->|"call LLM"| OpenAI
    SG3 -->|"call LLM"| OpenAI
    SG4 -->|"call LLM"| OpenAI
    SG5 -->|"call LLM"| OpenAI
    SG6 -->|"call LLM"| OpenAI
    SG7 -->|"call LLM"| OpenAI
    SG8 -->|"call LLM"| OpenAI
    SG9 -->|"call LLM"| OpenAI
    SG10 -->|"call LLM"| OpenAI
    SG11 -->|"call LLM"| OpenAI
    SG13 -->|"call LLM"| OpenAI
    SGNew -->|"call LLM"| OpenAI

    SG1 -->|"optional trace"| LangSmith
    SG2 -->|"optional trace"| LangSmith
    SG3 -->|"optional trace"| LangSmith
    SG4 -->|"optional trace"| LangSmith
    SG5 -->|"optional trace"| LangSmith
    SG6 -->|"optional trace"| LangSmith
    SG7 -->|"optional trace"| LangSmith
    SG8 -->|"optional trace"| LangSmith
    SG9 -->|"optional trace"| LangSmith
    SG10 -->|"optional trace"| LangSmith
    SG11 -->|"optional trace"| LangSmith
    SG13 -->|"optional trace"| LangSmith
    SGNew -->|"optional trace"| LangSmith

    SG1 -->|"render graph"| Utils
    SG2 -->|"render graph"| Utils
    SG3 -->|"render graph"| Utils
    SG4 -->|"render graph"| Utils
    SG5 -->|"render graph"| Utils
    SG6 -->|"render graph"| Utils
    SG7 -->|"render graph"| Utils
    SG8 -->|"render graph"| Utils
    SG9 -->|"render graph"| Utils
    SG10 -->|"render graph"| Utils
    SG11 -->|"render graph"| Utils
    SG13 -->|"render graph"| Utils
    SGNew -->|"render graph"| Utils

    SG1 -->|"save image"| Images
    SG2 -->|"save image"| Images
    SG3 -->|"save image"| Images
    SG4 -->|"save image"| Images
    SG5 -->|"save image"| Images
    SG6 -->|"save image"| Images
    SG7 -->|"save image"| Images
    SG8 -->|"save image"| Images
    SG9 -->|"save image"| Images
    SG10 -->|"save image"| Images
    SG11 -->|"save image"| Images
    SG13 -->|"save image"| Images
    SGNew -->|"save image"| Images

    %% MongoDB checkpoint bidirectional for checkpointer scripts
    SG10 -->|"save checkpoint"| MongoDB
    MongoDB -->|"load checkpoint"| SG10
    SG11 -->|"save checkpoint"| MongoDB
    MongoDB -->|"load checkpoint"| SG11

    %% Click Events
    click SG1 "https://github.com/dev-arctik/langgraph_learning/blob/master/1-SimpleGraph.py"
    click SG2 "https://github.com/dev-arctik/langgraph_learning/blob/master/2-ToolGraph.py"
    click SG3 "https://github.com/dev-arctik/langgraph_learning/blob/master/3-AgentGraph.py"
    click SG4 "https://github.com/dev-arctik/langgraph_learning/blob/master/4-AgentGraph_withMemory.py"
    click SG5 "https://github.com/dev-arctik/langgraph_learning/blob/master/5-SummaryInputGraph.py"
    click SG6 "https://github.com/dev-arctik/langgraph_learning/blob/master/6-BreakpointGraph.py"
    click SG7 "https://github.com/dev-arctik/langgraph_learning/blob/master/7-EditBreakpointGraph.py"
    click SG8 "https://github.com/dev-arctik/langgraph_learning/blob/master/8-ParallelWebSearchGraph.py"
    click SG9 "https://github.com/dev-arctik/langgraph_learning/blob/master/9-StreamingChatGraph.py"
    click SG10 "https://github.com/dev-arctik/langgraph_learning/blob/master/10-MongoDBCheckpointer.py"
    click SG11 "https://github.com/dev-arctik/langgraph_learning/blob/master/11-AsynMongoDBCheckpointer.py"
    click SG13 "https://github.com/dev-arctik/langgraph_learning/blob/master/13-MemoryBetweenThreads.py"
    click Config "https://github.com/dev-arctik/langgraph_learning/blob/master/config/secret_keys.py"
    click Utils "https://github.com/dev-arctik/langgraph_learning/blob/master/utils/graph_img_generation.py"
    click Images "https://github.com/dev-arctik/langgraph_learning/tree/master/GraphImages/"

    %% Styles
    classDef scripts fill:#D0E8FF,stroke:#0366d6,stroke-width:1px;
    classDef config fill:#DFFFE0,stroke:#228B22,stroke-width:1px;
    classDef utils fill:#E8D0FF,stroke:#6A0Dad,stroke-width:1px;
    classDef external fill:#FFE8B0,stroke:#FF8C00,stroke-width:1px;
    classDef storage fill:#FFF5D0,stroke:#DAA520,stroke-width:1px;
```
