<p align="center">
  <picture>
    <source media="(prefers-color-scheme: dark)" srcset="https://live.hubroplatform.no/assets/logo-inverted.png">
    <source media="(prefers-color-scheme: light)" srcset="https://live.hubroplatform.no/assets/logo.png">
    <img alt="Hubro SDK Logo" src="https://live.hubroplatform.no/assets/logo.png" width="120" height="120">
  </picture>
</p>

<h1 align="center">Hubro SDK</h1>

<p align="center">
  <a href="https://www.rust-lang.org"><img src="https://img.shields.io/badge/rust-1.93.0%2B-orange.svg" alt="Rust"></a>
  <a href="https://live.hubroplatform.no"><img src="https://img.shields.io/badge/platform-Hubro-green.svg" alt="Platform"></a>
  <a href="https://wa.dev/hubro-platform:hubro-sdk"><img src="https://img.shields.io/badge/registry-warg-blue.svg" alt="Warg"></a>
</p>

---

The **Hubro SDK** is a powerful Rust-based development kit designed for building high-performance plugins for the [Hubro Platform](https://live.hubroplatform.no). 

Whether you're building server-side microservices or mobile-first data collection agents, this SDK provides the core infrastructure, security, and data standards compliance (HL7 FHIR) you need.

---

## 🚀 Key Features

### 🖥️ Server Side (`feature = "server"`)
*Optimized for [Fermyon Spin](https://www.fermyon.com/spin) and WebAssembly microservices.*

- **HL7 FHIR Integration**: Seamlessly handle medical data standards using `fhirbolt`.
- **Plugin Infrastructure**: Built-in metadata, registration, and standard endpoints (`/info`, `/authorize`, `/data`).
- **Signal Handling**: Efficient processing of platform events and signals.
- **Security**: Robust JWT-based authentication and secure data handling.

### 📱 Mobile Side (`feature = "mobile"`)
*Designed for on-device edge processing and federated learning.*

- **Platform Interfaces**: Native-like interaction with mobile platform routines.
- **Record Management**: Securely manage health and user records on-device.
- **Advanced ML**: Integrated support for Federated Learning and distributed processing via `burn` and `linfa`.
- **Privacy-Preserving Tech**: Experimental support for Post-Quantum Cryptography (ML-KEM/ML-DSA).

---

## 🛠️ Installation

Add this to your `Cargo.toml`:

```toml
[dependencies]
hubro-sdk = { version = "1.0.1", features = ["server"] } # Or "mobile"
```

---

## 🏗️ Development & Build

### Target
The SDK primarily targets WebAssembly (**WASI**).

### Standard Build (WASIp1)
```bash
# Clean release build
cargo build --target wasm32-wasip1 --release
```

### WASIp2 Build (Mobile/Advanced)
```bash
cargo build --release --target wasm32-wasip2 --features mobile
```

### ⚡ Optimization
To minimize binary size for production, we recommend using `wasm-opt`:
```bash
wasm-opt --all-features -Oz -o optimized.wasm unoptimized.wasm
```

---

## 🧰 Technology Stack

- **Runtime**: WebAssembly (WASI) / Fermyon Spin
- **Data Standard**: HL7 FHIR (R4B)
- **Serialization**: `serde` / `serde_json` / `polars`
- **Cryptography**: `jwt-compact`, `chacha20poly1305`, `ml-kem`, `tfhe`
- **Machine Learning**: `burn`, `linfa`, `ndarray`

---

## 📁 Project Structure

- `src/plugin.rs`: Core plugin infrastructure and deployment logic.
- `src/fhir.rs`: HL7 FHIR standard implementation.
- `src/signals.rs`: Platform signal and event handling.
- `src/mobile.rs`: Mobile-specific platform routines.
- `src/toolbox.rs`: Utility logic (e.g., OTP interception).
- `hubro-sdk-macros`: Procedural macros for easier plugin development.
- `wit/`: Interface definitions for WebAssembly.

---

## 📖 Documentation & Resources

- **Official Guides**: [Extending Hubro](https://docs.hubroplatform.no/extending-hubro.html)
- **Warg Registry**: [hubro-platform:hubro-sdk](https://wa.dev/hubro-platform:hubro-sdk)
- **Architecture Details**: See [AGENTS.md](./AGENTS.md) for a deep dive into the SDK's modules.

---

## 🏗️ Maintainers

### Publishing
```bash
# Standard crate publish
cargo publish --allow-dirty

# WASIp2 / Warg publish
warg publish release --name hubro-platform:hubro-sdk --version 1.0.1 target/wasm32-wasip2/release/hubro_sdk.wasm
```

---

Built with ❤️ by the Hubro Team.