# mattey2026/unsloth architecture

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

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

## Overview

Unsloth is a desktop and web application for running, training, and deploying local AI models, with Unsloth Core as another interface. A typical Studio workflow starts with a user request, passes through backend routes to inference orchestration and a selected model engine, and returns generated output. The repository also has distinct model/dataset management, training, export, Data Recipes, RAG and research capabilities. Edges reflect the documented product flow and sampled engine behavior; many feature-specific route-to-service connections are not established by the excerpts and are omitted.

Main entry points: [`studio/backend/main.py`](https://github.com/mattey2026/unsloth/blob/main/studio/backend/main.py) (Backend API), [`studio/backend/core/inference/orchestrator.py`](https://github.com/mattey2026/unsloth/blob/main/studio/backend/core/inference/orchestrator.py) (Inference orchestration), [`studio/backend/routes/inference.py`](https://github.com/mattey2026/unsloth/blob/main/studio/backend/routes/inference.py) (Inference routes), [`studio/backend/core/inference/diffusion_engine_router.py`](https://github.com/mattey2026/unsloth/blob/main/studio/backend/core/inference/diffusion_engine_router.py) (Diffusion engine selection)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_studio["Studio interface"]
  node_frontend["Studio web UI"]
  node_api["Backend API<br/>[main.py]"]
end

subgraph group_models["Models and inference"]
  node_inference_route["Inference routes<br/>[inference.py]"]
  node_inference_core["Inference orchestration<br/>[orchestrator.py]"]
  node_diffusion_router["Diffusion engine selection"]
  node_diffusion_engine["Diffusion runtime<br/>[diffusion.py]"]
  node_sd_cpp_engine["Native diffusion engine<br/>[sd_cpp_engine.py]"]
  node_llama_runtime["Local LLM runtime<br/>[llama_cpp.py]"]
  node_hub_routes["Model and dataset routes"]
  node_hub_services["Hub services"]
  node_providers["Cloud providers<br/>[providers.py]"]
end

subgraph group_creation["Training and data"]
  node_training_routes["Training routes<br/>[training.py]"]
  node_training_core["Training runtime<br/>[training.py]"]
  node_recipe_routes["Data Recipe routes"]
  node_recipe_service["Data Recipe service<br/>[service.py]"]
  node_export_routes["Export routes<br/>[export.py]"]
  node_export_core["Export runtime<br/>[orchestrator.py]"]
end

subgraph group_knowledge["Knowledge and accounts"]
  node_rag_routes["RAG routes<br/>[rag.py]"]
  node_rag_core["RAG pipeline<br/>[ingestion.py]"]
  node_research_routes["Research routes<br/>[research_runs.py]"]
  node_auth["Authentication<br/>[authentication.py]"]
end

subgraph group_persistence["State and storage"]
  node_model_store[("Model files and caches")]
  node_auth_store[("Auth database<br/>[storage.py]")]
  node_chat_store[("Chat history storage<br/>[studio_db.py]")]
end

node_user(("User"))
node_external_model{{"Model provider"}}

node_user -->|"uses"| node_frontend
node_frontend -->|"sends requests"| node_api
node_api -->|"dispatches"| node_inference_route
node_inference_route -->|"runs inference"| node_inference_core
node_inference_core -->|"runs local LLM"| node_llama_runtime
node_inference_core -->|"selects engine"| node_diffusion_router
node_diffusion_router -->|"selects GPU engine"| node_diffusion_engine
node_diffusion_router -->|"selects native engine"| node_sd_cpp_engine
node_inference_route -->|"returns output"| node_frontend
node_api -->|"dispatches"| node_hub_routes
node_hub_routes -->|"handles requests"| node_hub_services
node_hub_services -->|"reads and writes"| node_model_store
node_api -->|"dispatches"| node_training_routes
node_training_routes -->|"starts training"| node_training_core
node_api -->|"dispatches"| node_recipe_routes
node_recipe_routes -->|"handles recipes"| node_recipe_service
node_api -->|"dispatches"| node_export_routes
node_export_routes -->|"starts export"| node_export_core
node_api -->|"dispatches"| node_rag_routes
node_rag_routes -->|"ingests documents"| node_rag_core
node_api -->|"dispatches"| node_research_routes
node_api -->|"authenticates"| node_auth
node_auth -->|"reads and writes"| node_auth_store
node_inference_core -.->|"persists conversations"| node_chat_store
node_inference_core -.->|"uses optional providers"| node_providers
node_providers -.->|"requests inference"| node_external_model

click node_frontend "https://github.com/mattey2026/unsloth/tree/main/studio/frontend/src"
click node_api "https://github.com/mattey2026/unsloth/blob/main/studio/backend/main.py"
click node_inference_route "https://github.com/mattey2026/unsloth/blob/main/studio/backend/routes/inference.py"
click node_inference_core "https://github.com/mattey2026/unsloth/blob/main/studio/backend/core/inference/orchestrator.py"
click node_diffusion_router "https://github.com/mattey2026/unsloth/blob/main/studio/backend/core/inference/diffusion_engine_router.py"
click node_diffusion_engine "https://github.com/mattey2026/unsloth/blob/main/studio/backend/core/inference/diffusion.py"
click node_sd_cpp_engine "https://github.com/mattey2026/unsloth/blob/main/studio/backend/core/inference/sd_cpp_engine.py"
click node_llama_runtime "https://github.com/mattey2026/unsloth/blob/main/studio/backend/core/inference/llama_cpp.py"
click node_hub_routes "https://github.com/mattey2026/unsloth/tree/main/studio/backend/hub/routes"
click node_hub_services "https://github.com/mattey2026/unsloth/tree/main/studio/backend/hub/services"
click node_model_store "https://github.com/mattey2026/unsloth/tree/main/studio/backend/hub/storage"
click node_training_routes "https://github.com/mattey2026/unsloth/blob/main/studio/backend/routes/training.py"
click node_training_core "https://github.com/mattey2026/unsloth/blob/main/studio/backend/core/training/training.py"
click node_recipe_routes "https://github.com/mattey2026/unsloth/tree/main/studio/backend/routes/data_recipe"
click node_recipe_service "https://github.com/mattey2026/unsloth/blob/main/studio/backend/core/data_recipe/service.py"
click node_export_routes "https://github.com/mattey2026/unsloth/blob/main/studio/backend/routes/export.py"
click node_export_core "https://github.com/mattey2026/unsloth/blob/main/studio/backend/core/export/orchestrator.py"
click node_rag_routes "https://github.com/mattey2026/unsloth/blob/main/studio/backend/routes/rag.py"
click node_rag_core "https://github.com/mattey2026/unsloth/blob/main/studio/backend/core/rag/ingestion.py"
click node_research_routes "https://github.com/mattey2026/unsloth/blob/main/studio/backend/routes/research_runs.py"
click node_auth "https://github.com/mattey2026/unsloth/blob/main/studio/backend/auth/authentication.py"
click node_auth_store "https://github.com/mattey2026/unsloth/blob/main/studio/backend/auth/storage.py"
click node_chat_store "https://github.com/mattey2026/unsloth/blob/main/studio/backend/storage/studio_db.py"
click node_providers "https://github.com/mattey2026/unsloth/blob/main/studio/backend/core/inference/providers.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_frontend,node_api,node_user toneBlue
class node_inference_route,node_inference_core,node_diffusion_router,node_diffusion_engine,node_sd_cpp_engine,node_llama_runtime,node_hub_routes,node_hub_services,node_providers toneAmber
class node_training_routes,node_training_core,node_recipe_routes,node_recipe_service,node_export_routes,node_export_core toneMint
class node_rag_routes,node_rag_core,node_research_routes,node_auth toneRose
class node_model_store,node_auth_store,node_chat_store,node_external_model toneIndigo
```

## Components

### Studio interface

- [Studio web UI](https://github.com/mattey2026/unsloth/tree/main/studio/frontend/src): `studio/frontend/src`
- [Backend API](https://github.com/mattey2026/unsloth/blob/main/studio/backend/main.py): `studio/backend/main.py`

### Models and inference

- [Inference routes](https://github.com/mattey2026/unsloth/blob/main/studio/backend/routes/inference.py): `studio/backend/routes/inference.py`
- [Inference orchestration](https://github.com/mattey2026/unsloth/blob/main/studio/backend/core/inference/orchestrator.py): `studio/backend/core/inference/orchestrator.py`
- [Diffusion engine selection](https://github.com/mattey2026/unsloth/blob/main/studio/backend/core/inference/diffusion_engine_router.py): `studio/backend/core/inference/diffusion_engine_router.py`
- [Diffusion runtime](https://github.com/mattey2026/unsloth/blob/main/studio/backend/core/inference/diffusion.py): `studio/backend/core/inference/diffusion.py`
- [Native diffusion engine](https://github.com/mattey2026/unsloth/blob/main/studio/backend/core/inference/sd_cpp_engine.py): `studio/backend/core/inference/sd_cpp_engine.py`
- [Local LLM runtime](https://github.com/mattey2026/unsloth/blob/main/studio/backend/core/inference/llama_cpp.py): `studio/backend/core/inference/llama_cpp.py`
- [Model and dataset routes](https://github.com/mattey2026/unsloth/tree/main/studio/backend/hub/routes): `studio/backend/hub/routes`
- [Hub services](https://github.com/mattey2026/unsloth/tree/main/studio/backend/hub/services): `studio/backend/hub/services`
- [Cloud providers](https://github.com/mattey2026/unsloth/blob/main/studio/backend/core/inference/providers.py): `studio/backend/core/inference/providers.py`

### Training and data

- [Training routes](https://github.com/mattey2026/unsloth/blob/main/studio/backend/routes/training.py): `studio/backend/routes/training.py`
- [Training runtime](https://github.com/mattey2026/unsloth/blob/main/studio/backend/core/training/training.py): `studio/backend/core/training/training.py`
- [Data Recipe routes](https://github.com/mattey2026/unsloth/tree/main/studio/backend/routes/data_recipe): `studio/backend/routes/data_recipe`
- [Data Recipe service](https://github.com/mattey2026/unsloth/blob/main/studio/backend/core/data_recipe/service.py): `studio/backend/core/data_recipe/service.py`
- [Export routes](https://github.com/mattey2026/unsloth/blob/main/studio/backend/routes/export.py): `studio/backend/routes/export.py`
- [Export runtime](https://github.com/mattey2026/unsloth/blob/main/studio/backend/core/export/orchestrator.py): `studio/backend/core/export/orchestrator.py`

### Knowledge and accounts

- [RAG routes](https://github.com/mattey2026/unsloth/blob/main/studio/backend/routes/rag.py): `studio/backend/routes/rag.py`
- [RAG pipeline](https://github.com/mattey2026/unsloth/blob/main/studio/backend/core/rag/ingestion.py): `studio/backend/core/rag/ingestion.py`
- [Research routes](https://github.com/mattey2026/unsloth/blob/main/studio/backend/routes/research_runs.py): `studio/backend/routes/research_runs.py`
- [Authentication](https://github.com/mattey2026/unsloth/blob/main/studio/backend/auth/authentication.py): `studio/backend/auth/authentication.py`

### State and storage

- [Model files and caches](https://github.com/mattey2026/unsloth/tree/main/studio/backend/hub/storage): `studio/backend/hub/storage`
- [Auth database](https://github.com/mattey2026/unsloth/blob/main/studio/backend/auth/storage.py): `studio/backend/auth/storage.py`
- [Chat history storage](https://github.com/mattey2026/unsloth/blob/main/studio/backend/storage/studio_db.py): `studio/backend/storage/studio_db.py`

### Other components

- **User**
- **Model provider**

## Connections

- User → Studio web UI: uses
- Studio web UI → Backend API: sends requests
- Backend API → Inference routes: dispatches
- Inference routes → Inference orchestration: runs inference
- Inference orchestration → Local LLM runtime: runs local LLM
- Inference orchestration → Diffusion engine selection: selects engine
- Diffusion engine selection → Diffusion runtime: selects GPU engine
- Diffusion engine selection → Native diffusion engine: selects native engine
- Inference routes → Studio web UI: returns output
- Backend API → Model and dataset routes: dispatches
- Model and dataset routes → Hub services: handles requests
- Hub services → Model files and caches: reads and writes
- Backend API → Training routes: dispatches
- Training routes → Training runtime: starts training
- Backend API → Data Recipe routes: dispatches
- Data Recipe routes → Data Recipe service: handles recipes
- Backend API → Export routes: dispatches
- Export routes → Export runtime: starts export
- Backend API → RAG routes: dispatches
- RAG routes → RAG pipeline: ingests documents
- Backend API → Research routes: dispatches
- Backend API → Authentication: authenticates
- Authentication → Auth database: reads and writes
- Inference orchestration → Chat history storage: persists conversations
- Inference orchestration → Cloud providers: uses optional providers
- Cloud providers → Model provider: requests inference
