unifly_core/lib.rs
1//! Reactive data layer between `unifly-api` and UI consumers (CLI / TUI).
2//!
3//! This crate owns the business logic, domain model, and reactive data
4//! infrastructure for the UniFi CLI workspace:
5//!
6//! - **[`Controller`]** — Central facade managing the full lifecycle:
7//! [`connect()`](Controller::connect) authenticates, fetches an initial data
8//! snapshot, then spawns background tasks for periodic refresh and command
9//! processing. [`Controller::oneshot()`](Controller::oneshot) provides a
10//! lightweight fire-and-forget mode for single CLI invocations.
11//!
12//! - **[`DataStore`]** — Lock-free reactive storage built on
13//! `EntityCollection<T>` (`DashMap` + `tokio::sync::watch` channels). Merges
14//! Integration and Legacy API responses into canonical domain types.
15//!
16//! - **[`EntityStream<T>`]** — Subscription handle vended by the `DataStore`.
17//! Exposes `current()` / `latest()` / `changed()` for TUI reactive rendering.
18//!
19//! - **[`Command`]** — Typed mutation requests routed through an `mpsc` channel
20//! to the controller's command processor. Reads bypass the channel via
21//! direct `DataStore` snapshots or ad-hoc API queries.
22//!
23//! - **Domain model** ([`model`]) — Canonical types (`Device`, `Client`,
24//! `Network`, `FirewallPolicy`, `Event`, etc.) with [`EntityId`] supporting
25//! both UUID (Integration API) and string-based (Legacy API) identifiers.
26
27pub mod command;
28pub mod config;
29pub mod controller;
30pub mod convert;
31pub mod error;
32pub mod model;
33pub mod store;
34pub mod stream;
35
36// ── Primary re-exports ──────────────────────────────────────────────
37pub use command::requests::*;
38pub use command::{Command, CommandResult};
39pub use config::{AuthCredentials, ControllerConfig, TlsVerification};
40pub use controller::{ConnectionState, Controller};
41pub use error::CoreError;
42pub use store::DataStore;
43pub use stream::EntityStream;
44
45// Re-export model types at the crate root for ergonomics.
46pub use model::{
47 // Firewall
48 AclRule,
49 // Legacy resource types
50 Admin,
51 // Events / alarms
52 Alarm,
53 // Core entities
54 Client,
55 ClientType,
56 Country,
57 Device,
58 DeviceState,
59 DeviceType,
60 DpiApplication,
61 DpiCategory,
62 EntityId,
63 Event,
64 EventCategory,
65 EventSeverity,
66 FirewallPolicy,
67 FirewallZone,
68 HealthSummary,
69 MacAddress,
70 Network,
71 RadiusProfile,
72 Site,
73 SysInfo,
74 SystemInfo,
75 // Supporting types
76 TrafficMatchingList,
77 VpnServer,
78 VpnTunnel,
79 WanInterface,
80};