# magomedcoder/gogguf architecture

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

- Interactive diagram: https://gitdiagram.com/magomedcoder/gogguf
- Repository: https://github.com/magomedcoder/gogguf

## Overview

GoGGUF is a Go library and HTTP service for loading GGUF language models and running inference, with a CLI and a Vue chat UI. The main path is model file → GGUF reader and weights → tokenizer/model runtime → generation or embeddings → CLI or HTTP response. The README documents chat templates, supported model families, quantized operations and CUDA offload. Some implementation details are unsampled; edges based on those capabilities cite the README rather than implying inspected call paths.

Main entry points: [`pkg/runtime/engine.go`](https://github.com/magomedcoder/gogguf/blob/main/pkg/runtime/engine.go) (Inference engine), [`pkg/model/detect.go`](https://github.com/magomedcoder/gogguf/blob/main/pkg/model/detect.go) (Model selection), [`pkg/weights/store.go`](https://github.com/magomedcoder/gogguf/blob/main/pkg/weights/store.go) (Weight store), [`pkg/gpu/backend.go`](https://github.com/magomedcoder/gogguf/blob/main/pkg/gpu/backend.go) (GPU backend)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_ingest["Model ingestion"]
  node_reader["GGUF reader<br/>[reader.go]"]
  node_weights["Weight store<br/>[store.go]"]
  node_tokenizer["Tokenizer<br/>[tokenizer.go]"]
end

subgraph group_inference["Inference engine"]
  node_model_load["Model selection<br/>[detect.go]"]
  node_qwen3["Qwen3 model<br/>[model.go]"]
  node_mistral["Mistral model<br/>[model.go]"]
  node_deepseek["DeepSeek model<br/>[model.go]"]
  node_deepseek2["DeepSeek2 model<br/>[model.go]"]
  node_other_models["Other model families<br/>[model.go]"]
  node_engine["Inference engine<br/>[engine.go]"]
  node_context["Inference context<br/>[context.go]"]
  node_session["Generation session<br/>[session.go]"]
  node_ops["Tensor operations<br/>[ops.go]"]
end

subgraph group_delivery["User interfaces"]
  node_cli["CLI commands<br/>[run.go]"]
  node_http["HTTP API<br/>[server.go]"]
  node_web["Web chat UI<br/>[ChatView.vue]"]
end

subgraph group_acceleration["Compute backends"]
  node_gpu_backend["GPU backend<br/>[backend.go]"]
  node_multi_gpu["Multi-GPU<br/>[multi.go]"]
  node_cuda_backend["CUDA backend<br/>[backend.go]"]
  node_cuda_driver["CUDA driver<br/>[driver.c]"]
  node_cpu_backend["CPU backend<br/>[cpu.go]"]
end

subgraph group_chat["Chat and sampling"]
  node_sampler["Sampling chain<br/>[chain.go]"]
  node_chat_templates["Chat templates<br/>[template.go]"]
end

node_user(("User"))
node_gguf["GGUF file"]
node_api_client(("HTTP client"))

node_user -->|"runs commands"| node_cli
node_user -->|"chats through"| node_web
node_user -->|"sends requests"| node_api_client
node_gguf -->|"parsed by"| node_reader
node_reader -->|"supplies tensors"| node_weights
node_reader -->|"provides metadata"| node_tokenizer
node_engine -->|"opens model"| node_reader
node_engine -->|"loads model"| node_model_load
node_engine -->|"creates tokenizer"| node_tokenizer
node_model_load -.->|"selects family"| node_qwen3
node_model_load -.->|"selects family"| node_mistral
node_model_load -.->|"selects family"| node_deepseek
node_model_load -.->|"selects family"| node_deepseek2
node_model_load -.->|"selects family"| node_other_models
node_qwen3 -->|"reads weights"| node_weights
node_mistral -->|"reads weights"| node_weights
node_deepseek -->|"reads weights"| node_weights
node_deepseek2 -->|"reads weights"| node_weights
node_qwen3 -->|"computes with"| node_ops
node_mistral -->|"computes with"| node_ops
node_deepseek -->|"computes with"| node_ops
node_deepseek2 -->|"computes with"| node_ops
node_engine -->|"creates context"| node_context
node_context -->|"starts generation"| node_session
node_session -->|"chooses tokens"| node_sampler
node_session -->|"encodes and decodes"| node_tokenizer
node_context -->|"uses model"| node_engine
node_cli -->|"loads and runs"| node_engine
node_cli -->|"formats chat"| node_chat_templates
node_http -->|"serves inference"| node_engine
node_api_client -->|"calls endpoints"| node_http
node_web -.->|"calls API"| node_http
node_engine -->|"opens backend"| node_gpu_backend
node_gpu_backend -.->|"may dispatch"| node_multi_gpu
node_gpu_backend -.->|"may dispatch"| node_cuda_backend
node_cuda_backend -->|"uses driver"| node_cuda_driver
node_gpu_backend -.->|"uses CPU path"| node_cpu_backend

click node_reader "https://github.com/magomedcoder/gogguf/blob/main/pkg/format/reader.go"
click node_weights "https://github.com/magomedcoder/gogguf/blob/main/pkg/weights/store.go"
click node_tokenizer "https://github.com/magomedcoder/gogguf/blob/main/pkg/tokenizer/tokenizer.go"
click node_model_load "https://github.com/magomedcoder/gogguf/blob/main/pkg/model/detect.go"
click node_qwen3 "https://github.com/magomedcoder/gogguf/blob/main/pkg/model/qwen3/model.go"
click node_mistral "https://github.com/magomedcoder/gogguf/blob/main/pkg/model/mistral/model.go"
click node_deepseek "https://github.com/magomedcoder/gogguf/blob/main/pkg/model/deepseek/model.go"
click node_deepseek2 "https://github.com/magomedcoder/gogguf/blob/main/pkg/model/deepseek2/model.go"
click node_other_models "https://github.com/magomedcoder/gogguf/blob/main/pkg/model/llama/model.go"
click node_engine "https://github.com/magomedcoder/gogguf/blob/main/pkg/runtime/engine.go"
click node_context "https://github.com/magomedcoder/gogguf/blob/main/pkg/runtime/context.go"
click node_session "https://github.com/magomedcoder/gogguf/blob/main/pkg/runtime/session.go"
click node_ops "https://github.com/magomedcoder/gogguf/blob/main/pkg/ops/ops.go"
click node_sampler "https://github.com/magomedcoder/gogguf/blob/main/pkg/sampler/chain.go"
click node_chat_templates "https://github.com/magomedcoder/gogguf/blob/main/pkg/chat/template.go"
click node_cli "https://github.com/magomedcoder/gogguf/blob/main/cmd/gogguf/run.go"
click node_http "https://github.com/magomedcoder/gogguf/blob/main/server/server.go"
click node_web "https://github.com/magomedcoder/gogguf/blob/main/web-ui/src/components/ChatView.vue"
click node_gpu_backend "https://github.com/magomedcoder/gogguf/blob/main/pkg/gpu/backend.go"
click node_multi_gpu "https://github.com/magomedcoder/gogguf/blob/main/pkg/gpu/multi.go"
click node_cuda_backend "https://github.com/magomedcoder/gogguf/blob/main/pkg/gpu/cuda/backend.go"
click node_cuda_driver "https://github.com/magomedcoder/gogguf/blob/main/pkg/gpu/cuda/driver.c"
click node_cpu_backend "https://github.com/magomedcoder/gogguf/blob/main/pkg/gpu/cpu.go"

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_reader,node_weights,node_tokenizer,node_user,node_api_client toneBlue
class node_model_load,node_qwen3,node_mistral,node_deepseek,node_deepseek2,node_other_models,node_engine,node_context,node_session,node_ops toneAmber
class node_cli,node_http,node_web toneMint
class node_gpu_backend,node_multi_gpu,node_cuda_backend,node_cuda_driver,node_cpu_backend toneRose
class node_sampler,node_chat_templates,node_gguf toneIndigo
```

## Components

### Model ingestion

- [GGUF reader](https://github.com/magomedcoder/gogguf/blob/main/pkg/format/reader.go): `pkg/format/reader.go`
- [Weight store](https://github.com/magomedcoder/gogguf/blob/main/pkg/weights/store.go): `pkg/weights/store.go`
- [Tokenizer](https://github.com/magomedcoder/gogguf/blob/main/pkg/tokenizer/tokenizer.go): `pkg/tokenizer/tokenizer.go`

### Inference engine

- [Model selection](https://github.com/magomedcoder/gogguf/blob/main/pkg/model/detect.go): `pkg/model/detect.go`
- [Qwen3 model](https://github.com/magomedcoder/gogguf/blob/main/pkg/model/qwen3/model.go): `pkg/model/qwen3/model.go`
- [Mistral model](https://github.com/magomedcoder/gogguf/blob/main/pkg/model/mistral/model.go): `pkg/model/mistral/model.go`
- [DeepSeek model](https://github.com/magomedcoder/gogguf/blob/main/pkg/model/deepseek/model.go): `pkg/model/deepseek/model.go`
- [DeepSeek2 model](https://github.com/magomedcoder/gogguf/blob/main/pkg/model/deepseek2/model.go): `pkg/model/deepseek2/model.go`
- [Other model families](https://github.com/magomedcoder/gogguf/blob/main/pkg/model/llama/model.go): `pkg/model/llama/model.go`
- [Inference engine](https://github.com/magomedcoder/gogguf/blob/main/pkg/runtime/engine.go): `pkg/runtime/engine.go`
- [Inference context](https://github.com/magomedcoder/gogguf/blob/main/pkg/runtime/context.go): `pkg/runtime/context.go`
- [Generation session](https://github.com/magomedcoder/gogguf/blob/main/pkg/runtime/session.go): `pkg/runtime/session.go`
- [Tensor operations](https://github.com/magomedcoder/gogguf/blob/main/pkg/ops/ops.go): `pkg/ops/ops.go`

### User interfaces

- [CLI commands](https://github.com/magomedcoder/gogguf/blob/main/cmd/gogguf/run.go): `cmd/gogguf/run.go`
- [HTTP API](https://github.com/magomedcoder/gogguf/blob/main/server/server.go): `server/server.go`
- [Web chat UI](https://github.com/magomedcoder/gogguf/blob/main/web-ui/src/components/ChatView.vue): `web-ui/src/components/ChatView.vue`

### Compute backends

- [GPU backend](https://github.com/magomedcoder/gogguf/blob/main/pkg/gpu/backend.go): `pkg/gpu/backend.go`
- [Multi-GPU](https://github.com/magomedcoder/gogguf/blob/main/pkg/gpu/multi.go): `pkg/gpu/multi.go`
- [CUDA backend](https://github.com/magomedcoder/gogguf/blob/main/pkg/gpu/cuda/backend.go): `pkg/gpu/cuda/backend.go`
- [CUDA driver](https://github.com/magomedcoder/gogguf/blob/main/pkg/gpu/cuda/driver.c): `pkg/gpu/cuda/driver.c`
- [CPU backend](https://github.com/magomedcoder/gogguf/blob/main/pkg/gpu/cpu.go): `pkg/gpu/cpu.go`

### Chat and sampling

- [Sampling chain](https://github.com/magomedcoder/gogguf/blob/main/pkg/sampler/chain.go): `pkg/sampler/chain.go`
- [Chat templates](https://github.com/magomedcoder/gogguf/blob/main/pkg/chat/template.go): `pkg/chat/template.go`

### Other components

- **User**
- **GGUF file**
- **HTTP client**

## Connections

- User → CLI commands: runs commands (evidence: `README.md`)
- User → Web chat UI: chats through (evidence: `README.md`)
- User → HTTP client: sends requests (evidence: `README.md`)
- GGUF file → GGUF reader: parsed by (evidence: `README.md`)
- GGUF reader → Weight store: supplies tensors (evidence: `pkg/weights/store.go`)
- GGUF reader → Tokenizer: provides metadata (evidence: `pkg/tokenizer/tokenizer.go`)
- Inference engine → GGUF reader: opens model (evidence: `pkg/runtime/engine.go`)
- Inference engine → Model selection: loads model (evidence: `pkg/runtime/engine.go`)
- Inference engine → Tokenizer: creates tokenizer (evidence: `pkg/runtime/engine.go`)
- Model selection → Qwen3 model: selects family
- Model selection → Mistral model: selects family
- Model selection → DeepSeek model: selects family
- Model selection → DeepSeek2 model: selects family
- Model selection → Other model families: selects family
- Qwen3 model → Weight store: reads weights (evidence: `pkg/model/qwen3/model.go`)
- Mistral model → Weight store: reads weights (evidence: `pkg/model/mistral/model.go`)
- DeepSeek model → Weight store: reads weights (evidence: `pkg/model/deepseek/model.go`)
- DeepSeek2 model → Weight store: reads weights (evidence: `pkg/model/deepseek2/model.go`)
- Qwen3 model → Tensor operations: computes with (evidence: `pkg/model/qwen3/model.go`)
- Mistral model → Tensor operations: computes with (evidence: `pkg/model/mistral/model.go`)
- DeepSeek model → Tensor operations: computes with (evidence: `pkg/model/deepseek/model.go`)
- DeepSeek2 model → Tensor operations: computes with (evidence: `pkg/model/deepseek2/model.go`)
- Inference engine → Inference context: creates context (evidence: `pkg/runtime/context.go`)
- Inference context → Generation session: starts generation (evidence: `pkg/runtime/session.go`)
- Generation session → Sampling chain: chooses tokens (evidence: `pkg/runtime/session.go`)
- Generation session → Tokenizer: encodes and decodes (evidence: `pkg/runtime/session.go`)
- Inference context → Inference engine: uses model (evidence: `pkg/runtime/context.go`)
- CLI commands → Inference engine: loads and runs (evidence: `cmd/gogguf/run.go`)
- CLI commands → Chat templates: formats chat (evidence: `cmd/gogguf/run.go`)
- HTTP API → Inference engine: serves inference (evidence: `server/server.go`)
- HTTP client → HTTP API: calls endpoints (evidence: `README.md`)
- Web chat UI → HTTP API: calls API
- Inference engine → GPU backend: opens backend (evidence: `pkg/runtime/engine.go`)
- GPU backend → Multi-GPU: may dispatch
- GPU backend → CUDA backend: may dispatch
- CUDA backend → CUDA driver: uses driver (evidence: `pkg/gpu/cuda/driver.c`)
- GPU backend → CPU backend: uses CPU path
