lemonade

Lemonade Development

This guide covers everything you need to build, test, and contribute to Lemonade from source. Whether you’re fixing a bug, adding a feature, or just exploring the codebase, this document will help you get started.

Table of Contents

Components

Lemonade consists of these main executables:

Building from Source

Prerequisites

All Platforms:

Windows:

Linux:

Build Steps

A helper script is available that will set up the build environment on popular Linux distributions and macOS. This will prompt to install dependencies via native package managers and create the build directory.

Linux / macOS

./setup.sh

Windows

./setup.ps1

Build by running:

Linux / macOS

cmake --build --preset default

Windows

cmake --build --preset windows

Build Outputs

Building the Electron Desktop App (Optional)

The tray menu’s “Open app” option and the lemonade-server run command can launch the Electron desktop app. To include it in your build:

Build the Electron app using CMake (requires Node.js 20+):

Linux

cmake --build --preset default --target electron-app

Windows

cmake --build --preset windows --target electron-app

This will:

  1. Copy src/app to build/app-src (keeps source tree clean)
  2. Run npm install in build/app-src
  3. Build to build/app/linux-unpacked/ (Linux) or build/app/win-unpacked/ (Windows)

The tray app searches for the Electron app in these locations:

If not found, the “Open app” menu option is hidden but everything else works.

Building an AppImage (Linux Only)

To create a standalone AppImage package that can run on any Linux distribution:

cmake --build --preset default --target appimage

This will:

  1. Copy the Electron app source to a separate build directory
  2. Set the package.json version to match the CMake project version
  3. Install npm dependencies
  4. Build the renderer with production optimizations
  5. Package the application as an AppImage using electron-builder

The generated AppImage will be located in:

The AppImage is a self-contained executable that includes all dependencies and can be run on any Linux distribution without installation. Simply make it executable and run it:

chmod +x build/app-appimage/Lemonade-*.AppImage
./build/app-appimage/Lemonade-*.AppImage

Platform-Specific Notes

Windows:

Linux:

macOS (beta):

Building Installers

Windows Installer (WiX/MSI)

Prerequisites:

Building:

Using PowerShell script (recommended):

cd src\cpp
.\build_installer.ps1

Manual build using CMake:

cd src\cpp\build
cmake --build . --config Release --target wix_installer

Installer Output:

Creates lemonade-server-minimal.msi which:

Available Installers:

Installation:

For detailed installation instructions including silent install, custom directories, and all-users installation, see the Server Integration Guide.

Linux .deb Package (Debian/Ubuntu)

Prerequisites:

Building:

cd build
cpack

Package Output:

Creates lemonade-server_<VERSION>_amd64.deb (e.g., lemonade-server_9.0.3_amd64.deb) which:

Installation:

# Replace <VERSION> with the actual version (e.g., 9.0.0)
sudo apt install ./lemonade-server_<VERSION>_amd64.deb

Uninstallation:

sudo dpkg -r lemonade-server

Post-Installation:

The executables will be available in PATH:

lemonade-server --help
lemonade-router --help

# Start server in headless mode:
lemonade-server serve --no-tray

# Or just:
lemonade-server serve

Linux .rpm Package (Fedora, RHEL etc)

Very similar to the Debian instructions above with minor changes

Building:

cd build
cpack -G RPM

Package Output:

Creates lemonade-server-<VERSION>.x86_64.rpm (e.g., lemonade-server-9.1.2.x86_64.rpm) and resources are installed as per DEB version above

Installation:

# Replace <VERSION> with the actual version (e.g., 9.0.0)
sudo dnf install ./lemonade-server-<VERSION>.x86_64.rpm

Uninstallation:

sudo dnf remove lemonade-server

Post-Installation:

Same as .deb above

macOS:

Building from Source on MacOS for M-Series / arm64 Family

Macos Notary Tool Command

For access with P

xcrun notarytool store-credentials AC_PASSWORD --apple-id "[email protected]" --team-id "your-team-id" --private-key "/path/to/AuthKey_XXXXXX.p8"

or For access with API password

xcrun notarytool store-credentials AC_PASSWORD --apple-id "[email protected]" --team-id "your-team-id" --password ""

Get your team id at: https://developer.apple.com/account

Cmake build instructions

# Install Xcode command line tools
xcode-select --install

# Navigate to the C++ source directory
cd src/cpp

# Create and enter build directory
mkdir build
cd build

