# unslothai/unsloth architecture

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

- Interactive diagram: https://gitdiagram.com/unslothai/unsloth
- Repository: https://github.com/unslothai/unsloth

## Overview

Unsloth is a desktop and web-based environment for running and training local AI models, with Unsloth Core also available as a code library. The principal workflow is a user choosing or supplying a model, Studio dispatching inference to a local engine, and the interface presenting the result. The product also covers chat tools and browser use, image/video generation, data preparation and fine-tuning, export, and remote/API access. Source excerpts are partial, so unverified runtime links are omitted or marked dashed rather than inferred from directory structure.

Main entry points: [`studio/frontend/src/features`](https://github.com/unslothai/unsloth/tree/main/studio/frontend/src/features) (Studio interface), [`studio/backend/core/inference/llama_cpp.py`](https://github.com/unslothai/unsloth/blob/main/studio/backend/core/inference/llama_cpp.py) (Model engines), [`studio/backend/main.py`](https://github.com/unslothai/unsloth/blob/main/studio/backend/main.py) (Studio backend), [`studio/backend/routes/inference.py`](https://github.com/unslothai/unsloth/blob/main/studio/backend/routes/inference.py) (Inference routes)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_app["Studio application"]
  node_desktop["Desktop shell<br/>[main.rs]"]
  node_studio_ui["Studio interface"]
  node_auth[("Accounts and keys<br/>[storage.py]")]
  node_chat_api["Chat API<br/>[chat-api.ts]"]
  node_chat_history[("Chat history")]
end

subgraph group_runtime["Model runtime"]
  node_backend["Studio backend<br/>[main.py]"]
  node_inference_routes["Inference routes<br/>[inference.py]"]
  node_managed_chat["Managed chat"]
  node_model_engine["Model engines<br/>[llama_cpp.py]"]
  node_engine_setup["Engine setup<br/>[engine_install.py]"]
  node_hardware["Hardware detection<br/>[hardware.py]"]
  node_diffusion["Image and video"]
  node_rag["Search and RAG"]
end

subgraph group_training["Training and data"]
  node_dataset_recipes["Data recipes"]
  node_training_core["Fine-tuning"]
  node_export["Model export"]
end

subgraph group_connections["Tools and deployment"]
  node_agent_tools["Agents and tools"]
  node_remote_access["Remote access"]
  node_api_service["OpenAI-compatible API"]
  node_core_cli["Unsloth CLI<br/>[inference.py]"]
end

node_user(("User"))

node_user -.->|"opens app"| node_desktop
node_user -.->|"uses Studio"| node_studio_ui
node_studio_ui -.->|"requests services"| node_backend
node_backend -.->|"checks credentials"| node_auth
node_studio_ui -.->|"submits chat"| node_chat_api
node_chat_api -.->|"sends requests"| node_inference_routes
node_chat_history -->|"syncs messages"| node_chat_api
node_inference_routes -.->|"dispatches chat"| node_managed_chat
node_managed_chat -->|"streams generation"| node_model_engine
node_inference_routes -.->|"runs inference"| node_model_engine
node_model_engine -.->|"selects device"| node_hardware
node_backend -.->|"manages engines"| node_engine_setup
node_studio_ui -.->|"requests generation"| node_diffusion
node_studio_ui -.->|"uses retrieval"| node_rag
node_studio_ui -.->|"builds datasets"| node_dataset_recipes
node_dataset_recipes -.->|"prepares data"| node_training_core
node_studio_ui -.->|"starts training"| node_training_core
node_training_core -.->|"exports models"| node_export
node_studio_ui -.->|"uses tools"| node_agent_tools
node_agent_tools -.->|"uses local models"| node_model_engine
node_user -.->|"runs CLI"| node_core_cli
node_model_engine -.->|"serves remotely"| node_remote_access
node_model_engine -.->|"serves API"| node_api_service

click node_desktop "https://github.com/unslothai/unsloth/blob/main/studio/src-tauri/src/main.rs"
click node_studio_ui "https://github.com/unslothai/unsloth/tree/main/studio/frontend/src/features"
click node_auth "https://github.com/unslothai/unsloth/blob/main/studio/backend/auth/storage.py"
click node_chat_api "https://github.com/unslothai/unsloth/blob/main/studio/frontend/src/features/chat/api/chat-api.ts"
click node_chat_history "https://github.com/unslothai/unsloth/blob/main/studio/frontend/src/features/chat/utils/chat-history-storage.ts"
click node_backend "https://github.com/unslothai/unsloth/blob/main/studio/backend/main.py"
click node_inference_routes "https://github.com/unslothai/unsloth/blob/main/studio/backend/routes/inference.py"
click node_managed_chat "https://github.com/unslothai/unsloth/blob/main/studio/backend/routes/managed_engine_chat.py"
click node_model_engine "https://github.com/unslothai/unsloth/blob/main/studio/backend/core/inference/llama_cpp.py"
click node_engine_setup "https://github.com/unslothai/unsloth/blob/main/studio/backend/core/inference/engine_install.py"
click node_hardware "https://github.com/unslothai/unsloth/blob/main/studio/backend/utils/hardware/hardware.py"
click node_diffusion "https://github.com/unslothai/unsloth/tree/main/studio/backend/core/inference"
click node_rag "https://github.com/unslothai/unsloth/tree/main/studio/backend/core/rag"
click node_dataset_recipes "https://github.com/unslothai/unsloth/tree/main/studio/backend/core/data_recipe"
click node_training_core "https://github.com/unslothai/unsloth/tree/main/unsloth"
click node_export "https://github.com/unslothai/unsloth/tree/main/studio/backend/core/export"
click node_agent_tools "https://github.com/unslothai/unsloth/tree/main/studio/backend/core/inference"
click node_remote_access "https://github.com/unslothai/unsloth/blob/main/studio/backend/cloudflare_tunnel.py"
click node_api_service "https://github.com/unslothai/unsloth/tree/main/studio/backend/routes"
click node_core_cli "https://github.com/unslothai/unsloth/blob/main/unsloth_cli/commands/inference.py"

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_desktop,node_studio_ui,node_auth,node_chat_api,node_chat_history,node_user toneBlue
class node_backend,node_inference_routes,node_managed_chat,node_model_engine,node_engine_setup,node_hardware,node_diffusion,node_rag toneAmber
class node_dataset_recipes,node_training_core,node_export toneMint
class node_agent_tools,node_remote_access,node_api_service,node_core_cli toneRose
```

## Components

### Studio application

- [Desktop shell](https://github.com/unslothai/unsloth/blob/main/studio/src-tauri/src/main.rs): `studio/src-tauri/src/main.rs`
- [Studio interface](https://github.com/unslothai/unsloth/tree/main/studio/frontend/src/features): `studio/frontend/src/features`
- [Accounts and keys](https://github.com/unslothai/unsloth/blob/main/studio/backend/auth/storage.py): `studio/backend/auth/storage.py`
- [Chat API](https://github.com/unslothai/unsloth/blob/main/studio/frontend/src/features/chat/api/chat-api.ts): `studio/frontend/src/features/chat/api/chat-api.ts`
- [Chat history](https://github.com/unslothai/unsloth/blob/main/studio/frontend/src/features/chat/utils/chat-history-storage.ts): `studio/frontend/src/features/chat/utils/chat-history-storage.ts`

### Model runtime

- [Studio backend](https://github.com/unslothai/unsloth/blob/main/studio/backend/main.py): `studio/backend/main.py`
- [Inference routes](https://github.com/unslothai/unsloth/blob/main/studio/backend/routes/inference.py): `studio/backend/routes/inference.py`
- [Managed chat](https://github.com/unslothai/unsloth/blob/main/studio/backend/routes/managed_engine_chat.py): `studio/backend/routes/managed_engine_chat.py`
- [Model engines](https://github.com/unslothai/unsloth/blob/main/studio/backend/core/inference/llama_cpp.py): `studio/backend/core/inference/llama_cpp.py`
- [Engine setup](https://github.com/unslothai/unsloth/blob/main/studio/backend/core/inference/engine_install.py): `studio/backend/core/inference/engine_install.py`
- [Hardware detection](https://github.com/unslothai/unsloth/blob/main/studio/backend/utils/hardware/hardware.py): `studio/backend/utils/hardware/hardware.py`
- [Image and video](https://github.com/unslothai/unsloth/tree/main/studio/backend/core/inference): `studio/backend/core/inference`
- [Search and RAG](https://github.com/unslothai/unsloth/tree/main/studio/backend/core/rag): `studio/backend/core/rag`

### Training and data

- [Data recipes](https://github.com/unslothai/unsloth/tree/main/studio/backend/core/data_recipe): `studio/backend/core/data_recipe`
- [Fine-tuning](https://github.com/unslothai/unsloth/tree/main/unsloth): `unsloth`
- [Model export](https://github.com/unslothai/unsloth/tree/main/studio/backend/core/export): `studio/backend/core/export`

### Tools and deployment

- [Agents and tools](https://github.com/unslothai/unsloth/tree/main/studio/backend/core/inference): `studio/backend/core/inference`
- [Remote access](https://github.com/unslothai/unsloth/blob/main/studio/backend/cloudflare_tunnel.py): `studio/backend/cloudflare_tunnel.py`
- [OpenAI-compatible API](https://github.com/unslothai/unsloth/tree/main/studio/backend/routes): `studio/backend/routes`
- [Unsloth CLI](https://github.com/unslothai/unsloth/blob/main/unsloth_cli/commands/inference.py): `unsloth_cli/commands/inference.py`

### Other components

- **User**

## Connections

- User → Desktop shell: opens app (evidence: `README.md`)
- User → Studio interface: uses Studio (evidence: `README.md`)
- Studio interface → Studio backend: requests services
- Studio backend → Accounts and keys: checks credentials
- Studio interface → Chat API: submits chat (evidence: `studio/frontend/src/features/chat/prompt-storage/prompt-storage-dialog.tsx`)
- Chat API → Inference routes: sends requests
- Chat history → Chat API: syncs messages (evidence: `studio/frontend/src/features/chat/utils/chat-history-storage.ts`)
- Inference routes → Managed chat: dispatches chat (evidence: `studio/backend/routes/managed_engine_chat.py`)
- Managed chat → Model engines: streams generation (evidence: `studio/backend/routes/managed_engine_chat.py`)
- Inference routes → Model engines: runs inference
- Model engines → Hardware detection: selects device (evidence: `studio/backend/utils/hardware/hardware.py`)
- Studio backend → Engine setup: manages engines
- Studio interface → Image and video: requests generation (evidence: `README.md`)
- Studio interface → Search and RAG: uses retrieval (evidence: `README.md`)
- Studio interface → Data recipes: builds datasets (evidence: `README.md`)
- Data recipes → Fine-tuning: prepares data
- Studio interface → Fine-tuning: starts training (evidence: `README.md`)
- Fine-tuning → Model export: exports models (evidence: `README.md`)
- Studio interface → Agents and tools: uses tools (evidence: `README.md`)
- Agents and tools → Model engines: uses local models (evidence: `README.md`)
- User → Unsloth CLI: runs CLI (evidence: `README.md`)
- Model engines → Remote access: serves remotely (evidence: `README.md`)
- Model engines → OpenAI-compatible API: serves API (evidence: `README.md`)
