# krishnnavarun/modelmux architecture

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

- Interactive diagram: https://gitdiagram.com/krishnnavarun/modelmux
- Repository: https://github.com/krishnnavarun/modelmux

## Overview

ModelMux is an inference-routing service: an application submits a prompt, the API checks the semantic cache, classifies misses, dispatches them through resilient provider adapters, and records the outcome. The README also documents operational metrics and a live dashboard. The graph preserves those product branches; unsampled configuration and storage wiring is shown only where the API excerpt or README supports it.

Main entry points: [`app/main.py`](https://github.com/krishnnavarun/modelmux/blob/main/app/main.py) (Chat API), [`app/providers/base.py`](https://github.com/krishnnavarun/modelmux/blob/main/app/providers/base.py) (Provider contract), [`app/providers/__init__.py`](https://github.com/krishnnavarun/modelmux/blob/main/app/providers/__init__.py) (Provider registry), [`app/classifier/heuristic.py`](https://github.com/krishnnavarun/modelmux/blob/main/app/classifier/heuristic.py) (Complexity classifier)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_request["Request handling"]
  node_api["Chat API<br/>[main.py]"]
  node_cache[("Semantic cache<br/>[cache.py]")]
end

subgraph group_routing["Classification and routing"]
  node_classifier["Complexity classifier<br/>[heuristic.py]"]
  node_signals["Complexity signals<br/>[signals.py]"]
  node_embeddings["Embedding classifier<br/>[embedding.py]"]
  node_tokenizer["Token counting<br/>[tokens.py]"]
  node_router["Tier selection<br/>[router.py]"]
end

subgraph group_providers["Provider dispatch"]
  node_resilience["Retry and circuits<br/>[resilience.py]"]
  node_registry["Provider registry<br/>[__init__.py]"]
  node_provider_contract["Provider contract<br/>[base.py]"]
  node_groq["Groq adapter<br/>[groq.py]"]
  node_google["Google adapter<br/>[google.py]"]
  node_anthropic["Anthropic adapter<br/>[anthropic.py]"]
  node_mock["Mock adapter<br/>[mock.py]"]
end

subgraph group_operations["State and operations"]
  node_config["Runtime configuration<br/>[config.py]"]
  node_database[("Request records<br/>[db.py]")]
  node_metrics["Usage metrics<br/>[metrics.py]"]
  node_rate_limit["Rate limiting<br/>[ratelimit.py]"]
  node_dashboard["Live dashboard<br/>[index.html]"]
end

node_caller(("Application caller"))
node_upstream(("LLM providers"))

node_caller -->|"submits prompt"| node_api
node_api -->|"checks cache"| node_cache
node_api -->|"selects tier"| node_router
node_router -.->|"scores complexity"| node_classifier
node_classifier -->|"uses signals"| node_signals
node_classifier -.->|"combines scoring"| node_embeddings
node_embeddings -->|"uses signals"| node_signals
node_signals -->|"counts tokens"| node_tokenizer
node_api -->|"dispatches request"| node_resilience
node_resilience -->|"calls adapter"| node_provider_contract
node_registry -->|"constructs"| node_groq
node_registry -->|"constructs"| node_google
node_registry -->|"constructs"| node_anthropic
node_registry -->|"constructs"| node_mock
node_groq -->|"implements"| node_provider_contract
node_google -->|"implements"| node_provider_contract
node_anthropic -->|"implements"| node_provider_contract
node_mock -->|"implements"| node_provider_contract
node_provider_contract -.->|"calls model API"| node_upstream
node_api -->|"records requests"| node_database
node_api -.->|"serves metrics"| node_metrics
node_api -.->|"applies limits"| node_rate_limit
node_api -->|"loads settings"| node_config
node_dashboard -.->|"displays live data"| node_api

click node_api "https://github.com/krishnnavarun/modelmux/blob/main/app/main.py"
click node_cache "https://github.com/krishnnavarun/modelmux/blob/main/app/cache.py"
click node_classifier "https://github.com/krishnnavarun/modelmux/blob/main/app/classifier/heuristic.py"
click node_signals "https://github.com/krishnnavarun/modelmux/blob/main/app/classifier/signals.py"
click node_embeddings "https://github.com/krishnnavarun/modelmux/blob/main/app/classifier/embedding.py"
click node_tokenizer "https://github.com/krishnnavarun/modelmux/blob/main/app/tokens.py"
click node_router "https://github.com/krishnnavarun/modelmux/blob/main/app/router.py"
click node_resilience "https://github.com/krishnnavarun/modelmux/blob/main/app/resilience.py"
click node_registry "https://github.com/krishnnavarun/modelmux/blob/main/app/providers/__init__.py"
click node_provider_contract "https://github.com/krishnnavarun/modelmux/blob/main/app/providers/base.py"
click node_groq "https://github.com/krishnnavarun/modelmux/blob/main/app/providers/groq.py"
click node_google "https://github.com/krishnnavarun/modelmux/blob/main/app/providers/google.py"
click node_anthropic "https://github.com/krishnnavarun/modelmux/blob/main/app/providers/anthropic.py"
click node_mock "https://github.com/krishnnavarun/modelmux/blob/main/app/providers/mock.py"
click node_config "https://github.com/krishnnavarun/modelmux/blob/main/app/config.py"
click node_database "https://github.com/krishnnavarun/modelmux/blob/main/app/db.py"
click node_metrics "https://github.com/krishnnavarun/modelmux/blob/main/app/metrics.py"
click node_rate_limit "https://github.com/krishnnavarun/modelmux/blob/main/app/ratelimit.py"
click node_dashboard "https://github.com/krishnnavarun/modelmux/blob/main/dashboard/index.html"

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_api,node_cache toneBlue
class node_classifier,node_signals,node_embeddings,node_tokenizer,node_router toneAmber
class node_resilience,node_registry,node_provider_contract,node_groq,node_google,node_anthropic,node_mock toneMint
class node_config,node_database,node_metrics,node_rate_limit,node_dashboard toneRose
class node_caller,node_upstream toneIndigo
```

## Components

### Request handling

- [Chat API](https://github.com/krishnnavarun/modelmux/blob/main/app/main.py): `app/main.py`
- [Semantic cache](https://github.com/krishnnavarun/modelmux/blob/main/app/cache.py): `app/cache.py`

### Classification and routing

- [Complexity classifier](https://github.com/krishnnavarun/modelmux/blob/main/app/classifier/heuristic.py): `app/classifier/heuristic.py`
- [Complexity signals](https://github.com/krishnnavarun/modelmux/blob/main/app/classifier/signals.py): `app/classifier/signals.py`
- [Embedding classifier](https://github.com/krishnnavarun/modelmux/blob/main/app/classifier/embedding.py): `app/classifier/embedding.py`
- [Token counting](https://github.com/krishnnavarun/modelmux/blob/main/app/tokens.py): `app/tokens.py`
- [Tier selection](https://github.com/krishnnavarun/modelmux/blob/main/app/router.py): `app/router.py`

### Provider dispatch

- [Retry and circuits](https://github.com/krishnnavarun/modelmux/blob/main/app/resilience.py): `app/resilience.py`
- [Provider registry](https://github.com/krishnnavarun/modelmux/blob/main/app/providers/__init__.py): `app/providers/__init__.py`
- [Provider contract](https://github.com/krishnnavarun/modelmux/blob/main/app/providers/base.py): `app/providers/base.py`
- [Groq adapter](https://github.com/krishnnavarun/modelmux/blob/main/app/providers/groq.py): `app/providers/groq.py`
- [Google adapter](https://github.com/krishnnavarun/modelmux/blob/main/app/providers/google.py): `app/providers/google.py`
- [Anthropic adapter](https://github.com/krishnnavarun/modelmux/blob/main/app/providers/anthropic.py): `app/providers/anthropic.py`
- [Mock adapter](https://github.com/krishnnavarun/modelmux/blob/main/app/providers/mock.py): `app/providers/mock.py`

### State and operations

- [Runtime configuration](https://github.com/krishnnavarun/modelmux/blob/main/app/config.py): `app/config.py`
- [Request records](https://github.com/krishnnavarun/modelmux/blob/main/app/db.py): `app/db.py`
- [Usage metrics](https://github.com/krishnnavarun/modelmux/blob/main/app/metrics.py): `app/metrics.py`
- [Rate limiting](https://github.com/krishnnavarun/modelmux/blob/main/app/ratelimit.py): `app/ratelimit.py`
- [Live dashboard](https://github.com/krishnnavarun/modelmux/blob/main/dashboard/index.html): `dashboard/index.html`

### Other components

- **Application caller**
- **LLM providers**

## Connections

- Application caller → Chat API: submits prompt (evidence: `README.md`)
- Chat API → Semantic cache: checks cache (evidence: `app/main.py`)
- Chat API → Tier selection: selects tier (evidence: `app/main.py`)
- Tier selection → Complexity classifier: scores complexity
- Complexity classifier → Complexity signals: uses signals (evidence: `app/classifier/heuristic.py`)
- Complexity classifier → Embedding classifier: combines scoring
- Embedding classifier → Complexity signals: uses signals (evidence: `app/classifier/embedding.py`)
- Complexity signals → Token counting: counts tokens (evidence: `app/classifier/signals.py`)
- Chat API → Retry and circuits: dispatches request (evidence: `app/main.py`)
- Retry and circuits → Provider contract: calls adapter (evidence: `app/resilience.py`)
- Provider registry → Groq adapter: constructs (evidence: `app/providers/__init__.py`)
- Provider registry → Google adapter: constructs (evidence: `app/providers/__init__.py`)
- Provider registry → Anthropic adapter: constructs (evidence: `app/providers/__init__.py`)
- Provider registry → Mock adapter: constructs (evidence: `app/providers/__init__.py`)
- Groq adapter → Provider contract: implements (evidence: `app/providers/groq.py`)
- Google adapter → Provider contract: implements (evidence: `app/providers/google.py`)
- Anthropic adapter → Provider contract: implements (evidence: `app/providers/anthropic.py`)
- Mock adapter → Provider contract: implements (evidence: `app/providers/__init__.py`)
- Provider contract → LLM providers: calls model API
- Chat API → Request records: records requests (evidence: `app/main.py`)
- Chat API → Usage metrics: serves metrics (evidence: `app/main.py`)
- Chat API → Rate limiting: applies limits (evidence: `app/main.py`)
- Chat API → Runtime configuration: loads settings (evidence: `app/main.py`)
- Live dashboard → Chat API: displays live data (evidence: `README.md`)
