# picovoice/rhino architecture

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

- Interactive diagram: https://gitdiagram.com/picovoice/rhino
- Repository: https://github.com/picovoice/rhino

## Overview

##### Project Type and Purpose
- This is an open-source, cross-platform Speech-to-Intent SDK (“Rhino”) with:
- A native, ANSI C core engine (`pv_rhino`) and parameter model (`rhino_params.pv`).
- Multi-language FFI bindings (Python, Node.js, Java, .NET, Rust, Android/Java, iOS/Swift, Flutter, React Native, Unity, Web/WASM).
- Reference demo applications per platform.
- Build and CI pipelines validating builds, style, demos, and performance.

##### File Structure
- Top level
- `include/` and `lib/`: header and compiled native libraries for each platform/architecture.
- `binding/<platform>/`: language-specific wrapper code and packaging (e.g., `binding/python`, `binding/nodejs`, `binding/android/Rhino`).
- `demo/<platform>/`: reference apps showing how to use the SDK on each platform (e.g., `demo/python`, `demo/web`, `demo/android/Activity`).
- `resources/contexts/` and `lib/common/rhino_params.pv`: shipped context files (`.rhn`) and model (`.pv`).
- `.github/workflows/`: CI jobs for style, build, demo, performance on each supported language.
- `script/` and `resources/scripts/`: automation and lint/test helpers.

##### README Insights
- Core engine infers “intent” and “slots” from microphone or audio file input.
- Broad language/platform support, including WebAssembly in a Web Worker.
- Demos illustrate both file-based and microphone-based usage.
- SDK sections detail high-level (automatic audio capture) vs. low-level APIs.

##### Main Components
a. Rhino Core Engine
- C library & model: `pv_rhino.h` + `rhino_params.pv` (lib/common).
- Exposed via FFI or WebAssembly.
b. Context Model Store
- Static `.rhn` files under `resources/contexts/<platform>` loaded at runtime.
c. Language Bindings (Adapters)
- Python (`binding/python`)
- Node.js (`binding/nodejs`)
- Java (`binding/java`)
- .NET (`binding/dotnet`)
- Rust (`binding/rust`)
- Android (Java JNI) (`binding/android/Rhino`)
- iOS (Swift/Obj-C) (`binding/ios`)
- Flutter (`binding/flutter`)
- React Native (`binding/react-native`)
- Unity (`binding/unity`)
- Web/WASM (`binding/web`) via Web Worker + WebVoiceProcessor
d. Demo Applications
- One per platform under `demo/<platform>` – using corresponding binding + context + audio I/O.
e. CI / Build Pipeline
- GitHub Actions jobs for each binding: style check, build, demo smoke tests, perf benchmarks.
f. Utilities & Scripts
- Linting, test data, automation scripts under `resources/.lint`, `resources/.test`, `resources/scripts`, `script/automation`.

##### Relationships and Data Flows
- Audio Input (Mic or File) → Binding (high-level or low-level API) → Rhino Core Engine (FFI/WASM) + Context → Inference Result → Binding → Demo/Application UI or CLI.
- CI pipelines pull from repo → build native libs (`lib/`), compile bindings, run demos/tests.

##### Architectural Patterns and Design Principles
- Adapter/Bridge pattern: each language binding adapts the uniform C API to a language-specific idiom.
- Plugin-like model loading: contexts (`.rhn`) and model (`.pv`) are data plugins.
- Polyglot monorepo: shared core, multiple language surfaces.
- Isolation for web: WebAssembly + Web Worker for non-blocking inference.
- High-Level vs. Low-Level API: automatic audio capture vs. manual frame feeding.

## Diagram (Mermaid)

