{
  "generator": {
    "name": "Symvanta",
    "url": "https://symvanta.com"
  },
  "page": {
    "url": "https://symvanta.com/architecture/ollama",
    "title": "Ollama Architecture: How It Actually Works",
    "description": "How the Ollama codebase is structured: module map, load-bearing symbols, and dependency structure, generated by Symvanta.",
    "datePublished": "2026-08-08",
    "dateModified": "2026-08-08"
  },
  "repository": {
    "name": "ollama/ollama",
    "url": "https://github.com/ollama/ollama",
    "commit": "26936be",
    "license": "MIT"
  },
  "graph": {
    "modules": 52,
    "dependencyCycles": 2,
    "modularityQ": 0.76,
    "largestCycleFiles": 2,
    "mutuallyRecursiveGroups": 7
  },
  "summaryMarkdown": "Ollama is a local model runtime with an HTTP server in front of it: it resolves\na model reference, loads the weights, schedules a runner, and streams tokens\nback. Symvanta's graph of the repo at `26936be` detects 52 functional modules at\nmodularity Q=0.76, and the largest are the ones that description predicts: chat\nrequest handling and prompt templating, model names and manifests, the launcher\nthat manages installed models, and an MLX runner for Apple silicon.\n\nTwo things about the shape stand out. The chat path concentrates in a single\nhandler: `server.Server.ChatHandler` runs from line 2417 to line 2911 of\n`server/routes.go`, and `GenerateHandler` above it is a similar size. And the\nMLX cluster is almost as large as the chat cluster, 793 symbols against 804,\nwhich is what a second inference path for one hardware family costs in a\ncodebase.",
  "subsystems": [
    {
      "name": "Chat rendering and templates",
      "descriptionMarkdown": "Prompt templating sits with terminal chat rendering (`chat.wrapChatText`,\n`chat.stripANSI`, `chat.chatDisplayWidthCut`) in the largest cluster on the map,\n804 symbols behind the hub `template.Template.Contains`. The same package builds\nthe prompt and paints the reply."
    },
    {
      "name": "MLX arrays and devices",
      "descriptionMarkdown": "Apple silicon runtime: `mlx.DefaultStream`, `mlx.DefaultDevice`, the array\noperations, and the Cocoa bindings. At 793 symbols it is within a rounding error\nof the chat cluster, and it calls into the MLX parameter and decode cluster 78\ntimes."
    },
    {
      "name": "API message and tool-call types",
      "descriptionMarkdown": "The wire types live here, 750 symbols of `Message`, `ToolCall`,\n`ToolCallFunction`, `ThinkValue`, and their conversion helpers. Every surface,\nnative or compatibility, funnels through them."
    },
    {
      "name": "Model launcher",
      "descriptionMarkdown": "Which models are installed and which one starts: `launch.fallbackLaunchModel`,\n`launch.launchModelsFromNames`, `launch.lookupCloudModelLimit`, and the\nenvironment host resolution around them, 647 symbols in total."
    },
    {
      "name": "Model names and manifests",
      "descriptionMarkdown": "Parsing and validating model references (`model.ParseName`,\n`model.Name.IsFullyQualified`, `model.isValidPart`) and finding their blobs on\ndisk (`manifest.BlobsPath`). 451 symbols, and all of it runs before a single\nweight is loaded."
    }
  ],
  "startReading": {
    "symbols": [
      {
        "name": "template.Template.Contains"
      },
      {
        "name": "mlx.DefaultStream"
      },
      {
        "name": "agent.SkillCatalog.Dir"
      },
      {
        "name": "mlxthread.Thread.Do"
      },
      {
        "name": "mlxthread.Thread.enqueue"
      },
      {
        "name": "mlx.Array.Equal"
      },
      {
        "name": "dialog.MsgBuilder.Info"
      },
      {
        "name": "envconfig.Var"
      },
      {
        "name": "model.Name.EqualFold"
      },
      {
        "name": "KV"
      }
    ],
    "endpoints": [
      {
        "method": "POST",
        "path": "/api/chat"
      },
      {
        "method": "POST",
        "path": "/api/generate"
      },
      {
        "method": "GET",
        "path": "/api/version"
      },
      {
        "method": "POST",
        "path": "/v1/chat/completions"
      },
      {
        "method": "POST",
        "path": "/v1/completions"
      },
      {
        "method": "POST",
        "path": "/v1/embeddings"
      },
      {
        "method": "GET",
        "path": "/v1/models"
      },
      {
        "method": "GET",
        "path": "/v1/models/:model"
      },
      {
        "method": "POST",
        "path": "/v1/responses"
      },
      {
        "method": "POST",
        "path": "/v1/audio/transcriptions"
      },
      {
        "method": "POST",
        "path": "/v1/messages"
      }
    ]
  },
  "requestFlow": [
    {
      "position": 1,
      "symbol": "r.POST./api/chat (server/routes.go:1891)",
      "sourceUrl": null,
      "markdown": "`r.POST./api/chat (server/routes.go:1891)`"
    },
    {
      "position": 2,
      "symbol": "server.Server.ChatHandler",
      "sourceUrl": null,
      "markdown": "`server.Server.ChatHandler`"
    },
    {
      "position": 3,
      "symbol": "server.parseAndValidateModelRef",
      "sourceUrl": null,
      "markdown": "`server.parseAndValidateModelRef`"
    },
    {
      "position": 4,
      "symbol": "server.GetModel",
      "sourceUrl": null,
      "markdown": "`server.GetModel`"
    },
    {
      "position": 5,
      "symbol": "server.Model.Capabilities",
      "sourceUrl": null,
      "markdown": "`server.Model.Capabilities`"
    },
    {
      "position": 6,
      "symbol": "server.chatModeForModel",
      "sourceUrl": null,
      "markdown": "`server.chatModeForModel`"
    },
    {
      "position": 7,
      "symbol": "server.chatPrompt",
      "sourceUrl": null,
      "markdown": "`server.chatPrompt`"
    },
    {
      "position": 8,
      "symbol": "server.filterThinkTags",
      "sourceUrl": null,
      "markdown": "`server.filterThinkTags`"
    }
  ],
  "diagrams": [
    {
      "url": "https://symvanta.com/architecture/ollama/module-map.svg",
      "encodingFormat": "image/svg+xml"
    }
  ]
}
