# Hubro SDK - AI Agent Context

The `hubro-sdk` is a Rust-based development kit designed for building plugins for the [Hubro Platform](https://live.hubroplatform.no). It supports both server-side and mobile-specific functionality through feature flags.

## Core Features and Modules

Crate integrates two main features as defined in the `Cargo.toml` file:

```toml
[features]
server = []
mobile = []
```

### Server Side (`feature = "server"`)
Used for plugins running as microservices (WebAssembly/Spin).

- `src/fhir.rs`: Implements [FHIR](https://www.hl7.org/fhir/) integration using `fhirbolt`.
- `src/plugin.rs`: Implements core plugin infrastructure: metadata (`PluginInfo`), registration, and common endpoints (`/info`, `/authorize`, `/data`).
- `src/signals.rs`: Handling of platform signals and event data.
- `src/toolbox.rs`: Utility logic, including OTP (One Time Password) interception and string manipulation.

### Mobile Side (`feature = "mobile"`)
Used for plugins running on mobile devices, typically for data collection or federated processing.

- `src/mobile.rs`: Mobile-specific logic and platform interfaces.
- `src/records/`: Management of health and user records on-device.
- `src/fed/`: Components related to federated learning or distributed data processing.

## Development & Deployment

### Build Requirements
The SDK targets WebAssembly (`wasm32-wasip1`).

```bash
# Clean build for Wasm target
cargo build --target wasm32-wasip1 --release
```

### Optimization
For production-ready Wasm binaries, it is recommended to use `wasm-opt`:
```bash
wasm-opt --all-features -Oz -o optimized.wasm unoptimized.wasm
```

### Publishing
```bash
# Publish the crate (internal or crates.io depending on configuration)
cargo publish --allow-dirty
```

## Key Technologies
- **Runtime**: [Fermyon Spin](https://www.fermyon.com/spin)
- **Serialization**: `serde` / `serde_json`
- **Data Standard**: HL7 FHIR (R4B)
- **Security**: JWT (`jwt-compact`), Base64, and authentication helpers.
