# abinash123hg/semcache-ai-a-local-semantic-caching-system-for-qwen-powered-llm-applications. architecture

> Architecture diagram of the GitHub repository abinash123hg/semcache-ai-a-local-semantic-caching-system-for-qwen-powered-llm-applications., generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-03). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/abinash123hg/semcache-ai-a-local-semantic-caching-system-for-qwen-powered-llm-applications.
- Repository: https://github.com/abinash123hg/semcache-ai-a-local-semantic-caching-system-for-qwen-powered-llm-applications.

## Overview

SemCache is a local semantic-cache service in front of Ollama. A user submits a question through the browser UI; the API normalizes it, checks the cache using exact and semantic matching, and on a miss generates and stores an answer. The same API exposes cache management, tuning, analytics, model management, streaming, and benchmark features. The main request flow is visible in the README and sampled API code; some benchmark internals and UI sections were not sampled.

Main entry points: [`backend/main.py`](https://github.com/abinash123hg/semcache-ai-a-local-semantic-caching-system-for-qwen-powered-llm-applications./blob/main/backend/main.py) (FastAPI routes), [`backend/cache.py`](https://github.com/abinash123hg/semcache-ai-a-local-semantic-caching-system-for-qwen-powered-llm-applications./blob/main/backend/cache.py) (Cache and analytics), [`backend/benchmark.py`](https://github.com/abinash123hg/semcache-ai-a-local-semantic-caching-system-for-qwen-powered-llm-applications./blob/main/backend/benchmark.py) (Benchmark runner), [`backend/ollama_client.py`](https://github.com/abinash123hg/semcache-ai-a-local-semantic-caching-system-for-qwen-powered-llm-applications./blob/main/backend/ollama_client.py) (Ollama client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_client["Browser client"]
  node_ui["Web UI<br/>[app.js]"]
end

subgraph group_api["API orchestration"]
  node_api_app["FastAPI routes<br/>[main.py]"]
  node_config["Runtime configuration<br/>[config.py]"]
end

subgraph group_cache["Cache and evaluation"]
  node_cache_logic["Cache and analytics<br/>[cache.py]"]
  node_sqlite[("SQLite cache")]
  node_benchmark["Benchmark runner<br/>[benchmark.py]"]
  node_dataset["Benchmark dataset"]
  node_results["Benchmark results"]
end

subgraph group_models["Embedding and models"]
  node_embed["Embedding helpers<br/>[embedding.py]"]
  node_ollama_client["Ollama client<br/>[ollama_client.py]"]
end

node_user(("User"))
node_ollama["Local Ollama"]

node_user -->|"asks question"| node_ui
node_ui -->|"sends requests"| node_api_app
node_api_app -->|"checks and records"| node_cache_logic
node_api_app -->|"embeds questions"| node_embed
node_api_app -->|"generates and checks"| node_ollama_client
node_embed -->|"requests embeddings"| node_ollama_client
node_ollama_client -->|"calls local API"| node_ollama
node_cache_logic -->|"reads and writes"| node_sqlite
node_cache_logic -->|"loads defaults"| node_config
node_api_app -->|"uses settings"| node_config
node_api_app -->|"runs experiments"| node_benchmark
node_benchmark -->|"evaluates pairs"| node_dataset
node_benchmark -->|"stores results"| node_results

click node_ui "https://github.com/abinash123hg/semcache-ai-a-local-semantic-caching-system-for-qwen-powered-llm-applications./blob/main/frontend/app.js"
click node_api_app "https://github.com/abinash123hg/semcache-ai-a-local-semantic-caching-system-for-qwen-powered-llm-applications./blob/main/backend/main.py"
click node_config "https://github.com/abinash123hg/semcache-ai-a-local-semantic-caching-system-for-qwen-powered-llm-applications./blob/main/backend/config.py"
click node_embed "https://github.com/abinash123hg/semcache-ai-a-local-semantic-caching-system-for-qwen-powered-llm-applications./blob/main/backend/embedding.py"
click node_ollama_client "https://github.com/abinash123hg/semcache-ai-a-local-semantic-caching-system-for-qwen-powered-llm-applications./blob/main/backend/ollama_client.py"
click node_cache_logic "https://github.com/abinash123hg/semcache-ai-a-local-semantic-caching-system-for-qwen-powered-llm-applications./blob/main/backend/cache.py"
click node_benchmark "https://github.com/abinash123hg/semcache-ai-a-local-semantic-caching-system-for-qwen-powered-llm-applications./blob/main/backend/benchmark.py"
click node_dataset "https://github.com/abinash123hg/semcache-ai-a-local-semantic-caching-system-for-qwen-powered-llm-applications./blob/main/data/benchmark_dataset.json"
click node_results "https://github.com/abinash123hg/semcache-ai-a-local-semantic-caching-system-for-qwen-powered-llm-applications./tree/main/data/results"

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_ui,node_user toneBlue
class node_api_app,node_config toneAmber
class node_cache_logic,node_sqlite,node_benchmark,node_dataset,node_results toneMint
class node_embed,node_ollama_client toneRose
class node_ollama toneIndigo
```

## Components

### Browser client

- [Web UI](https://github.com/abinash123hg/semcache-ai-a-local-semantic-caching-system-for-qwen-powered-llm-applications./blob/main/frontend/app.js): `frontend/app.js`

### API orchestration

- [FastAPI routes](https://github.com/abinash123hg/semcache-ai-a-local-semantic-caching-system-for-qwen-powered-llm-applications./blob/main/backend/main.py): `backend/main.py`
- [Runtime configuration](https://github.com/abinash123hg/semcache-ai-a-local-semantic-caching-system-for-qwen-powered-llm-applications./blob/main/backend/config.py): `backend/config.py`

### Cache and evaluation

- [Cache and analytics](https://github.com/abinash123hg/semcache-ai-a-local-semantic-caching-system-for-qwen-powered-llm-applications./blob/main/backend/cache.py): `backend/cache.py`
- **SQLite cache**
- [Benchmark runner](https://github.com/abinash123hg/semcache-ai-a-local-semantic-caching-system-for-qwen-powered-llm-applications./blob/main/backend/benchmark.py): `backend/benchmark.py`
- [Benchmark dataset](https://github.com/abinash123hg/semcache-ai-a-local-semantic-caching-system-for-qwen-powered-llm-applications./blob/main/data/benchmark_dataset.json): `data/benchmark_dataset.json`
- [Benchmark results](https://github.com/abinash123hg/semcache-ai-a-local-semantic-caching-system-for-qwen-powered-llm-applications./tree/main/data/results): `data/results`

### Embedding and models

- [Embedding helpers](https://github.com/abinash123hg/semcache-ai-a-local-semantic-caching-system-for-qwen-powered-llm-applications./blob/main/backend/embedding.py): `backend/embedding.py`
- [Ollama client](https://github.com/abinash123hg/semcache-ai-a-local-semantic-caching-system-for-qwen-powered-llm-applications./blob/main/backend/ollama_client.py): `backend/ollama_client.py`

### Other components

- **User**
- **Local Ollama**

## Connections

- User → Web UI: asks question (evidence: `README.md`)
- Web UI → FastAPI routes: sends requests (evidence: `frontend/app.js`)
- FastAPI routes → Cache and analytics: checks and records (evidence: `backend/main.py`)
- FastAPI routes → Embedding helpers: embeds questions (evidence: `backend/main.py`)
- FastAPI routes → Ollama client: generates and checks (evidence: `backend/main.py`)
- Embedding helpers → Ollama client: requests embeddings (evidence: `backend/embedding.py`)
- Ollama client → Local Ollama: calls local API (evidence: `backend/ollama_client.py`)
- Cache and analytics → SQLite cache: reads and writes (evidence: `backend/cache.py`)
- Cache and analytics → Runtime configuration: loads defaults (evidence: `backend/cache.py`)
- FastAPI routes → Runtime configuration: uses settings (evidence: `backend/main.py`)
- FastAPI routes → Benchmark runner: runs experiments (evidence: `backend/main.py`)
- Benchmark runner → Benchmark dataset: evaluates pairs (evidence: `README.md`)
- Benchmark runner → Benchmark results: stores results (evidence: `README.md`)