# Configure with CMake
cmake ..

# Build with all cores
cmake --build . --config Release -j

CMake Targets

The build system provides several CMake targets for different build configurations:

Building and Notarizing for Distribution

To build a notarized macOS installer for distribution:

  1. Prerequisites:
    • Apple Developer Program membership
    • Valid Developer ID Application and Installer certificates
    • App-specific password for notarization
    • Xcode command line tools
  2. Set Environment Variables:
    export DEVELOPER_ID_APPLICATION_IDENTITY="Developer ID Application: Your Name (TEAMID)"
    export DEVELOPER_ID_INSTALLER_IDENTITY="Developer ID Installer: Your Name (TEAMID)"
    export AC_PASSWORD="your-app-specific-password"
    
  3. Configure Notarization Keychain Profile:
    xcrun notarytool store-credentials "AC_PASSWORD" \
      --apple-id "[email protected]" \
      --team-id "YOURTEAMID" \
      --password "your-app-specific-password"
    
  4. Build and Notarize:
    cd src/cpp/build
    cmake --build . --config Release --target package-macos
    cmake --build . --config Release --target notarize_package
    

The notarization process will:

Note: The package is signed with hardened runtime entitlements during the build process for security.

Developer IDE & IDE Build Steps

Visual Studio Code Setup Guide

  1. Clone the repository into a blank folder locally on your computer.
  2. Open the folder in visual studio code.
  3. Install Dev Containers extension in Visual Studio Code by using control + p to open the command bar at the top of the IDE or if on mac with Cmd + p.
  4. Type “> Extensions: Install Extensions” which will open the Extensions side panel.
  5. in the extensions search type Dev Containers and install it.
  6. Once completed with the prior steps you may run command >Dev Containers: Open Workspace in Container or >Dev Containers: Open Folder in Container which you can do in the command bar in the IDE and it should reopen the visual studio code project.
  7. It will launch a docker and start building a new docker and then the project will open in visual studio code.

Build & Compile Options

  1. Assuming your VSCode IDE is open and the dev container is working.
  2. Go to the CMake plugin you may select the “Folder” that is where you currently want to build.
  3. Once done with that you may select which building toolkit you are using under Configure and then begin configure.
  4. Under Build, Test, Debug and/or Launch you may select whatever configuration you want to build, test, debug and/or launch.

Debug / Runtime / Console arguments

  1. You may find arguments which are passed through to the application you are debugging in .vscode/settings.json which will look like the following:
    "cmake.debugConfig": {
         "args": [
             "--llamacpp", "cpu"
         ]
     }
    
  2. If you want to debug lemonade-router you may pass –llamacpp cpu for cpu based tests.
  3. For lemonade-server you may pass serve as a argument as well.
The hard way - commands only.
  1. Now if you want to do it the hard way below are the commands in which you can run in the command dropdown in which you can see if you use the following keyboard shortcuts. cmd + p / control + p ```

Cmake: Select a Kit

Select a kit or Scan for kit. (Two options should be available gcc or clang)

Cmake: Configure

Optional commands are:

Cmake: Build Target

use this to select a cmake target to build

Cmake: Set Launch/Debug target

use this to select/set your cmake target you want to build/debug

This next command lets you debug

Cmake: Debug

This command lets you delete the cmake cache and reconfigure which is rarely needed.

Cmake: Delete Cache and Reconfigure ```

  1. Custom configurations for cmake are in the root directory under .vscode/settings.json in which you may set custom args for launching the debug in the json key cmake.debugConfig

Note

For running Lemonade as a containerized application (as an alternative to the MSI-based distribution), see DOCKER_GUIDE.md.

Code Structure

