# spring-projects/spring-ai-examples architecture

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

- Interactive diagram: https://gitdiagram.com/spring-projects/spring-ai-examples
- Repository: https://github.com/spring-projects/spring-ai-examples

## Overview

##### Project’s Nature and Purpose
- This repository is a collection of example projects – all built around Spring (and related frameworks) with an emphasis on AI integration, agentic patterns, and demonstrating various architectural patterns using both Java and Kotlin.
- The examples cover multiple aspects such as agent workflows (chain, evaluator/optimizer, orchestrator, routing, parallelization), client–server interaction, function callbacks (in Kotlin), and even database-backed examples (e.g., SQLite-based projects in model-context-protocol). In essence, it’s a “kitchen sink” of Spring AI examples meant to illustrate different design patterns and integrations.

##### File Structure
- The top-level directories (agentic-patterns, agents, kotlin, model-context-protocol, misc, models) indicate that projects are grouped by theme or design pattern.
- Under “agentic-patterns” you have submodules like “chain-workflow”, “evaluator-optimizer”, “orchestrator-workers”, “parallelization-worflow”, and “routing-workflow”. These likely encapsulate different agent-based workflows.
- The “agents/reflection” module shows a separate example demonstrating reflective or AI agent behaviors.
- The “kotlin” folder contains various Kotlin-based projects that illustrate different functionalities – one showing function callbacks, another a simple “hello world”, and one with a more complex rag-based (retrieval augmented generation) example.
- The “model-context-protocol” directory is particularly rich with multiple submodules (e.g., brave, client-starter, filesystem, sampling, weather, web-search) and appears to be a suite of protocols and integration examples that can serve as client–server or microservice examples. Notice that each has its own Maven structure with individual “pom.xml” files.
- Under “misc” there are additional examples (like the openai-streaming-response and spring-ai-java-function-callback) focusing on specific use cases.
- Finally, the “models” folder (e.g., chat/helloworld) hosts another set of examples, likely centering on AI model interactions.

##### Specific Elements
- Annotations to indicate which modules use Spring Boot, what type of architectural pattern they demonstrate (e.g., microservice, workflow orchestration), and what integration technologies are employed (Maven for build, various configuration files, etc.).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Central Common Library Node
    Common["Spring AI Common Library<br/>(Spring Boot, Maven)"]:::common

    %% Agentic Patterns Subgraph
    subgraph "Agentic Patterns"
        AP_CONTAINER["Agentic Patterns"]:::java
        AP1["Chain Workflow"]:::java
        AP2["Evaluator Optimizer"]:::java
        AP3["Orchestrator Workers"]:::java
        AP4["Parallelization Workflow"]:::java
        AP5["Routing Workflow"]:::java
        AP_CONTAINER --> AP1
        AP_CONTAINER --> AP2
        AP_CONTAINER --> AP3
        AP_CONTAINER --> AP4
        AP_CONTAINER --> AP5
    end

    %% Agents – Reflection Subgraph
    subgraph "Agents – Reflection"
        AR_CONTAINER["Agents – Reflection"]:::java
    end

    %% Kotlin Examples Subgraph
    subgraph "Kotlin Examples"
        KE_CONTAINER["Kotlin Examples"]:::kotlin
        KE1["Kotlin Function Callback"]:::kotlin
        KE2["Kotlin Hello World"]:::kotlin
        KE3["RAG with Kotlin"]:::kotlin
        KE_CONTAINER --> KE1
        KE_CONTAINER --> KE2
        KE_CONTAINER --> KE3
    end

    %% Model Context Protocol Subgraph
    subgraph "Model Context Protocol"
        MCP_CONTAINER["Model Context Protocol"]:::protocol
        MCP1["Brave Module"]:::protocol
        MCP2["Client Starter"]:::protocol
        MCP3["Filesystem"]:::protocol
        MCP4["Sampling"]:::protocol
        MCP5["Weather"]:::protocol
        MCP6["SQLite Example"]:::protocol
        MCP7["Web Search"]:::protocol
        MCP_CONTAINER --> MCP1
        MCP_CONTAINER --> MCP2
        MCP_CONTAINER --> MCP3
        MCP_CONTAINER --> MCP4
        MCP_CONTAINER --> MCP5
        MCP_CONTAINER --> MCP6
        MCP_CONTAINER --> MCP7
    end

    %% Miscellaneous Examples Subgraph
    subgraph "Miscellaneous Examples"
        MISC_CONTAINER["Miscellaneous Examples"]:::misc
        MISC1["OpenAI Streaming Response"]:::misc
        MISC2["Spring AI Java Function Callback"]:::misc
        MISC_CONTAINER --> MISC1
        MISC_CONTAINER --> MISC2
    end

    %% Models – Chat Subgraph
    subgraph "Models – Chat"
        MC_CONTAINER["Models – Chat"]:::model
        MC["Chat HelloWorld"]:::model
        MC_CONTAINER --> MC
    end

    %% Connections from container nodes to Common Library
    AP_CONTAINER --> Common
    AR_CONTAINER --> Common
    KE_CONTAINER --> Common
    MCP_CONTAINER --> Common
    MISC_CONTAINER --> Common
    MC_CONTAINER --> Common

    %% Additional inter-module interactions
    MCP2 -->|"uses"| AR_CONTAINER
    KE3 -->|"integrates"| MC

    %% Click Events for component mapping
    click AP_CONTAINER "https://github.com/spring-projects/spring-ai-examples/tree/main/agentic-patterns"
    click AR_CONTAINER "https://github.com/spring-projects/spring-ai-examples/tree/main/agents/reflection"
    click KE_CONTAINER "https://github.com/spring-projects/spring-ai-examples/tree/main/kotlin"
    click MCP_CONTAINER "https://github.com/spring-projects/spring-ai-examples/tree/main/model-context-protocol"
    click MISC_CONTAINER "https://github.com/spring-projects/spring-ai-examples/tree/main/misc"
    click MC_CONTAINER "https://github.com/spring-projects/spring-ai-examples/tree/main/models/chat/helloworld"

    %% Styles
    classDef java fill:#AED6F1,stroke:#1B4F72,stroke-width:2px;
    classDef kotlin fill:#A9DFBF,stroke:#1D8348,stroke-width:2px;
    classDef protocol fill:#F9E79F,stroke:#B7950B,stroke-width:2px;
    classDef misc fill:#F5B7B1,stroke:#922B21,stroke-width:2px;
    classDef model fill:#D2B4DE,stroke:#6C3483,stroke-width:2px;
    classDef common fill:#D5DBDB,stroke:#7D7D7D,stroke-width:2px;
```
