|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +niinii is a Windows desktop application for glossing and translating Japanese text, primarily used for assisted reading of visual novels. It provides real-time text segmentation (via Ichiran), dictionary lookups (JMDict/KANJIDIC2), furigana display, and LLM-based translation. The UI is built with imgui-rs. |
| 8 | + |
| 9 | +## Build Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +# Build (requires vcpkg with freetype installed) |
| 13 | +# vcpkg install freetype:x64-windows-static-md |
| 14 | +cargo build --release |
| 15 | + |
| 16 | +# Run |
| 17 | +cargo run --release -p niinii |
| 18 | + |
| 19 | +# Run tests |
| 20 | +cargo test --workspace |
| 21 | + |
| 22 | +# Run a single crate's tests |
| 23 | +cargo test -p openai |
| 24 | +cargo test -p ichiran |
| 25 | + |
| 26 | +# Optional features |
| 27 | +cargo build --features tracing-tracy # Tracy profiler support |
| 28 | +cargo build --features tracing-chrome # Chrome tracing support |
| 29 | +cargo build --features voicevox # Text-to-speech (Windows only) |
| 30 | +cargo build --features hook # DLL injection/hooking (Windows only) |
| 31 | + |
| 32 | +# 32-bit build (for hooking into 32-bit applications) |
| 33 | +cargo +stable-i686-pc-windows-msvc build --target i686-pc-windows-msvc --release |
| 34 | +``` |
| 35 | + |
| 36 | +## Architecture |
| 37 | + |
| 38 | +### Workspace Crates |
| 39 | + |
| 40 | +- **`niinii/`** — Main application crate (binary + cdylib). Contains the GUI, application logic, and glue between subsystems. |
| 41 | +- **`openai/`** — Custom OpenAI API client library (Chat Completions, Realtime WebSocket, Responses API). Not published; built specifically for this project. |
| 42 | +- **`ichiran/`** — Rust wrapper around `ichiran-cli`, a Common Lisp program for Japanese text segmentation. Manages a PostgreSQL subprocess and communicates via CLI invocations with S-expressions. Includes LRU caching for segments and kanji lookups. |
| 43 | +- **`third-party/`** — Vendored/forked dependencies: `imgui-dx11-renderer`, `vvcore` (VOICEVOX), `eventsource-stream`. |
| 44 | + |
| 45 | +### Key Subsystems in `niinii/` |
| 46 | + |
| 47 | +- **`app.rs`** — Central `App` struct. Owns the parser, translator, TTS engine, and coordinates async message passing (gloss results, translations) via tokio mpsc channels. |
| 48 | +- **`renderer/`** — Rendering backends implementing the `Renderer` trait: `glow_viewports` (OpenGL, cross-platform) and `d3d11` (Direct3D 11, Windows-only). Manages imgui context, font loading, and the main event loop. |
| 49 | +- **`translator/`** — Currently one backend: `chat` (OpenAI Chat Completions). Organized as a command/event/state store: the UI sends `ChatCommand`s, a single writer task applies commands and reduces `ChatEvent`s emitted by adapter tasks, and publishes immutable `ChatState` snapshots via `ArcSwap`. UI reads are wait-free (`state.load_full()`) and never `async`. Per-request knobs are snapshotted into `TranslateConfig` at submission time; the backend never reads `Settings` live. |
| 50 | +- **`view/`** — imgui UI components. Each top-level window (translator, settings, inject, style editor) is a persistent struct that owns its own `open: bool` and any edit-buffer state. Convention: `show_menu_item(ui)` to render the menu entry that opens it, and `ui(...)` self-renders the window with `.opened(&mut self.open)` and early-returns when closed. `App` holds one instance of each and calls `ui(...)` unconditionally each frame. |
| 51 | +- **`settings.rs`** — Application configuration. Serialized to/from `niinii.toml` using serde. |
| 52 | +- **`parser.rs`** — Wraps the `ichiran` crate to produce a `SyntaxTree` from Japanese input text. |
| 53 | +- **`hook.rs`** — DLL injection support via `hudhook` for rendering the overlay inside another process (feature-gated). |
| 54 | + |
| 55 | +### Configuration |
| 56 | + |
| 57 | +The app reads `niinii.toml` at startup. This contains API keys, model settings, translation prompts, renderer choice, and UI preferences. Settings are written back on exit. |
| 58 | + |
| 59 | +### Dependencies and Patches |
| 60 | + |
| 61 | +The workspace uses a forked `imgui-rs` (branch `glow-viewports-mdpi`) patched for viewport and DPI support. The fork is referenced via `[patch.crates-io]` in the root `Cargo.toml`. The `freetype` library is required via vcpkg for font rendering. |
| 62 | + |
| 63 | +### Runtime Dependencies |
| 64 | + |
| 65 | +Japanese language support requires `ichiran-cli` and a PostgreSQL instance with the Ichiran database. Paths are configured in `niinii.toml`. The `data/` directory contains these runtime dependencies for packaged builds. |
| 66 | + |
| 67 | +## Target Platform |
| 68 | + |
| 69 | +Primary target is `x86_64-pc-windows-msvc`. Cross-platform support is possible via the Glow renderer but is not actively maintained. |
0 commit comments