src/cpp/
├── build_installer.ps1         # Installer build script
├── CopyElectronApp.cmake       # CMake module to copy Electron app to build output
├── CPackRPM.cmake              # RPM packaging configuration
├── DOCKER_GUIDE.md             # Docker containerization guide
├── Extra-Models-Dir-Spec.md    # Extra models directory specification
├── Multi-Model-Spec.md         # Multi-model loading specification
├── postinst                    # Debian package post-install script
├── postinst-full               # Debian package post-install script (full version)
├── resources/                  # Configuration and data files (self-contained)
│   ├── backend_versions.json   # llama.cpp/whisper version configuration
│   ├── server_models.json      # Model registry (available models)
│   └── static/                 # Web UI assets
│       ├── index.html          # Server landing page (with template variables)
│       └── favicon.ico         # Site icon
│
├── installer/                  # WiX MSI installer (Windows)
│   ├── Product.wxs.in          # WiX installer definition template
│   ├── installer_banner_wix.bmp  # Left-side banner (493×312)
│   └── top_banner.bmp          # Top banner with lemon icon (493×58)
│
├── server/                     # Server implementation
│   ├── main.cpp                # Entry point, CLI routing
│   ├── server.cpp              # HTTP server (cpp-httplib)
│   ├── router.cpp              # Routes requests to backends
│   ├── model_manager.cpp       # Model registry, downloads, caching
│   ├── cli_parser.cpp          # Command-line argument parsing (CLI11)
│   ├── recipe_options.cpp      # Recipe option handling
│   ├── wrapped_server.cpp      # Base class for backend wrappers
│   ├── streaming_proxy.cpp     # Server-Sent Events for streaming
│   ├── system_info.cpp         # NPU/GPU device detection
│   ├── lemonade.manifest.in    # Windows manifest template
│   ├── version.rc              # Windows version resource
│   │
│   ├── backends/               # Model backend implementations
│   │   ├── backend_utils.cpp     # Shared backend utilities
│   │   ├── llamacpp_server.cpp   # Wraps llama.cpp for LLM inference (CPU/GPU)
│   │   ├── fastflowlm_server.cpp # Wraps FastFlowLM for NPU inference
│   │   ├── ryzenaiserver.cpp     # Wraps RyzenAI server for hybrid NPU
│   │   ├── sd_server.cpp         # Wraps Stable Diffusion for image generation
│   │   └── whisper_server.cpp    # Wraps whisper.cpp for audio transcription (CPU/NPU)
│   │
│   └── utils/                  # Utility functions
│       ├── http_client.cpp     # HTTP client using libcurl
│       ├── json_utils.cpp      # JSON file I/O
│       ├── process_manager.cpp # Cross-platform process management
│       ├── path_utils.cpp      # Path manipulation
│       ├── wmi_helper.cpp      # Windows WMI for NPU detection
│       └── wmi_helper.h        # WMI helper header
│
├── include/lemon/              # Public headers
│   ├── server.h                # HTTP server interface
│   ├── router.h                # Request routing
│   ├── model_manager.h         # Model management
│   ├── cli_parser.h            # CLI argument parsing
│   ├── recipe_options.h        # Recipe option definitions
│   ├── wrapped_server.h        # Backend wrapper base class
│   ├── streaming_proxy.h       # Streaming proxy
│   ├── system_info.h           # System information
│   ├── model_types.h           # Model type definitions
│   ├── audio_types.h           # Audio type definitions
│   ├── error_types.h           # Error type definitions
│   ├── server_capabilities.h   # Server capability definitions
│   ├── single_instance.h       # Single instance enforcement
│   ├── version.h.in            # Version header template
│   ├── backends/               # Backend headers
│   │   ├── backend_utils.h       # Backend utilities
│   │   ├── llamacpp_server.h     # LlamaCpp backend
│   │   ├── fastflowlm_server.h   # FastFlowLM backend
│   │   ├── ryzenaiserver.h       # RyzenAI backend
│   │   ├── sd_server.h           # Stable Diffusion backend
│   │   └── whisper_server.h      # Whisper backend
│   └── utils/                  # Utility headers
│       ├── http_client.h       # HTTP client
│       ├── json_utils.h        # JSON utilities
│       ├── process_manager.h   # Process management
│       |── path_utils.h        # Path utilities
|       |── network_beacon.h    # Helps broadcast a beacon on port 8000 to network multicast
│
└── tray/                       # System tray application
    ├── CMakeLists.txt          # Tray-specific build config
    ├── main.cpp                # Tray entry point (lemonade-server)
    ├── tray_launcher.cpp       # GUI launcher (lemonade-tray)
    ├── log-viewer.cpp          # Log file viewer (lemonade-log-viewer)
    ├── server_manager.cpp      # Manages lemonade-router process
    ├── tray_app.cpp            # Main tray application logic
    ├── lemonade-server.manifest.in  # Windows manifest template
    ├── version.rc              # Windows version resource
    └── platform/               # Platform-specific implementations
        ├── windows_tray.cpp    # Win32 system tray API
        ├── macos_tray.mm       # Objective-C++ NSStatusBar
        ├── linux_tray.cpp      # GTK/AppIndicator
        └── tray_factory.cpp    # Platform detection

