Skip to main content

Shared Types

The bf_types crate serves as the central type library shared across all workers and services in the Broadford Living platform. This ensures type consistency and enables seamless communication between components.

Purpose

Having a shared types library provides several benefits:

  • Type Safety: All services use the same type definitions, preventing mismatches
  • Code Generation: Types are used to generate OpenAPI specs and TypeScript definitions
  • Compile-Time Verification: Changes to types are caught at compile time across all crates
  • Documentation: Types serve as living documentation of the API contract

Module Structure

bf_types/
├── auth/ # Authentication types (ClerkAuth, roles)
├── error/ # Unified error handling (AppError, ErrorResponse)
├── mesh/ # Service-to-service client types
├── notify/ # Webhook and notification payloads
├── ota/ # Over-the-air update types
├── resident/ # Property, device, and query types
├── smart/ # Device capabilities and states
└── user/ # Tenant lifecycle types (move-in/out)

Key Design Decisions

Flat Re-exports

The crate re-exports key types at the root level for convenience:

pub use resident::{PropertyInfo, DeviceMapping};
pub use smart::{DeviceType, DeviceCapability};
pub use error::{AppError, ErrorResponse};

Feature-Gated Clients

The mesh client module is behind a feature flag to avoid including HTTP client dependencies in WASM targets:

#[cfg(feature = "mesh")]
pub mod mesh;

Documentation in This Section