How azookey/azookey-desktop works
Purpose and Deployment
azooKey-Desktop is a macOS Japanese Input Method Editor (IME) using Zenzai neural kana-kanji conversion. It is packaged as an installable input source, with bundled language-model and GGUF inference resources. The Xcode app target is azooKeyMac/, while shared conversion logic and a separate converter process live in the Swift package under Core/.
Primary app lifecycle entry point: azooKeyMac/AppDelegate.swift. Input-method interaction begins in azooKeyMac/InputController/azooKeyMacInputController.swift. Distribution builds/install through install.sh and pkgbuild.sh.
Process Split and IPC Boundary
Conversion is isolated in a ConverterServer executable rather than performed directly in the input-method extension. Server startup is Core/Sources/ConverterServer/main.swift; ConverterSession.swift owns per-client conversion state. The server exposes snapshot, settings, and key-event operations through:
• Core/Sources/ConverterServer/ConverterServer+KeyEvent.swift
• Core/Sources/ConverterServer/ConverterServer+Snapshot.swift
• Core/Sources/Core/XPC/ConverterServerXPCProtocol.swift
The input controller consumes this service through azooKeyMac/InputController/ConverterServerClient.swift. This XPC boundary separates macOS text-client/UI concerns from model-backed stateful conversion and allows the server to run as a managed background process.
Input Event and Composition Pipeline
The input controller receives macOS keyboard events, maps them to core key representations, forwards conversion-relevant events to the server, then applies returned composition/candidate state to the host application. Key event adaptation and controller behavior are centered in:
• azooKeyMac/InputController/azooKeyMacInputController.swift
• azooKeyMac/InputController/NSEvent.swift
• Core/Sources/Core/InputUtils/KeyEventCore.swift
Core state transitions distinguish client-facing actions from user-editing actions via Core/Sources/Core/InputUtils/Actions/ClientAction.swift and Core/Sources/Core/InputUtils/Actions/UserAction.swift. Core/Sources/Core/InputUtils/InputState.swift represents conversion/composition state; SegmentsManager.swift manages segmented text, predictions, candidates, corrections, and selection.
Conversion Engine and Resources
The conversion stack is backed by bundled Zenzai resources under azooKeyMac/Resources/base_n5_lm and azooKeyMac/Resources/gguf (with additional model material supplied via Git submodules/LFS). The Core package orchestrates input segmentation and candidate presentation rather than embedding model resources directly:
• Core/Sources/Core/InputUtils/SegmentsManager.swift
• Core/Sources/Core/InputUtils/CandidatePresentationContext.swift
• Core/Sources/Core/InputUtils/InputLanguage.swift
Romaji/AZIK and punctuation/direct-input behavior are mediated by Core/Sources/Core/KeyMap/KeyMap.swift, Core/Sources/Core/InputUtils/OptionDirectInputResolver.swift, and configurable punctuation handling.
Candidate UI and Text Commitment
Candidate rendering is native macOS UI owned by the input-method target. The controller translates server snapshots into candidate-window state and commits selected or transformed text back through the InputMethodKit client boundary:
• azooKeyMac/InputController/CandidateWindow/BaseCandidateViewController.swift
• azooKeyMac/InputController/CandidateWindow/CandidateView.swift
• azooKeyMac/InputController/azooKeyMacInputController+SelectedTextTransform.swift
Window placement spans AppKit/CoreGraphics in azooKeyMac/InputController/WindowPositioning+CoreGraphics.swift, with shared positioning logic in Core/Sources/Core/Windows/WindowPositioning.swift.
Configuration, Personalization, and Dictionaries
Shared typed configuration is defined in Core/Sources/Core/Configs/Config.swift and persisted through config item types; app-private secrets use Keychain-oriented azooKeyMac/Configs/SecureConfigItem.swift. User dictionary storage/compilation is represented by:
• Core/Sources/Core/UserDictionary/CompiledUserDictionaryStore.swift
• Core/Sources/Core/UserDictionary/SystemUserDictionaryHelper.swift
Native configuration and editing windows expose these concerns, including user dictionaries and custom romaji tables: azooKeyMac/Windows/UserDictionaryEditorWindow.swift and azooKeyMac/Windows/RomajiTableEditorWindow.swift.
Optional LLM “Magic Conversion”
A separate magic-conversion layer supports LLM-assisted transformations. It abstracts providers in Core/Sources/Core/MagicConversion/AIBackend.swift, with clients for Apple Foundation Models and OpenAI:
• Core/Sources/Core/MagicConversion/FoundationModelsClient.swift
• Core/Sources/Core/MagicConversion/OpenAIClient.swift
Prompt UI and history are app-side in azooKeyMac/Windows/PromptInput/PromptInputWindow.swift and azooKeyMac/Windows/PromptInput/PromptInputView.swift; provider credentials are expected to remain on the app/secure-config side rather than crossing ordinary conversion state flows.
Main entry points: azooKeyMacInputController.swift Input controller · main.swift Converter server · ConverterServerClient.swift Converter client · ConverterSession.swift Conversion session
Components 23
macOS Input Method
Xcode target handling InputMethodKit integration and native UI.
- App lifecycle
azooKeyMac/AppDelegate.swift - Input controller · Receives host keyboard events and applies composition results.
azooKeyMac/InputController/azooKeyMacInputController.swift - macOS event adapter
azooKeyMac/InputController/NSEvent.swift - Converter client
azooKeyMac/InputController/ConverterServerClient.swift - Candidate window
azooKeyMac/InputController/CandidateWindow/BaseCandidateViewController.swift - Text commit & transform
azooKeyMac/InputController/azooKeyMacInputController+SelectedTextTransform.swift - Dictionary editor
azooKeyMac/Windows/UserDictionaryEditorWindow.swift
Converter Process
Managed background conversion service behind XPC.
- Converter server · Owns a stateful conversion session per client.
Core/Sources/ConverterServer/main.swift - Conversion session
Core/Sources/ConverterServer/ConverterSession.swift - Converter XPC protocol · Carries key events, snapshots, and settings.
Core/Sources/Core/XPC/ConverterServerXPCProtocol.swift - Server key-event API
Core/Sources/ConverterServer/ConverterServer+KeyEvent.swift - Server snapshot API
Core/Sources/ConverterServer/ConverterServer+Snapshot.swift
Core Conversion
Shared Swift package conversion state and input logic.
- Core key events
Core/Sources/Core/InputUtils/KeyEventCore.swift - Actions & input state · Separates client-facing actions from user editing actions.
Core/Sources/Core/InputUtils/InputState.swift - Segments manager · Manages segments, predictions, candidates, corrections, and selection.
Core/Sources/Core/InputUtils/SegmentsManager.swift - Key map & direct input
Core/Sources/Core/KeyMap/KeyMap.swift - Zenzai model resources · Language-model and inference assets bundled with the input source.
azooKeyMac/Resources/base_n5_lm
Configuration & Dictionaries
Persistent personalization and configuration concerns.
- Shared configuration
Core/Sources/Core/Configs/Config.swift - Compiled user dictionary
Core/Sources/Core/UserDictionary/CompiledUserDictionaryStore.swift - Secure credentials · Keeps provider credentials app-side.
azooKeyMac/Configs/SecureConfigItem.swift
Magic Conversion
Optional LLM-assisted text transformation.
- AI backend abstraction
Core/Sources/Core/MagicConversion/AIBackend.swift - OpenAI provider
Core/Sources/Core/MagicConversion/OpenAIClient.swift - Magic prompt UI
azooKeyMac/Windows/PromptInput/PromptInputWindow.swift
Connections 23
- App lifecycle → Input controller: starts input method
- Input controller → macOS event adapter: adapts macOS events
- macOS event adapter → Core key events: maps to core event
- Input controller → Converter client: forwards conversion events
- Converter client → Converter XPC protocol: uses
- Converter XPC protocol → Converter server: IPC boundary
- Converter server → Conversion session: creates
- Converter server → Server key-event API: serves
- Converter server → Server snapshot API: serves
- Server key-event API → Core key events: consumes
- Conversion session → Actions & input state: updates
- Actions & input state → Segments manager: drives
- Key map & direct input → Core key events: interprets input
- Segments manager → Zenzai model resources: uses conversion resources
- Server snapshot API → Converter client: returns composition state
- Converter client → Candidate window: updates candidates
- Input controller → Text commit & transform: commits selected text
- Shared configuration → Conversion session: applies settings
- Compiled user dictionary → Segments manager: supplies user entries
- Dictionary editor → Compiled user dictionary: edits
- Magic prompt UI → AI backend abstraction: requests transformation
- AI backend abstraction → OpenAI provider: provider implementation
- Secure credentials → OpenAI provider: provides credentials