# townsendmerino/goinfer architecture

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

- Interactive diagram: https://gitdiagram.com/townsendmerino/goinfer
- Repository: https://github.com/townsendmerino/goinfer

## Overview

goinfer is a Go runtime for local open-weight language models, offered as a library, chat binary, and OpenAI/Anthropic-compatible server. Its main workflow is to accept a prompt or API request, resolve and load model assets, run inference, and return generated output; optional paths add schema-constrained output, multimodal inputs, embeddings, and tool use. The graph also shows model acquisition and CLI utilities. Several subsystem links are supported only by README statements or SOURCE INDEX references; unsampled implementations and their internal call paths are not inferred.

Main entry points: [`internal/serveapp/main.go`](https://github.com/townsendmerino/goinfer/blob/main/internal/serveapp/main.go) (HTTP server), [`internal/modelload/modelload.go`](https://github.com/townsendmerino/goinfer/blob/main/internal/modelload/modelload.go) (Model loading), [`internal/chatapp/main.go`](https://github.com/townsendmerino/goinfer/blob/main/internal/chatapp/main.go) (Chat CLI), [`decoder/session.go`](https://github.com/townsendmerino/goinfer/blob/main/decoder/session.go) (Model decoder)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["User entrypoints"]
  node_chatapp["Chat CLI<br/>[main.go]"]
  node_serveapp["HTTP server<br/>[main.go]"]
  node_serverlib["In-process API<br/>[server.go]"]
end

subgraph group_runtime["Model runtime"]
  node_decoder["Model decoder<br/>[session.go]"]
  node_cuda["CUDA backend<br/>[resident.go]"]
  node_metalembed["Metal embeddings<br/>[embeddinggemma2.go]"]
end

subgraph group_assets["Model assets"]
  node_modelload["Model loading<br/>[modelload.go]"]
  node_loadflags["Load configuration<br/>[loadflags.go]"]
  node_pullcmd["Pull commands<br/>[pull.go]"]
  node_pull["Checkpoint retrieval<br/>[pull.go]"]
  node_prequant["Prequantization<br/>[prequant.go]"]
  node_fitcmd["Hardware fit checks<br/>[fit.go]"]
end

subgraph group_serve["Serving features"]
  node_decidecmd["Decision CLI<br/>[decidecmd.go]"]
  node_decide["Label scoring<br/>[decide.go]"]
  node_inproc["In-process transport<br/>[transport.go]"]
end

subgraph group_extensions["Output and modalities"]
  node_constrain["Schema constraints<br/>[schema.go]"]
  node_chattools["Chat tool formats<br/>[tools.go]"]
  node_multimodal["Multimodal processing<br/>[load.go]"]
  node_embeddings["Embedding model<br/>[model.go]"]
end

node_user(("User or client"))

node_user -->|"prompts"| node_chatapp
node_user -->|"sends requests"| node_serveapp
node_chatapp -->|"loads model"| node_modelload
node_chatapp -->|"generates with"| node_decoder
node_chatapp -->|"supports schema output"| node_constrain
node_chatapp -->|"dispatches pull"| node_pullcmd
node_chatapp -->|"dispatches fit"| node_fitcmd
node_serveapp -->|"loads models"| node_modelload
node_serveapp -->|"registers options"| node_loadflags
node_serveapp -->|"dispatches pull"| node_pullcmd
node_serveapp -->|"serves inference"| node_decoder
node_serveapp -->|"offers label scoring"| node_decide
node_serveapp -->|"supports modalities"| node_multimodal
node_serveapp -->|"serves embeddings"| node_embeddings
node_serverlib -->|"wraps handler"| node_serveapp
node_serverlib -->|"uses transport"| node_inproc
node_modelload -->|"loads into"| node_decoder
node_modelload -->|"resolves assets"| node_pull
node_modelload -->|"uses bundles"| node_prequant
node_loadflags -->|"configures"| node_decoder
node_pullcmd -->|"fetches checkpoints"| node_pull
node_decidecmd -->|"runs scoring"| node_decide
node_decidecmd -->|"loads model"| node_modelload
node_fitcmd -->|"loads model"| node_modelload
node_fitcmd -->|"uses quantization"| node_prequant
node_decoder -->|"supports constrained decode"| node_constrain
node_cuda -->|"registers backend"| node_decoder
node_metalembed -->|"implements acceleration"| node_embeddings

click node_chatapp "https://github.com/townsendmerino/goinfer/blob/main/internal/chatapp/main.go"
click node_serveapp "https://github.com/townsendmerino/goinfer/blob/main/internal/serveapp/main.go"
click node_serverlib "https://github.com/townsendmerino/goinfer/blob/main/server/server.go"
click node_decoder "https://github.com/townsendmerino/goinfer/blob/main/decoder/session.go"
click node_cuda "https://github.com/townsendmerino/goinfer/blob/main/cuda/resident.go"
click node_metalembed "https://github.com/townsendmerino/goinfer/blob/main/metal/embeddinggemma2.go"
click node_modelload "https://github.com/townsendmerino/goinfer/blob/main/internal/modelload/modelload.go"
click node_loadflags "https://github.com/townsendmerino/goinfer/blob/main/internal/loadflags/loadflags.go"
click node_pullcmd "https://github.com/townsendmerino/goinfer/blob/main/internal/pullcmd/pull.go"
click node_pull "https://github.com/townsendmerino/goinfer/blob/main/pull/pull.go"
click node_prequant "https://github.com/townsendmerino/goinfer/blob/main/internal/prequant/prequant.go"
click node_fitcmd "https://github.com/townsendmerino/goinfer/blob/main/internal/fitcmd/fit.go"
click node_decidecmd "https://github.com/townsendmerino/goinfer/blob/main/internal/decidecmd/decidecmd.go"
click node_decide "https://github.com/townsendmerino/goinfer/blob/main/internal/decide/decide.go"
click node_constrain "https://github.com/townsendmerino/goinfer/blob/main/constrain/schema.go"
click node_chattools "https://github.com/townsendmerino/goinfer/blob/main/chat/tools.go"
click node_multimodal "https://github.com/townsendmerino/goinfer/blob/main/multimodal/load.go"
click node_embeddings "https://github.com/townsendmerino/goinfer/blob/main/embeddinggemma2/model.go"
click node_inproc "https://github.com/townsendmerino/goinfer/blob/main/internal/inproc/transport.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_chatapp,node_serveapp,node_serverlib,node_user toneBlue
class node_decoder,node_cuda,node_metalembed toneAmber
class node_modelload,node_loadflags,node_pullcmd,node_pull,node_prequant,node_fitcmd toneMint
class node_decidecmd,node_decide,node_inproc toneRose
class node_constrain,node_chattools,node_multimodal,node_embeddings toneIndigo
```

## Components

### User entrypoints

- [Chat CLI](https://github.com/townsendmerino/goinfer/blob/main/internal/chatapp/main.go): `internal/chatapp/main.go`
- [HTTP server](https://github.com/townsendmerino/goinfer/blob/main/internal/serveapp/main.go): `internal/serveapp/main.go`
- [In-process API](https://github.com/townsendmerino/goinfer/blob/main/server/server.go): `server/server.go`

### Model runtime

- [Model decoder](https://github.com/townsendmerino/goinfer/blob/main/decoder/session.go): `decoder/session.go`
- [CUDA backend](https://github.com/townsendmerino/goinfer/blob/main/cuda/resident.go): `cuda/resident.go`
- [Metal embeddings](https://github.com/townsendmerino/goinfer/blob/main/metal/embeddinggemma2.go): `metal/embeddinggemma2.go`

### Model assets

- [Model loading](https://github.com/townsendmerino/goinfer/blob/main/internal/modelload/modelload.go): `internal/modelload/modelload.go`
- [Load configuration](https://github.com/townsendmerino/goinfer/blob/main/internal/loadflags/loadflags.go): `internal/loadflags/loadflags.go`
- [Pull commands](https://github.com/townsendmerino/goinfer/blob/main/internal/pullcmd/pull.go): `internal/pullcmd/pull.go`
- [Checkpoint retrieval](https://github.com/townsendmerino/goinfer/blob/main/pull/pull.go): `pull/pull.go`
- [Prequantization](https://github.com/townsendmerino/goinfer/blob/main/internal/prequant/prequant.go): `internal/prequant/prequant.go`
- [Hardware fit checks](https://github.com/townsendmerino/goinfer/blob/main/internal/fitcmd/fit.go): `internal/fitcmd/fit.go`

### Serving features

- [Decision CLI](https://github.com/townsendmerino/goinfer/blob/main/internal/decidecmd/decidecmd.go): `internal/decidecmd/decidecmd.go`
- [Label scoring](https://github.com/townsendmerino/goinfer/blob/main/internal/decide/decide.go): `internal/decide/decide.go`
- [In-process transport](https://github.com/townsendmerino/goinfer/blob/main/internal/inproc/transport.go): `internal/inproc/transport.go`

### Output and modalities

- [Schema constraints](https://github.com/townsendmerino/goinfer/blob/main/constrain/schema.go): `constrain/schema.go`
- [Chat tool formats](https://github.com/townsendmerino/goinfer/blob/main/chat/tools.go): `chat/tools.go`
- [Multimodal processing](https://github.com/townsendmerino/goinfer/blob/main/multimodal/load.go): `multimodal/load.go`
- [Embedding model](https://github.com/townsendmerino/goinfer/blob/main/embeddinggemma2/model.go): `embeddinggemma2/model.go`

### Other components

- **User or client**

## Connections

- User or client → Chat CLI: prompts (evidence: `internal/chatapp/main.go`)
- User or client → HTTP server: sends requests
- Chat CLI → Model loading: loads model (evidence: `internal/chatapp/main.go`)
- Chat CLI → Model decoder: generates with (evidence: `internal/chatapp/main.go`)
- Chat CLI → Schema constraints: supports schema output (evidence: `internal/chatapp/main.go`)
- Chat CLI → Pull commands: dispatches pull (evidence: `internal/chatapp/main.go`)
- Chat CLI → Hardware fit checks: dispatches fit (evidence: `internal/chatapp/main.go`)
- HTTP server → Model loading: loads models (evidence: `internal/serveapp/main.go`)
- HTTP server → Load configuration: registers options (evidence: `internal/serveapp/main.go`)
- HTTP server → Pull commands: dispatches pull (evidence: `internal/serveapp/main.go`)
- HTTP server → Model decoder: serves inference (evidence: `internal/serveapp/main.go`)
- HTTP server → Label scoring: offers label scoring (evidence: `internal/serveapp/main.go`)
- HTTP server → Multimodal processing: supports modalities (evidence: `internal/serveapp/main.go`)
- HTTP server → Embedding model: serves embeddings (evidence: `internal/serveapp/main.go`)
- In-process API → HTTP server: wraps handler (evidence: `server/server.go`)
- In-process API → In-process transport: uses transport (evidence: `server/server.go`)
- Model loading → Model decoder: loads into (evidence: `internal/modelload/modelload.go`)
- Model loading → Checkpoint retrieval: resolves assets (evidence: `internal/modelload/modelload.go`)
- Model loading → Prequantization: uses bundles (evidence: `internal/modelload/modelload.go`)
- Load configuration → Model decoder: configures (evidence: `internal/loadflags/loadflags.go`)
- Pull commands → Checkpoint retrieval: fetches checkpoints (evidence: `internal/pullcmd/pull.go`)
- Decision CLI → Label scoring: runs scoring (evidence: `internal/decidecmd/decidecmd.go`)
- Decision CLI → Model loading: loads model (evidence: `internal/decidecmd/decidecmd.go`)
- Hardware fit checks → Model loading: loads model (evidence: `internal/fitcmd/fit.go`)
- Hardware fit checks → Prequantization: uses quantization (evidence: `internal/fitcmd/fit.go`)
- Model decoder → Schema constraints: supports constrained decode (evidence: `decoder/session.go`)
- CUDA backend → Model decoder: registers backend
- Metal embeddings → Embedding model: implements acceleration (evidence: `metal/embeddinggemma2.go`)
