# bemor187/garlic-llm architecture

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

- Interactive diagram: https://gitdiagram.com/bemor187/garlic-llm
- Repository: https://github.com/bemor187/garlic-llm

## Overview

Garlic LLM is an offline PS4 chat application that runs Qwen3.5 on the console GPU, with voice, dictation, Python execution, and an optional network API. The principal workflow is controller or API input → tokenization → model inference → displayed or spoken output. README statements establish several feature links; sampled source confirms key GPU dispatch, UI ownership, and embedded MicroPython behavior. Unsampled speech and API implementation details are represented only at the documented subsystem level.

Main entry points: [`chat/main.c`](https://github.com/bemor187/garlic-llm/blob/main/chat/main.c) (Chat coordinator), [`chat/engine.c`](https://github.com/bemor187/garlic-llm/blob/main/chat/engine.c) (Qwen engine), [`chat/api.c`](https://github.com/bemor187/garlic-llm/blob/main/chat/api.c) (HTTP API), [`chat/py/mp/port/embed_util.c`](https://github.com/bemor187/garlic-llm/blob/main/chat/py/mp/port/embed_util.c) (MicroPython embed)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_interaction["Chat interaction"]
  node_ui["Controller UI<br/>[ui.c]"]
  node_app["Chat coordinator<br/>[main.c]"]
  node_api["HTTP API<br/>[api.c]"]
  node_api_protocol["API protocol<br/>[api_proto.c]"]
end

subgraph group_inference["Model inference"]
  node_tokenizer["Tokenizer<br/>[tokenizer.c]"]
  node_engine["Qwen engine<br/>[engine.c]"]
  node_gpu_kernels["GPU kernels"]
  node_weight_format["Q4 weights<br/>[q4.py]"]
end

subgraph group_speech["Speech features"]
  node_dictation["Speech recognition<br/>[speech_text.c]"]
  node_speech_normalization["Speech normalization<br/>[speech_norm.c]"]
  node_voice_engine["Voice synthesis<br/>[engine.c]"]
  node_audio["Audio output<br/>[audio_out.c]"]
end

subgraph group_runtime["Embedded runtime"]
  node_python_runner["Python runner<br/>[pyrun.c]"]
  node_micropython_embed["MicroPython embed<br/>[embed_util.c]"]
  node_python_compiler["Python compiler<br/>[compile.c]"]
  node_python_runtime["Python runtime<br/>[runtime.c]"]
  node_string_extensions["String extensions<br/>[garlic_str.c]"]
end

node_user(("PS4 user"))
node_api_client(("API client"))

node_user -->|"enters prompt"| node_ui
node_ui -->|"routes input"| node_app
node_app -->|"encodes text"| node_tokenizer
node_app -->|"requests generation"| node_engine
node_engine -->|"dispatches kernels"| node_gpu_kernels
node_weight_format -.->|"stores model weights"| node_engine
node_engine -->|"returns tokens"| node_app
node_app -->|"shows reply"| node_ui
node_user -->|"speaks prompt"| node_dictation
node_app -.->|"uses dictation"| node_dictation
node_dictation -->|"normalizes text"| node_speech_normalization
node_app -->|"requests speech"| node_voice_engine
node_voice_engine -->|"produces audio"| node_audio
node_audio -->|"plays response"| node_user
node_user -.->|"submits request"| node_api_client
node_api_client -->|"sends HTTP"| node_api
node_api -.->|"uses protocol"| node_api_protocol
node_api -->|"queues generation"| node_app
node_app -->|"runs generated code"| node_python_runner
node_python_runner -.->|"executes script"| node_micropython_embed
node_micropython_embed -->|"compiles source"| node_python_compiler
node_micropython_embed -->|"initializes runtime"| node_python_runtime
node_python_compiler -.->|"emits executable code"| node_python_runtime
node_string_extensions -.->|"extends strings"| node_python_runtime

click node_ui "https://github.com/bemor187/garlic-llm/blob/main/chat/ui.c"
click node_app "https://github.com/bemor187/garlic-llm/blob/main/chat/main.c"
click node_tokenizer "https://github.com/bemor187/garlic-llm/blob/main/chat/tokenizer.c"
click node_engine "https://github.com/bemor187/garlic-llm/blob/main/chat/engine.c"
click node_gpu_kernels "https://github.com/bemor187/garlic-llm/tree/main/shaders"
click node_weight_format "https://github.com/bemor187/garlic-llm/blob/main/pc/q4.py"
click node_api "https://github.com/bemor187/garlic-llm/blob/main/chat/api.c"
click node_api_protocol "https://github.com/bemor187/garlic-llm/blob/main/chat/api_proto.c"
click node_dictation "https://github.com/bemor187/garlic-llm/blob/main/chat/speech_text.c"
click node_speech_normalization "https://github.com/bemor187/garlic-llm/blob/main/chat/speech_norm.c"
click node_voice_engine "https://github.com/bemor187/garlic-llm/blob/main/chat/engine.c"
click node_audio "https://github.com/bemor187/garlic-llm/blob/main/chat/audio_out.c"
click node_python_runner "https://github.com/bemor187/garlic-llm/blob/main/chat/pyrun.c"
click node_micropython_embed "https://github.com/bemor187/garlic-llm/blob/main/chat/py/mp/port/embed_util.c"
click node_python_compiler "https://github.com/bemor187/garlic-llm/blob/main/chat/py/mp/py/compile.c"
click node_python_runtime "https://github.com/bemor187/garlic-llm/blob/main/chat/py/mp/py/runtime.c"
click node_string_extensions "https://github.com/bemor187/garlic-llm/blob/main/chat/py/garlic_str.c"

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_ui,node_app,node_api,node_api_protocol,node_user,node_api_client toneBlue
class node_tokenizer,node_engine,node_gpu_kernels,node_weight_format toneAmber
class node_dictation,node_speech_normalization,node_voice_engine,node_audio toneMint
class node_python_runner,node_micropython_embed,node_python_compiler,node_python_runtime,node_string_extensions toneRose
```

## Components

### Chat interaction

- [Controller UI](https://github.com/bemor187/garlic-llm/blob/main/chat/ui.c): `chat/ui.c`
- [Chat coordinator](https://github.com/bemor187/garlic-llm/blob/main/chat/main.c): `chat/main.c`
- [HTTP API](https://github.com/bemor187/garlic-llm/blob/main/chat/api.c): `chat/api.c`
- [API protocol](https://github.com/bemor187/garlic-llm/blob/main/chat/api_proto.c): `chat/api_proto.c`

### Model inference

- [Tokenizer](https://github.com/bemor187/garlic-llm/blob/main/chat/tokenizer.c): `chat/tokenizer.c`
- [Qwen engine](https://github.com/bemor187/garlic-llm/blob/main/chat/engine.c): `chat/engine.c`
- [GPU kernels](https://github.com/bemor187/garlic-llm/tree/main/shaders): `shaders`
- [Q4 weights](https://github.com/bemor187/garlic-llm/blob/main/pc/q4.py): `pc/q4.py`

### Speech features

- [Speech recognition](https://github.com/bemor187/garlic-llm/blob/main/chat/speech_text.c): `chat/speech_text.c`
- [Speech normalization](https://github.com/bemor187/garlic-llm/blob/main/chat/speech_norm.c): `chat/speech_norm.c`
- [Voice synthesis](https://github.com/bemor187/garlic-llm/blob/main/chat/engine.c): `chat/engine.c`
- [Audio output](https://github.com/bemor187/garlic-llm/blob/main/chat/audio_out.c): `chat/audio_out.c`

### Embedded runtime

- [Python runner](https://github.com/bemor187/garlic-llm/blob/main/chat/pyrun.c): `chat/pyrun.c`
- [MicroPython embed](https://github.com/bemor187/garlic-llm/blob/main/chat/py/mp/port/embed_util.c): `chat/py/mp/port/embed_util.c`
- [Python compiler](https://github.com/bemor187/garlic-llm/blob/main/chat/py/mp/py/compile.c): `chat/py/mp/py/compile.c`
- [Python runtime](https://github.com/bemor187/garlic-llm/blob/main/chat/py/mp/py/runtime.c): `chat/py/mp/py/runtime.c`
- [String extensions](https://github.com/bemor187/garlic-llm/blob/main/chat/py/garlic_str.c): `chat/py/garlic_str.c`

### Other components

- **PS4 user**
- **API client**

## Connections

- PS4 user → Controller UI: enters prompt (evidence: `README.md`)
- Controller UI → Chat coordinator: routes input (evidence: `chat/main.c`)
- Chat coordinator → Tokenizer: encodes text (evidence: `README.md`)
- Chat coordinator → Qwen engine: requests generation (evidence: `README.md`)
- Qwen engine → GPU kernels: dispatches kernels (evidence: `README.md`)
- Q4 weights → Qwen engine: stores model weights
- Qwen engine → Chat coordinator: returns tokens (evidence: `README.md`)
- Chat coordinator → Controller UI: shows reply (evidence: `chat/main.c`)
- PS4 user → Speech recognition: speaks prompt (evidence: `README.md`)
- Chat coordinator → Speech recognition: uses dictation
- Speech recognition → Speech normalization: normalizes text (evidence: `chat/speech_norm.c`)
- Chat coordinator → Voice synthesis: requests speech (evidence: `README.md`)
- Voice synthesis → Audio output: produces audio (evidence: `README.md`)
- Audio output → PS4 user: plays response (evidence: `README.md`)
- PS4 user → API client: submits request
- API client → HTTP API: sends HTTP (evidence: `README.md`)
- HTTP API → API protocol: uses protocol
- HTTP API → Chat coordinator: queues generation (evidence: `chat/main.c`)
- Chat coordinator → Python runner: runs generated code (evidence: `README.md`)
- Python runner → MicroPython embed: executes script
- MicroPython embed → Python compiler: compiles source (evidence: `chat/py/mp/port/embed_util.c`)
- MicroPython embed → Python runtime: initializes runtime (evidence: `chat/py/mp/port/embed_util.c`)
- Python compiler → Python runtime: emits executable code
- String extensions → Python runtime: extends strings
