# cocktailpeanut/dalai architecture

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

- Interactive diagram: https://gitdiagram.com/cocktailpeanut/dalai
- Repository: https://github.com/cocktailpeanut/dalai

## Overview

Dalai is a local LLaMA/Alpaca runner with model installation, a web UI, and JavaScript/Socket.io APIs. The main workflow is to install a model, launch the server, and send prompts for streamed inference from the local model executable. The graph also preserves the documented programmatic and remote API capabilities. Some central orchestration code is excerpted only in part, so uncertain engine-dispatch relationships are shown as unverified rather than asserted.

Main entry points: [`index.js`](https://github.com/cocktailpeanut/dalai/blob/main/index.js) (Dalai core), [`bin/web/index.js`](https://github.com/cocktailpeanut/dalai/blob/main/bin/web/index.js) (Web server), [`llama.js`](https://github.com/cocktailpeanut/dalai/blob/main/llama.js) (LLaMA engine), [`alpaca.js`](https://github.com/cocktailpeanut/dalai/blob/main/alpaca.js) (Alpaca engine)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["Entry points"]
  node_cli["Command CLI<br/>[cli.js]"]
  node_dalai["Dalai core<br/>[index.js]"]
end

subgraph group_models["Model provisioning"]
  node_llama["LLaMA engine<br/>[llama.js]"]
  node_alpaca["Alpaca engine<br/>[alpaca.js]"]
  node_torrent["Torrent downloader<br/>[torrent.js]"]
  node_modelstore[("Local model files")]
  node_model_sources(("Model sources"))
end

subgraph group_runtime["Inference runtime"]
  node_native_runner["Model executable"]
end

subgraph group_interfaces["User interfaces"]
  node_webserver["Web server<br/>[index.js]"]
  node_webui["Web UI<br/>[index.ejs]"]
  node_promptfiles["Prompt files"]
  node_socket_client["Socket.io client<br/>[index.js]"]
end

node_user(("Operator"))
node_browser(("Browser user"))

node_user -->|"runs commands"| node_cli
node_cli -->|"calls methods"| node_dalai
node_cli -->|"starts server"| node_webserver
node_dalai -.->|"dispatches install"| node_llama
node_dalai -.->|"dispatches install"| node_alpaca
node_llama -->|"downloads weights"| node_model_sources
node_alpaca -->|"downloads weights"| node_model_sources
node_llama -->|"writes models"| node_modelstore
node_alpaca -->|"writes models"| node_modelstore
node_llama -->|"uses process runner"| node_dalai
node_alpaca -->|"uses process runner"| node_dalai
node_browser -->|"opens UI"| node_webserver
node_webserver -->|"configures API"| node_dalai
node_webserver -->|"renders page"| node_webui
node_webserver -->|"reads prompts"| node_promptfiles
node_dalai -->|"executes inference"| node_native_runner
node_dalai -->|"connects remotely"| node_socket_client
node_torrent -->|"downloads files"| node_modelstore

click node_cli "https://github.com/cocktailpeanut/dalai/blob/main/bin/cli.js"
click node_dalai "https://github.com/cocktailpeanut/dalai/blob/main/index.js"
click node_llama "https://github.com/cocktailpeanut/dalai/blob/main/llama.js"
click node_alpaca "https://github.com/cocktailpeanut/dalai/blob/main/alpaca.js"
click node_torrent "https://github.com/cocktailpeanut/dalai/blob/main/torrent.js"
click node_webserver "https://github.com/cocktailpeanut/dalai/blob/main/bin/web/index.js"
click node_webui "https://github.com/cocktailpeanut/dalai/blob/main/bin/web/views/index.ejs"
click node_promptfiles "https://github.com/cocktailpeanut/dalai/tree/main/bin/web/prompts"
click node_socket_client "https://github.com/cocktailpeanut/dalai/blob/main/index.js"

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_dalai,node_browser toneBlue
class node_llama,node_alpaca,node_torrent,node_modelstore,node_model_sources toneAmber
class node_native_runner toneMint
class node_webserver,node_webui,node_promptfiles,node_socket_client toneRose
class node_user toneIndigo
```

## Components

### Entry points

- [Command CLI](https://github.com/cocktailpeanut/dalai/blob/main/bin/cli.js): `bin/cli.js`
- [Dalai core](https://github.com/cocktailpeanut/dalai/blob/main/index.js): `index.js`

### Model provisioning

- [LLaMA engine](https://github.com/cocktailpeanut/dalai/blob/main/llama.js): `llama.js`
- [Alpaca engine](https://github.com/cocktailpeanut/dalai/blob/main/alpaca.js): `alpaca.js`
- [Torrent downloader](https://github.com/cocktailpeanut/dalai/blob/main/torrent.js): `torrent.js`
- **Local model files**
- **Model sources**

### Inference runtime

- **Model executable**

### User interfaces

- [Web server](https://github.com/cocktailpeanut/dalai/blob/main/bin/web/index.js): `bin/web/index.js`
- [Web UI](https://github.com/cocktailpeanut/dalai/blob/main/bin/web/views/index.ejs): `bin/web/views/index.ejs`
- [Prompt files](https://github.com/cocktailpeanut/dalai/tree/main/bin/web/prompts): `bin/web/prompts`
- [Socket.io client](https://github.com/cocktailpeanut/dalai/blob/main/index.js): `index.js`

### Other components

- **Operator**
- **Browser user**

## Connections

- Operator → Command CLI: runs commands (evidence: `bin/cli.js`)
- Command CLI → Dalai core: calls methods (evidence: `bin/cli.js`)
- Command CLI → Web server: starts server (evidence: `bin/cli.js`)
- Dalai core → LLaMA engine: dispatches install (evidence: `index.js`)
- Dalai core → Alpaca engine: dispatches install (evidence: `index.js`)
- LLaMA engine → Model sources: downloads weights (evidence: `llama.js`)
- Alpaca engine → Model sources: downloads weights (evidence: `alpaca.js`)
- LLaMA engine → Local model files: writes models (evidence: `llama.js`)
- Alpaca engine → Local model files: writes models (evidence: `alpaca.js`)
- LLaMA engine → Dalai core: uses process runner (evidence: `llama.js`)
- Alpaca engine → Dalai core: uses process runner (evidence: `alpaca.js`)
- Browser user → Web server: opens UI
- Web server → Dalai core: configures API (evidence: `bin/web/index.js`)
- Web server → Web UI: renders page (evidence: `bin/web/index.js`)
- Web server → Prompt files: reads prompts (evidence: `bin/web/index.js`)
- Dalai core → Model executable: executes inference (evidence: `index.js`)
- Dalai core → Socket.io client: connects remotely (evidence: `index.js`)
- Torrent downloader → Local model files: downloads files (evidence: `torrent.js`)
