# langchain4j/langchain4j-examples architecture

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

- Interactive diagram: https://gitdiagram.com/langchain4j/langchain4j-examples
- Repository: https://github.com/langchain4j/langchain4j-examples

## Overview

##### Project type and purpose
- This is a Maven “multi-module” examples repository for LangChain4j.
- At the root you have an aggregator POM (`pom.xml`) and dozens of child modules (e.g., `spring-boot-example`, `azure-open-ai-examples`, `rag-examples`, `customer-support-agent-example`, etc.).
- Each module is a self-contained demo showing how to integrate LLMs, RAG, tools, memory, streaming, vector stores and/or frameworks (Spring Boot, Quarkus, Helidon, Jakarta EE, Wildfly, JavaFX, CLI, etc.) with the LangChain4j library.

##### File structure
- Top-level aggregator POM references all the example modules.
- Each module has its own `pom.xml`, `src/main/java`, `src/main/resources`, and often `src/test`.
- Some modules are pure Java CLIs (e.g., `tutorials`, `other-examples`, `open-ai-examples`), others are full-fledged microservices or web apps (e.g., `spring-boot-example`, `customer-support-agent-example`, Helidon/Quarkus/Wildfly examples).
- Provider-specific demos (`azure-*`, `open-ai-examples`, `vertex-ai-gemini-examples`, `mistral-ai-examples`, etc.)
- Vector store demos (`redis-example`, `chroma-example`, `pinecone-example`, etc.)
- Framework demos (`spring-boot-example`, `quarkus-example`, `helidon-examples`, `jakartaee-microprofile-example`, `wildfly-example`)
- Core LLM/RAG/memory/tutorial demos (`tutorials`, `rag-examples`, `other-examples`, `customer-support-agent-example`).

##### Extract insights from the README
- It points to tutorials, other-examples, rag-examples, and the customer-support-agent-example as good starting points.

A. Root-level multi-module structure
– LLM provider demos
– Vector store demos
– Framework demos
– Core feature demos (RAG, tutorials, multi-tool agent)

B. Drill-down into a representative module (e.g., customer-support-agent-example)
- Components:
1. Client (e.g., HTTP REST or CLI)
2. Spring Boot Application
3. REST Controller (`CustomerSupportAgentController`)
4. Agent orchestration class (`CustomerSupportAgent`)
5. Tool adapters (`BookingTools`)
6. Domain service (`BookingService`, `Customer` model)
7. LangChain4j Core (Chains, Prompts, Memory)
8. External LLM API (Azure OpenAI, OpenAI, etc.)
- Data stores: in-memory or optionally an external DB/vector store for RAG (if present).
– Client → Controller (HTTP request)
– Controller → Agent orchestration → Chain steps → LLM API
– Agent calls Tool adapters → Domain service → Data store
– Chain returns text/stream → Controller → Client

C. Show common architectural patterns
- Microservice-style modules: illustrate the web framework, DI container, REST interface.
- CLI-style modules: illustrate simple Java `main()` invoking LangChain4j chains and printing to console.
- RAG pattern: show document loader → vector store → retriever → chain → LLM.
- Memory pattern: show in-memory or persistent memory store.
- Tooling pattern: show function-calling interfaces with JSON schemas.

D. Technologies & libraries
- Maven (multi-module)
- Java 17+
- LangChain4j core (chains, prompts, memory, tools)
- HTTP clients (OkHttp, WebClient)
- Frameworks: Spring Boot, Quarkus, Helidon MP/SE, Jakarta EE, Wildfly, JavaFX
- Vector stores: Redis, Milvus, Pinecone, Qdrant, Chroma, Couchbase, Infinispan, Neo4j, ElasticSearch, OpenSearch, PgVector, Vespa, Weaviate
- LLM providers: OpenAI, Azure OpenAI, Anthropic, Bedrock, Google Gemini, Ollama, Mistral, OVH.ai, Vertex AI, Voyage.ai