Architecture Overview

Overview

The Lemonade Server C++ implementation uses a client-server architecture:

lemonade-router (Server Component)

A pure HTTP server that:

Key Layers:

Multi-Model Support:

lemonade-server (CLI Client Component)

A console application for terminal users:

Command Types:

lemonade-tray (GUI Launcher - Windows Only)

A minimal WIN32 GUI application for desktop users:

Client-Server Communication

The lemonade-server client communicates with lemonade-router server via HTTP:

The client automatically:

Single-Instance Protection:

Network Beacon based broadcasting:

Dependencies

All dependencies are automatically fetched by CMake via FetchContent:

Platform-specific SSL backends are used (Schannel on Windows, SecureTransport on macOS, OpenSSL on Linux).

Usage

lemonade-router (Server Only)

The lemonade-router executable is a pure HTTP server without any command-based interface:

# Start server with default options
./lemonade-router

# Start server with custom options
./lemonade-router --port 8080 --ctx-size 8192 --log-level debug

# Available options:
#   --port PORT              Port number (default: 8000)
#   --host HOST              Bind address (default: localhost)
#   --ctx-size SIZE          Context size (default: 4096)
#   --log-level LEVEL        Log level: critical, error, warning, info, debug, trace
#   --llamacpp BACKEND       LlamaCpp backend: vulkan, rocm, metal
#   --max-loaded-models N    Maximum models per type slot (default: 1)
#   --version, -v            Show version
#   --help, -h               Show help

lemonade-server.exe (Console CLI Client)

The lemonade-server executable is the command-line interface for terminal users:

# List available models
./lemonade-server list

# Pull a model
./lemonade-server pull Llama-3.2-1B-Instruct-CPU

# Delete a model
./lemonade-server delete Llama-3.2-1B-Instruct-CPU

# Check server status
./lemonade-server status

# Stop the server
./lemonade-server stop

# Run a model (starts persistent server with tray and opens browser)
./lemonade-server run Llama-3.2-1B-Instruct-CPU

# Start persistent server (with tray on Windows/macOS, headless on Linux)
./lemonade-server serve

# Start persistent server without tray (headless mode, explicit on all platforms)
./lemonade-server serve --no-tray

# Start server with custom options
./lemonade-server serve --port 8080 --ctx-size 8192

Available Options:

Note: lemonade-router is always launched with --log-level debug for optimal troubleshooting. Use --log-level debug on lemonade-server commands to see client-side debug output.

lemonade-tray.exe (GUI Tray Launcher - Windows Only)

The lemonade-tray executable is a simple GUI launcher for desktop users:

What it does:

  1. Finds lemonade-server.exe in the same directory
  2. Launches it with the serve command
  3. Exits immediately (server continues running with tray icon)

When to use:

System Tray Features (when running):

UI Improvements:

Logging and Console Output

When running lemonade-server.exe serve:

Log Viewer Features:

Testing

Basic Functionality Tests

Run the commands from the Usage section above to verify basic functionality.

Integration Tests

The C++ implementation is tested using the existing Python test suite.

Prerequisites:

Python integration tests (from test/ directory, ordered least to most complex):

Test File Description
server_cli.py CLI commands (version, list, pull, status, delete, serve, stop, run)
server_endpoints.py HTTP endpoints (health, models, pull, load, unload, system-info, stats)
server_llm.py LLM inference (chat completions, embeddings, reranking)
server_whisper.py Audio transcription (whisper models)
server_sd.py Image generation (Stable Diffusion, ~2-3 min per image on CPU)

Running tests:

# CLI tests (no inference backend needed)
python test/server_cli.py

# Endpoint tests (no inference backend needed)
python test/server_endpoints.py

# LLM tests (specify wrapped server and backend)
python test/server_llm.py --wrapped-server llamacpp --backend vulkan

# Audio transcription tests
python test/server_whisper.py

# Image generation tests (slow)
python test/server_sd.py

The tests auto-discover the server binary from the build directory. Use --server-binary to override if needed.

See the .github/workflows/ directory for CI/CD test configurations.

Note: The Python tests should now use lemonade-server.exe as the entry point since it provides the CLI interface.

Development

Code Style

Key Resources

License

This project is licensed under the Apache 2.0 License. All dependencies use permissive licenses (MIT, BSD, Apache 2.0, curl license).