# aadityauohyd/springboot-ai-rag-ollama-demo architecture

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

- Interactive diagram: https://gitdiagram.com/aadityauohyd/springboot-ai-rag-ollama-demo
- Repository: https://github.com/aadityauohyd/springboot-ai-rag-ollama-demo

## Overview

##### Main Components
- Frontend/API Layer: Although this project does not include a typical client-side UI, the REST API endpoint (handled by ChatController) serves as the primary interface for users.
- Application Core & Business Logic: The Spring Boot application as a whole, emphasizing the RAG implementation. Key subcomponents include:
- ChatController (REST API endpoints for interactions).
- DocumentIngestionService (ingests and processes the Spring Boot PDF documentation using Apache Tika and text splitting).
- External Service Integration (LLM):
- Ollama: Provides the language model (deepseek-r1:8b) running on http://localhost:11434.
- Data Storage Layer:
- PGVector Database: A PostgreSQL database enhanced with PGVector to store and retrieve vector embeddings.
- Supporting Components:
- Maven build configuration (pom.xml, maven wrapper).
- Docker Compose (compose.yml) for running the PGVector-enabled PostgreSQL container.

##### Relationships and Interactions
- REST API Requests: Clients send HTTP requests to the ChatController, which parses and forwards the requests to the RAG processing pipeline.
- RAG Pipeline Interaction:
- ChatController interacts with the DocumentIngestionService, which handles document parsing (using Apache Tika), text splitting, and vector embedding creation.
- Integration with Ollama:
- Data Storage:
- Docker Container:
- A note for the Docker Compose orchestration that runs the PGVector-enabled database.

##### Architectural Patterns and Design Principles
- Layered Architecture: Separate layers include the REST controller, service layer (business logic & document ingestion), integration adapters (to Ollama and PGVector), and supporting configuration (application.properties).
- Modular Design: The project structure hints at clear separation of concerns (API handling vs. ingestion vs. testing) which should be clearly represented.
- Microservice/Integration Style: Although this is a monolithic Spring Boot application, the distinct external dependencies (Ollama, PGVector) should be shown as separate services.

##### Relevant Technologies
- Java 21 and Spring Boot 3.4.3 as the core framework.
- Maven as the build and dependency management tool.
- PGVector and PostgreSQL (with container management via Docker Compose).
- Apache Tika for PDF ingestion.
- Ollama for LLM functionality (model deepseek-r1:8b).
- Spring AI for RAG implementation.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Request
    Client["User Request"]:::client

    %% Frontend / API Layer
    subgraph "Frontend / API Layer"
        ChatCtrl["ChatController (REST API)"]:::api
    end

    %% Application Core & Business Logic
    subgraph "Application Core & Business Logic"
        AppEntry["Spring Boot Application Entry Point"]:::service
        DocIngest["DocumentIngestionService (Document Ingestion & Processing)"]:::service
    end

    %% External Services
    subgraph "External Services"
        LLM["Ollama LLM [deepseek-r1:8b]"]:::external
        PGVector["PGVector Database"]:::database
    end

    %% Supporting Infrastructure
    subgraph "Supporting Infrastructure"
        Maven["Maven Build Configuration"]:::support
        Docker["Docker Compose (PGVector Container)"]:::support
    end

    %% Connections
    Client -->|"sends request"| ChatCtrl
    ChatCtrl -->|"calls"| DocIngest
    DocIngest -->|"LLM_query"| LLM
    DocIngest -->|"vector_storage"| PGVector
    Maven -->|"builds"| AppEntry
    Docker -->|"orchestrates"| PGVector

    %% Click Events
    click ChatCtrl "https://github.com/aadityauohyd/springboot-ai-rag-ollama-demo/blob/main/src/main/java/org/aadi/springboot/ai/rag/ChatController.java"
    click DocIngest "https://github.com/aadityauohyd/springboot-ai-rag-ollama-demo/blob/main/src/main/java/org/aadi/springboot/ai/rag/ingestion/DocumentIngestionService.java"
    click AppEntry "https://github.com/aadityauohyd/springboot-ai-rag-ollama-demo/blob/main/src/main/java/org/aadi/springboot/ai/rag/SpringbootAiRagOllamaDemoApplication.java"
    click Maven "https://github.com/aadityauohyd/springboot-ai-rag-ollama-demo/blob/main/pom.xml"
    click Docker "https://github.com/aadityauohyd/springboot-ai-rag-ollama-demo/blob/main/compose.yml"

    %% Class Definitions
    classDef client fill:#FDEBD0,stroke:#333,stroke-width:1px;
    classDef api fill:#C3E88D,stroke:#333,stroke-width:1px;
    classDef service fill:#82AAFF,stroke:#333,stroke-width:1px;
    classDef external fill:#F07178,stroke:#333,stroke-width:1px;
    classDef database fill:#FFCB6B,stroke:#333,stroke-width:1px;
    classDef support fill:#C792EA,stroke:#333,stroke-width:1px;
```
