# hdz65/ai-server architecture

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

- Interactive diagram: https://gitdiagram.com/hdz65/ai-server
- Repository: https://github.com/hdz65/ai-server

## Overview

##### Project type and purpose
- This is a NestJS–based backend “AI server” that exposes HTTP endpoints, integrates with an Ollama LLM process, and performs Retrieval-Augmented Generation (RAG) using an embeddings store and markdown utilities.

##### File structure
- Top‐level files: Nest config (nest-cli.json, tsconfig.json), lint/prettier, package.json.
- src/main.ts boots the Nest application.
- src/app.*: global AppModule, AppController & AppService (example “health check” or root endpoint).
- src/ollama: OllamaModule, OllamaController (exposes LLM endpoints), OllamaService (invokes the Ollama binary/HTTP API).
- src/rag: rag/embeddings.store.ts (manages vector store of embeddings), rag/markdown.ts (prepares docs for RAG pipeline).
- src/utils: md.ts (shared markdown parsing/utility functions).
- test/: E2E tests for API.

##### Detailed breakdown to capture essential elements
→ sends → External: Ollama LLM Server
← receives text ←
← receives vectors ←
← receives raw markdown ←
- (Optionally) show Test Suite hitting endpoints via Nest TestingModule

## Diagram (Mermaid)

```mermaid
flowchart TD
    Client["Client (HTTP)"]:::external
    TestSuite["E2E Test Suite"]:::test

    subgraph "NestJS API Layer"
        direction TB
        Bootstrap["Bootstrap\n(main.ts)"]:::bootstrap
        AppModule["AppModule"]:::module
        AppController["AppController"]:::controller
        AppService["AppService"]:::service
        OllamaModule["OllamaModule"]:::module
        OllamaController["OllamaController"]:::controller
        OllamaService["OllamaService"]:::service
    end

    subgraph "RAG Layer"
        direction TB
        EmbeddingsStore["EmbeddingsStore"]:::storage
        MarkdownRAG["Markdown (rag)"]:::util
        SharedMD["Shared Markdown Utils"]:::util
    end

    subgraph "External Systems"
        direction TB
        LLMServer["Ollama LLM Server"]:::external
    end

    Client -->|"/"| AppController
    AppController --> AppService
    AppService -->|bootstrap| Pompty[ ] 
    Bootstrap --> AppModule
    AppModule --> AppController
    AppModule --> OllamaModule
    OllamaModule --> OllamaController
    OllamaModule --> OllamaService
    OllamaController --> OllamaService
    OllamaService --> EmbeddingsStore
    OllamaService --> MarkdownRAG
    MarkdownRAG --> SharedMD
    OllamaService -->|generate| LLMServer
    LLMServer -->|response| OllamaService
    OllamaService --> OllamaController
    OllamaController --> Client
    TestSuite -->|tests| AppModule

    click Bootstrap "https://github.com/hdz65/ai-server/blob/main/src/main.ts"
    click AppModule "https://github.com/hdz65/ai-server/blob/main/src/app.module.ts"
    click AppController "https://github.com/hdz65/ai-server/blob/main/src/app.controller.ts"
    click AppService "https://github.com/hdz65/ai-server/blob/main/src/app.service.ts"
    click OllamaModule "https://github.com/hdz65/ai-server/blob/main/src/ollama/ollama.module.ts"
    click OllamaController "https://github.com/hdz65/ai-server/blob/main/src/ollama/ollama.controller.ts"
    click OllamaService "https://github.com/hdz65/ai-server/blob/main/src/ollama/ollama.service.ts"
    click EmbeddingsStore "https://github.com/hdz65/ai-server/blob/main/src/rag/embeddings.store.ts"
    click MarkdownRAG "https://github.com/hdz65/ai-server/blob/main/src/rag/markdown.ts"
    click SharedMD "https://github.com/hdz65/ai-server/blob/main/src/utils/md.ts"
    click TestSuite "https://github.com/hdz65/ai-server/blob/main/test/app.e2e-spec.ts"

    classDef module fill:#DDEEFF,stroke:#333,stroke-width:1px
    classDef controller fill:#BBCCFF,stroke:#333
    classDef service fill:#AACCEE,stroke:#333
    classDef util fill:#CCFFCC,stroke:#333
    classDef storage fill:#FFE0B2,stroke:#333,stroke-width:1px
    classDef external fill:#FFCC99,stroke:#333
    classDef bootstrap fill:#CCCCFF,stroke:#333
    classDef test fill:#FFDDDD,stroke:#333
```
