# hmeyrakrklnc/foundrylocal architecture

> Architecture diagram of the GitHub repository hmeyrakrklnc/foundrylocal, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-17). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/hmeyrakrklnc/foundrylocal
- Repository: https://github.com/hmeyrakrklnc/foundrylocal

## Overview

This is an offline Turkish RAG assistant. A user submits a question through the chat loop; the app retrieves relevant chunks from local TXT/PDF documents, adds them and recent chat history to a prompted request, then returns a Phi-4 mini response. Document loading, chunking, embedding, persistent Chroma storage and MMR retrieval form the retrieval stages; Foundry Local serves generation. The README also documents the major integrations. Edges follow the shown calls or explicit README descriptions; the generated Chroma directory is not in the supplied tree.

Main entry points: [`main.py`](https://github.com/hmeyrakrklnc/foundrylocal/blob/main/main.py) (Chat loop), [`model.py`](https://github.com/hmeyrakrklnc/foundrylocal/blob/main/model.py) (Foundry wrapper), [`database.py`](https://github.com/hmeyrakrklnc/foundrylocal/blob/main/database.py) (Chroma store), [`data/metin.txt`](https://github.com/hmeyrakrklnc/foundrylocal/blob/main/data/metin.txt) (Local documents)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interaction["Chat interaction"]
  node_chat["Chat loop<br/>[main.py]"]
  node_query_context["Query context<br/>[main.py]"]
  node_chat_memory["Chat memory<br/>[main.py]"]
  node_answer["Assistant answer<br/>[main.py]"]
end

subgraph group_retrieval["Document retrieval"]
  node_source_docs["Local documents<br/>[metin.txt]"]
  node_document_loading["Document loading<br/>[database.py]"]
  node_chunking["Chunking<br/>[database.py]"]
  node_embeddings["Embeddings<br/>[database.py]"]
  node_chroma[("Chroma store<br/>[database.py]")]
  node_retriever["MMR retrieval<br/>[database.py]"]
end

subgraph group_generation["Answer generation"]
  node_prompt["System prompt<br/>[config.py]"]
  node_llm_wrapper["Foundry wrapper<br/>[model.py]"]
  node_endpoint["Endpoint discovery<br/>[model.py]"]
end

node_user(("User"))
node_foundry{{"Foundry Local"}}

node_user -->|"submits question"| node_chat
node_chat -->|"prepares query"| node_query_context
node_chat -->|"reads and updates"| node_chat_memory
node_chat -->|"invokes search"| node_retriever
node_source_docs -->|"loads TXT/PDF"| node_document_loading
node_document_loading -->|"splits documents"| node_chunking
node_chunking -->|"indexes chunks"| node_chroma
node_embeddings -->|"embeds content"| node_chroma
node_chroma -->|"creates retriever"| node_retriever
node_retriever -->|"returns matching chunks"| node_chat
node_chat -->|"uses instructions"| node_prompt
node_chat -->|"invokes model"| node_llm_wrapper
node_llm_wrapper -->|"looks up endpoint"| node_endpoint
node_endpoint -->|"checks server status"| node_foundry
node_llm_wrapper -->|"posts completion request"| node_foundry
node_foundry -->|"returns completion"| node_llm_wrapper
node_llm_wrapper -->|"returns response"| node_answer
node_answer -->|"displays answer"| node_user

click node_chat "https://github.com/hmeyrakrklnc/foundrylocal/blob/main/main.py"
click node_query_context "https://github.com/hmeyrakrklnc/foundrylocal/blob/main/main.py"
click node_chat_memory "https://github.com/hmeyrakrklnc/foundrylocal/blob/main/main.py"
click node_source_docs "https://github.com/hmeyrakrklnc/foundrylocal/blob/main/data/metin.txt"
click node_document_loading "https://github.com/hmeyrakrklnc/foundrylocal/blob/main/database.py"
click node_chunking "https://github.com/hmeyrakrklnc/foundrylocal/blob/main/database.py"
click node_embeddings "https://github.com/hmeyrakrklnc/foundrylocal/blob/main/database.py"
click node_chroma "https://github.com/hmeyrakrklnc/foundrylocal/blob/main/database.py"
click node_retriever "https://github.com/hmeyrakrklnc/foundrylocal/blob/main/database.py"
click node_prompt "https://github.com/hmeyrakrklnc/foundrylocal/blob/main/config.py"
click node_llm_wrapper "https://github.com/hmeyrakrklnc/foundrylocal/blob/main/model.py"
click node_endpoint "https://github.com/hmeyrakrklnc/foundrylocal/blob/main/model.py"
click node_answer "https://github.com/hmeyrakrklnc/foundrylocal/blob/main/main.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_chat,node_query_context,node_chat_memory,node_answer,node_user toneBlue
class node_source_docs,node_document_loading,node_chunking,node_embeddings,node_chroma,node_retriever toneAmber
class node_prompt,node_llm_wrapper,node_endpoint toneMint
class node_foundry toneIndigo
```

## Components

### Chat interaction

- [Chat loop](https://github.com/hmeyrakrklnc/foundrylocal/blob/main/main.py): `main.py`
- [Query context](https://github.com/hmeyrakrklnc/foundrylocal/blob/main/main.py): `main.py`
- [Chat memory](https://github.com/hmeyrakrklnc/foundrylocal/blob/main/main.py): `main.py`
- [Assistant answer](https://github.com/hmeyrakrklnc/foundrylocal/blob/main/main.py): `main.py`

### Document retrieval

- [Local documents](https://github.com/hmeyrakrklnc/foundrylocal/blob/main/data/metin.txt): `data/metin.txt`
- [Document loading](https://github.com/hmeyrakrklnc/foundrylocal/blob/main/database.py): `database.py`
- [Chunking](https://github.com/hmeyrakrklnc/foundrylocal/blob/main/database.py): `database.py`
- [Embeddings](https://github.com/hmeyrakrklnc/foundrylocal/blob/main/database.py): `database.py`
- [Chroma store](https://github.com/hmeyrakrklnc/foundrylocal/blob/main/database.py): `database.py`
- [MMR retrieval](https://github.com/hmeyrakrklnc/foundrylocal/blob/main/database.py): `database.py`

### Answer generation

- [System prompt](https://github.com/hmeyrakrklnc/foundrylocal/blob/main/config.py): `config.py`
- [Foundry wrapper](https://github.com/hmeyrakrklnc/foundrylocal/blob/main/model.py): `model.py`
- [Endpoint discovery](https://github.com/hmeyrakrklnc/foundrylocal/blob/main/model.py): `model.py`

### Other components

- **User**
- **Foundry Local**

## Connections

- User → Chat loop: submits question (evidence: `main.py`)
- Chat loop → Query context: prepares query (evidence: `main.py`)
- Chat loop → Chat memory: reads and updates (evidence: `main.py`)
- Chat loop → MMR retrieval: invokes search (evidence: `main.py`)
- Local documents → Document loading: loads TXT/PDF (evidence: `database.py`)
- Document loading → Chunking: splits documents (evidence: `database.py`)
- Chunking → Chroma store: indexes chunks (evidence: `database.py`)
- Embeddings → Chroma store: embeds content (evidence: `database.py`)
- Chroma store → MMR retrieval: creates retriever (evidence: `database.py`)
- MMR retrieval → Chat loop: returns matching chunks (evidence: `main.py`)
- Chat loop → System prompt: uses instructions (evidence: `main.py`)
- Chat loop → Foundry wrapper: invokes model (evidence: `main.py`)
- Foundry wrapper → Endpoint discovery: looks up endpoint (evidence: `model.py`)
- Endpoint discovery → Foundry Local: checks server status (evidence: `model.py`)
- Foundry wrapper → Foundry Local: posts completion request (evidence: `model.py`)
- Foundry Local → Foundry wrapper: returns completion (evidence: `model.py`)
- Foundry wrapper → Assistant answer: returns response (evidence: `main.py`)
- Assistant answer → User: displays answer (evidence: `main.py`)