##### Detail without over-splitting
- Essential layers: project structure, frameworks, chain orchestration, tools, memory, storage, external provider interactions.
- Avoid drawing every single example; focus on grouping modules and fully detailing 1–2 representative flows.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Root POM
    RootPOM["langchain4j-examples (aggregator POM)"]:::root

    %% Provider-specific demos
    subgraph "Provider-specific demos"
        A1["azure-open-ai-examples"]:::module
        A2["open-ai-examples"]:::module
        A3["anthropic-examples"]:::module
        A4["mistral-ai-examples"]:::module
    end

    %% Vector store demos
    subgraph "Vector store demos"
        V1["redis-example"]:::module
        V2["pinecone-example"]:::module
        V3["chroma-example"]:::module
    end

    %% Framework demos
    subgraph "Framework demos"
        F1["spring-boot-example"]:::module
        F2["quarkus-example"]:::module
        F3["helidon-examples/coffee-shop-assistant-mp"]:::module
        F4["jakartaee-microprofile-example"]:::module
        F5["wildfly-example"]:::module
    end

    %% Core feature demos
    subgraph "Core feature demos"
        C1["tutorials"]:::module
        C2["rag-examples"]:::module
        C3["other-examples"]:::module
        C4["customer-support-agent-example"]:::module
    end

    %% Connections from Root
    RootPOM --> A1
    RootPOM --> A2
    RootPOM --> A3
    RootPOM --> A4
    RootPOM --> V1
    RootPOM --> V2
    RootPOM --> V3
    RootPOM --> F1
    RootPOM --> F2
    RootPOM --> F3
    RootPOM --> F4
    RootPOM --> F5
    RootPOM --> C1
    RootPOM --> C2
    RootPOM --> C3
    RootPOM --> C4

    %% Drill-down: Customer Support Agent Example
    subgraph "Customer Support Agent Example"
        Client["Client (HTTP/CLI)"]:::external
        Controller["CustomerSupportAgentController"]:::service
        Agent["CustomerSupportAgent (Orchestration)"]:::core
        Tools["BookingTools"]:::core
        Service["BookingService"]:::service
        Models["Domain Models"]:::service
        Core["LangChain4j Core\n(Chains, Prompts, Memory)"]:::core
        LLM["External LLM API"]:::external
        Store["Data Store (in-memory/DB)"]:::external
    end

    %% Drill-down connections
    Client -->|"HTTP request"| Controller
    Controller -->|"invoke agent"| Agent
    Agent -->|"run chain"| Core
    Core -->|"calls"| LLM
    Agent -->|"use tools"| Tools
    Tools -->|"invoke service"| Service
    Service -->|"read/write"| Store
    Core -->|"response"| Controller
    Controller -->|"HTTP response"| Client

    %% Click Events
    click RootPOM "https://github.com/langchain4j/langchain4j-examples/blob/main/pom.xml"
    click A1 "https://github.com/langchain4j/langchain4j-examples/blob/main/azure-open-ai-examples/pom.xml"
    click A2 "https://github.com/langchain4j/langchain4j-examples/blob/main/open-ai-examples/pom.xml"
    click A3 "https://github.com/langchain4j/langchain4j-examples/blob/main/anthropic-examples/pom.xml"
    click A4 "https://github.com/langchain4j/langchain4j-examples/blob/main/mistral-ai-examples/pom.xml"
    click V1 "https://github.com/langchain4j/langchain4j-examples/blob/main/redis-example/pom.xml"
    click V2 "https://github.com/langchain4j/langchain4j-examples/blob/main/pinecone-example/pom.xml"
    click V3 "https://github.com/langchain4j/langchain4j-examples/blob/main/chroma-example/pom.xml"
    click F1 "https://github.com/langchain4j/langchain4j-examples/blob/main/spring-boot-example/pom.xml"
    click F2 "https://github.com/langchain4j/langchain4j-examples/blob/main/quarkus-example/pom.xml"
    click F3 "https://github.com/langchain4j/langchain4j-examples/blob/main/helidon-examples/coffee-shop-assistant-mp/pom.xml"
    click F4 "https://github.com/langchain4j/langchain4j-examples/blob/main/jakartaee-microprofile-example/pom.xml"
    click F5 "https://github.com/langchain4j/langchain4j-examples/blob/main/wildfly-example/pom.xml"
    click C1 "https://github.com/langchain4j/langchain4j-examples/blob/main/tutorials/pom.xml"
    click C2 "https://github.com/langchain4j/langchain4j-examples/blob/main/rag-examples/pom.xml"
    click C3 "https://github.com/langchain4j/langchain4j-examples/blob/main/other-examples/pom.xml"
    click C4 "https://github.com/langchain4j/langchain4j-examples/blob/main/customer-support-agent-example/pom.xml"
    click Controller "https://github.com/langchain4j/langchain4j-examples/blob/main/customer-support-agent-example/src/main/java/dev/langchain4j/example/CustomerSupportAgentController.java"
    click Agent "https://github.com/langchain4j/langchain4j-examples/blob/main/customer-support-agent-example/src/main/java/dev/langchain4j/example/CustomerSupportAgent.java"
    click Tools "https://github.com/langchain4j/langchain4j-examples/blob/main/customer-support-agent-example/src/main/java/dev/langchain4j/example/BookingTools.java"
    click Service "https://github.com/langchain4j/langchain4j-examples/blob/main/customer-support-agent-example/src/main/java/dev/langchain4j/example/booking/BookingService.java"
    click Models "https://github.com/langchain4j/langchain4j-examples/tree/main/customer-support-agent-example/src/main/java/dev/langchain4j/example/booking"
    click Core "https://github.com/langchain4j/langchain4j-examples/blob/main/customer-support-agent-example/src/main/java/dev/langchain4j/example/CustomerSupportAgentApplication.java"

    %% Styles
    classDef root fill:#f9f,stroke:#333,stroke-width:2px
    classDef module fill:#ccf,stroke:#333
    classDef service fill:#cfc,stroke:#333
    classDef core fill:#fcf,stroke:#333
    classDef external fill:#ffc,stroke:#333,stroke-dasharray: 5 5
```