```mermaid
graph TD
    subgraph "CI / Build Pipeline"
        CI["GitHub Actions"]:::ci
    end

    subgraph "Utilities & Scripts"
        UTIL["Utilities/Scripts"]:::util
    end

    subgraph "Core & Data"
        CORE["Rhino Core Engine\n(C Library & WASM)"]:::core
        CONT["Context Model Store"]:::data
    end

    subgraph "Bindings / Adapters"
        PY["Python Binding"]:::binding
        NODE["Node.js Binding"]:::binding
        JAVA["Java Binding"]:::binding
        DOTNET[".NET Binding"]:::binding
        RUST["Rust Binding"]:::binding
        ANDR["Android Binding"]:::binding
        IOS["iOS Binding"]:::binding
        FLUT["Flutter Binding"]:::binding
        RN["React Native Binding"]:::binding
        UNITY["Unity Binding"]:::binding
        WEB["Web/WASM Binding"]:::binding
    end

    subgraph "Demo Applications"
        DEMOPY["Demo Python"]:::demo
        DEMONODE["Demo Node.js"]:::demo
        DEMOJAVA["Demo Java"]:::demo
        DEMODOT["Demo .NET"]:::demo
        DEMOC["Demo C"]:::demo
        DEMOANDROID["Demo Android"]:::demo
        DEMOIOS["Demo iOS"]:::demo
        DEMOFLUT["Demo Flutter"]:::demo
        DEMORN["Demo ReactNative"]:::demo
        DEMOUNITY["Demo Unity"]:::demo
        DEMOWEB["Demo Web"]:::demo
        DEMORUST["Demo Rust"]:::demo
    end

    CI --> CORE
    CI --> PY
    CI --> NODE
    CI --> JAVA
    CI --> DOTNET
    CI --> RUST
    CI --> ANDR
    CI --> IOS
    CI --> FLUT
    CI --> RN
    CI --> UNITY
    CI --> WEB

    UTIL --> CI

    DEMOPY --> PY
    DEMONODE --> NODE
    DEMOJAVA --> JAVA
    DEMODOT --> DOTNET
    DEMOC --> CORE
    DEMOANDROID --> ANDR
    DEMOIOS --> IOS
    DEMOFLUT --> FLUT
    DEMORN --> RN
    DEMOUNITY --> UNITY
    DEMOWEB --> WEB
    DEMORUST --> RUST

    PY --> CORE
    NODE --> CORE
    JAVA --> CORE
    DOTNET --> CORE
    RUST --> CORE
    ANDR --> CORE
    IOS --> CORE
    FLUT --> CORE
    RN --> CORE
    UNITY --> CORE
    WEB --> CORE

    CORE --> PY
    CORE --> NODE
    CORE --> JAVA
    CORE --> DOTNET
    CORE --> RUST
    CORE --> ANDR
    CORE --> IOS
    CORE --> FLUT
    CORE --> RN
    CORE --> UNITY
    CORE --> WEB

    CONT --> CORE

    click CORE "https://github.com/picovoice/rhino/blob/master/include/pv_rhino.h"
    click CORE "https://github.com/picovoice/rhino/blob/master/include/picovoice.h"
    click CORE "https://github.com/picovoice/rhino/blob/master/lib/common/rhino_params.pv"
    click CORE "https://github.com/picovoice/rhino/blob/master/lib/wasm/pv_rhino.wasm"

    click CONT "https://github.com/picovoice/rhino/tree/master/resources/contexts/"

    click PY "https://github.com/picovoice/rhino/tree/master/binding/python/"
    click NODE "https://github.com/picovoice/rhino/tree/master/binding/nodejs/"
    click JAVA "https://github.com/picovoice/rhino/blob/master/binding/java/src/ai/picovoice/rhino/Rhino.java"
    click DOTNET "https://github.com/picovoice/rhino/blob/master/binding/dotnet/Rhino/Rhino.cs"
    click RUST "https://github.com/picovoice/rhino/blob/master/binding/rust/src/lib.rs"
    click ANDR "https://github.com/picovoice/rhino/blob/master/binding/android/Rhino/rhino/src/main/java/ai/picovoice/rhino/Rhino.java"
    click IOS "https://github.com/picovoice/rhino/blob/master/binding/ios/Rhino.swift"
    click FLUT "https://github.com/picovoice/rhino/blob/master/binding/flutter/lib/rhino.dart"
    click RN "https://github.com/picovoice/rhino/blob/master/binding/react-native/src/index.tsx"
    click UNITY "https://github.com/picovoice/rhino/blob/master/binding/unity/Assets/Rhino/Rhino.cs"
    click WEB "https://github.com/picovoice/rhino/blob/master/binding/web/src/rhino_worker.ts"

    click DEMOPY "https://github.com/picovoice/rhino/blob/master/demo/python/rhino_demo_file.py"
    click DEMONODE "https://github.com/picovoice/rhino/blob/master/demo/nodejs/file.js"
    click DEMOJAVA "https://github.com/picovoice/rhino/blob/master/demo/java/src/ai/picovoice/rhinodemo/FileDemo.java"
    click DEMODOT "https://github.com/picovoice/rhino/blob/master/demo/dotnet/RhinoDemo/FileDemo.cs"
    click DEMOC "https://github.com/picovoice/rhino/blob/master/demo/c/rhino_demo_file.c"
    click DEMOANDROID "https://github.com/picovoice/rhino/tree/master/demo/android/Activity/rhino-activity-demo-app/"
    click DEMOIOS "https://github.com/picovoice/rhino/tree/master/demo/ios/RhinoDemo/"
    click DEMOFLUT "https://github.com/picovoice/rhino/blob/master/demo/flutter/lib/main.dart"
    click DEMORN "https://github.com/picovoice/rhino/blob/master/demo/react-native/RhinoTestApp/App.tsx"
    click DEMOUNITY "https://github.com/picovoice/rhino/blob/master/demo/unity/RhinoDemo.cs"
    click DEMOWEB "https://github.com/picovoice/rhino/blob/master/demo/web/scripts/run_demo.js"
    click DEMORUST "https://github.com/picovoice/rhino/blob/master/demo/rust/filedemo/src/main.rs"

    classDef core fill:#cccccc,stroke:#333,stroke-width:1px;
    classDef data fill:#b2d8b2,stroke:#333,stroke-width:1px;
    classDef binding fill:#9ecae1,stroke:#333,stroke-width:1px;
    classDef demo fill:#dadaf7,stroke:#333,stroke-width:1px;
    classDef ci fill:#fdd0a2,stroke:#333,stroke-width:1px;
    classDef util fill:#d9d2e9,stroke:#333,stroke-width:1px;
```
