# anythinglinux/localai architecture

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

- Interactive diagram: https://gitdiagram.com/anythinglinux/localai
- Repository: https://github.com/anythinglinux/localai

## Overview

LocalAI is a self-hosted AI server and web interface. The main workflow is a user request through the UI or compatible API, into the application, then to a model backend for inference and a response. Around that path, the README describes chats and agents using tools, MCP, files and collections; add-ons extend the assistant, while the model gallery and backend system manage model availability. The graph combines README-documented capabilities with sampled application and module references; many internal routes and service calls were not shown, so those links are omitted.

Main entry points: [`core/application/application.go`](https://github.com/anythinglinux/localai/blob/master/core/application/application.go) (Application), [`core/services/messaging`](https://github.com/anythinglinux/localai/tree/master/core/services/messaging) (Chats and agents), [`core/http/react-ui`](https://github.com/anythinglinux/localai/tree/master/core/http/react-ui) (Web interface), [`core/http/endpoints`](https://github.com/anythinglinux/localai/tree/master/core/http/endpoints) (HTTP and API)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Server and inference"]
  node_cli["Server entry<br/>[main.go]"]
  node_application["Application<br/>[application.go]"]
  node_api["HTTP and API"]
end

subgraph group_models["Models and backends"]
  node_model_runtime["Model runtime"]
  node_backend_workers["Inference backends"]
  node_gallery["Model gallery<br/>[storage.go]"]
end

subgraph group_experience["Chat and collaboration"]
  node_ui["Web interface"]
  node_chats["Chats and agents"]
  node_collections[("Knowledge collections")]
  node_team["Team and sharing"]
end

subgraph group_extensions["Tools and add-ons"]
  node_mcp["MCP tools"]
  node_addons["Add-ons"]
  node_workspace[("Files and workspace")]
  node_hostops["Add-on host operations"]
end

subgraph group_operations["Operations"]
  node_jobs["Fine-tuning and quantization jobs"]
  node_distributed["Distributed inference"]
  node_storage_report["Model storage report<br/>[storage.go]"]
end

node_user(("User"))

node_user -->|"uses"| node_ui
node_user -->|"requests inference"| node_api
node_ui -->|"calls API"| node_api
node_cli -.->|"starts server"| node_application
node_api -.->|"serves requests"| node_application
node_application -->|"initializes"| node_model_runtime
node_model_runtime -->|"dispatches inference"| node_backend_workers
node_application -->|"manages models"| node_gallery
node_user -->|"starts conversations"| node_chats
node_chats -->|"uses tools"| node_mcp
node_chats -->|"uses knowledge"| node_collections
node_chats -->|"uses files"| node_workspace
node_user -->|"collaborates"| node_team
node_application -->|"starts add-ons"| node_addons
node_addons -->|"requests host operations"| node_hostops
node_hostops -->|"reads and writes"| node_workspace
node_application -->|"exposes job operations"| node_jobs
node_application -->|"supports distribution"| node_distributed
node_ui -->|"requests storage report"| node_storage_report
node_storage_report -->|"indexes model files"| node_gallery

click node_cli "https://github.com/anythinglinux/localai/blob/master/cmd/local-ai/main.go"
click node_application "https://github.com/anythinglinux/localai/blob/master/core/application/application.go"
click node_api "https://github.com/anythinglinux/localai/tree/master/core/http/endpoints"
click node_ui "https://github.com/anythinglinux/localai/tree/master/core/http/react-ui"
click node_model_runtime "https://github.com/anythinglinux/localai/tree/master/core/backend"
click node_backend_workers "https://github.com/anythinglinux/localai/tree/master/backend"
click node_gallery "https://github.com/anythinglinux/localai/blob/master/core/gallery/storage.go"
click node_chats "https://github.com/anythinglinux/localai/tree/master/core/services/messaging"
click node_collections "https://github.com/anythinglinux/localai/tree/master/core/services/collections"
click node_team "https://github.com/anythinglinux/localai/tree/master/core/services"
click node_mcp "https://github.com/anythinglinux/localai/tree/master/core/http/endpoints/mcp"
click node_addons "https://github.com/anythinglinux/localai/tree/master/core/services/addons"
click node_workspace "https://github.com/anythinglinux/localai/tree/master/core/services/studio/workspace"
click node_hostops "https://github.com/anythinglinux/localai/blob/master/core/services/addons/hostops/engine_client_folders.go"
click node_jobs "https://github.com/anythinglinux/localai/blob/master/core/http/endpoints/localai/addon_engine_jobs.go"
click node_distributed "https://github.com/anythinglinux/localai/tree/master/core/services/nodes"
click node_storage_report "https://github.com/anythinglinux/localai/blob/master/core/gallery/storage.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_cli,node_application,node_api,node_user toneBlue
class node_model_runtime,node_backend_workers,node_gallery toneAmber
class node_ui,node_chats,node_collections,node_team toneMint
class node_mcp,node_addons,node_workspace,node_hostops toneRose
class node_jobs,node_distributed,node_storage_report toneIndigo
```

## Components

### Server and inference

- [Server entry](https://github.com/anythinglinux/localai/blob/master/cmd/local-ai/main.go): `cmd/local-ai/main.go`
- [Application](https://github.com/anythinglinux/localai/blob/master/core/application/application.go): `core/application/application.go`
- [HTTP and API](https://github.com/anythinglinux/localai/tree/master/core/http/endpoints): `core/http/endpoints`

### Models and backends

- [Model runtime](https://github.com/anythinglinux/localai/tree/master/core/backend): `core/backend`
- [Inference backends](https://github.com/anythinglinux/localai/tree/master/backend): `backend`
- [Model gallery](https://github.com/anythinglinux/localai/blob/master/core/gallery/storage.go): `core/gallery/storage.go`

### Chat and collaboration

- [Web interface](https://github.com/anythinglinux/localai/tree/master/core/http/react-ui): `core/http/react-ui`
- [Chats and agents](https://github.com/anythinglinux/localai/tree/master/core/services/messaging): `core/services/messaging`
- [Knowledge collections](https://github.com/anythinglinux/localai/tree/master/core/services/collections): `core/services/collections`
- [Team and sharing](https://github.com/anythinglinux/localai/tree/master/core/services): `core/services`

### Tools and add-ons

- [MCP tools](https://github.com/anythinglinux/localai/tree/master/core/http/endpoints/mcp): `core/http/endpoints/mcp`
- [Add-ons](https://github.com/anythinglinux/localai/tree/master/core/services/addons): `core/services/addons`
- [Files and workspace](https://github.com/anythinglinux/localai/tree/master/core/services/studio/workspace): `core/services/studio/workspace`
- [Add-on host operations](https://github.com/anythinglinux/localai/blob/master/core/services/addons/hostops/engine_client_folders.go): `core/services/addons/hostops/engine_client_folders.go`

### Operations

- [Fine-tuning and quantization jobs](https://github.com/anythinglinux/localai/blob/master/core/http/endpoints/localai/addon_engine_jobs.go): `core/http/endpoints/localai/addon_engine_jobs.go`
- [Distributed inference](https://github.com/anythinglinux/localai/tree/master/core/services/nodes): `core/services/nodes`
- [Model storage report](https://github.com/anythinglinux/localai/blob/master/core/gallery/storage.go): `core/gallery/storage.go`

### Other components

- **User**

## Connections

- User → Web interface: uses
- User → HTTP and API: requests inference
- Web interface → HTTP and API: calls API (evidence: `core/http/react-ui/src/utils/api.js`)
- Server entry → Application: starts server
- HTTP and API → Application: serves requests (evidence: `core/application/application.go`)
- Application → Model runtime: initializes (evidence: `core/application/application.go`)
- Model runtime → Inference backends: dispatches inference
- Application → Model gallery: manages models (evidence: `core/application/application.go`)
- User → Chats and agents: starts conversations
- Chats and agents → MCP tools: uses tools
- Chats and agents → Knowledge collections: uses knowledge
- Chats and agents → Files and workspace: uses files
- User → Team and sharing: collaborates
- Application → Add-ons: starts add-ons (evidence: `core/application/application.go`)
- Add-ons → Add-on host operations: requests host operations (evidence: `core/services/addons/hostops/engine_client_folders.go`)
- Add-on host operations → Files and workspace: reads and writes (evidence: `core/services/addons/hostops/engine_client_folders.go`)
- Application → Fine-tuning and quantization jobs: exposes job operations (evidence: `core/application/application.go`)
- Application → Distributed inference: supports distribution (evidence: `core/application/application.go`)
- Web interface → Model storage report: requests storage report (evidence: `core/http/react-ui/src/hooks/useModelStorage.js`)
- Model storage report → Model gallery: indexes model files (evidence: `core/gallery/storage.go`)
