aimdb-dev/aimdb

GitHub: aimdb-dev/aimdb

AimDB 是一个分布式数据平面工具,使用 Rust 类型作为契约,解决跨设备数据一致性问题。

Stars: 84 | Forks: 9

AimDB

Distributed by design. Data-driven by default.

Stars Release Crates.io Build License Newsletter

AimDB 将数据契约融入架构之中。定义一次 schema,即可将其原样部署到微控制器、边缘网关、Kubernetes 和浏览器中,并在契约演进时进行明确、带类型的迁移。 AimDB 不是存储引擎。它是一个类型化数据平面,其中 Rust 类型 *就是* 线上格式。 [![AimDB 实时演示](https://static.pigsec.cn/wp-content/uploads/repos/2026/05/11ea81b9d3063303.gif)](https://aimdb.dev) ## 为何需要 AimDB 分布式系统将大部分复杂性预算花在了层间的转换上:IDL、代码生成、序列化、schema 注册表以及胶水服务。AimDB 通过 **让 Rust 类型成为契约** 来移除这一层:定义一次,从 `no_std` 微控制器到浏览器,编译后保持不变。 - **一个类型,所有层级。** 同一个结构体可用于固件和云端编译。它们之间无需转换层。 - **缓冲区定义数据移动方式。** 无需手动连接队列,无需单独的传输配置。 - **无非类型化边界。** 流处理、迁移、可观测性和连接器等能力通过 trait 解锁。 [软件架构的下一纪元:数据为先](https://aimdb.dev/blog/data-driven-design) ## 快速开始 ### 5 分钟内本地运行 ``` cargo new my-aimdb-app && cd my-aimdb-app cargo add aimdb-core aimdb-tokio-adapter cargo add tokio --features full ``` 将此代码放入 `src/main.rs`: ``` use aimdb_core::{buffer::BufferCfg, AimDbBuilder}; use aimdb_tokio_adapter::{TokioAdapter, TokioRecordRegistrarExt}; use std::sync::Arc; #[derive(Clone, Debug)] pub struct Temperature { pub celsius: f32, } #[tokio::main] async fn main() -> Result<(), Box> { let runtime = Arc::new(TokioAdapter::new()?); let mut builder = AimDbBuilder::new().runtime(runtime); builder.configure::("temp.indoor", |reg| { reg.buffer(BufferCfg::SpmcRing { capacity: 16 }) .source(|ctx, producer| async move { for celsius in [21.0, 22.5, 24.1] { producer.produce(Temperature { celsius }).await.ok(); ctx.time().sleep(ctx.time().secs(1)).await; } }) .tap(|ctx, consumer| async move { let mut reader = consumer.subscribe().unwrap(); while let Ok(t) = reader.recv().await { ctx.log().info(&format!("temp: {:.1}°C", t.celsius)); } }) .finish(); }); // `.run()` builds the database, collects every producer/consumer/transform // future, and drives them all on a single `FuturesUnordered`. It blocks // until shutdown. For programmatic access to the `AimDb` handle, call // `.build().await?` directly — it returns `(AimDb, AimDbRunner)`. builder.run().await?; Ok(()) } ``` `cargo run` —— 三次温度读数通过一个类型化管道进行流式传输。相同的代码通过交换运行时适配器,可为 Cortex-M4 上的 Embassy 或浏览器中的 WASM 进行编译。 ### 30 分钟内运行真实的天气网格 一个完整的 MCU → 边缘 → 云网格:三个气象站、MQTT 代理和一个中心集线器。 ``` git clone https://github.com/aimdb-dev/aimdb cd aimdb/examples/weather-mesh-demo docker compose up ``` [文档中的详细讲解](https://aimdb.dev/docs/getting-started) ## 你将获得 覆盖大部分数据移动模式的 **三种缓冲区原语**: | 缓冲区 | 语义 | 用例 | | --- | --- | --- | | **SPMC 环形缓冲区** | 具有独立消费者的有界流 | 传感器遥测、事件日志 | | [**SingleLatest**](examples/hello-single-latest-async) | 仅关心当前值 | 功能开关、配置、UI 状态 | | [**Mailbox**](examples/hello-mailbox) | 最新指令生效 | 设备命令、执行机构、RPC | **四种能力 trait** —— 可选启用、类型检查: | Trait | 解锁的能力 | | --- | --- | | [`Streamable`](https://aimdb.dev/blog/streamable-crossing-boundaries) | 跨越 WASM / WebSocket / CLI 边界 | | [`Migratable`](https://aimdb.dev/blog/schema-migration-without-ceremony) | 跨已部署集群的类型化 schema 演进 | | `Observable` | 自动的每记录指标 | | [`Linkable`](https://aimdb.dev/blog/connectors-where-aimdb-meets-the-real-world) | 线上格式连接器 | **跨运行时的单一异步 API。** Tokio、Embassy、WASM —— 交换运行时适配器,代码不变。 → [运行时抽象如何工作](https://aimdb.dev/blog/building-aimdb-one-async-api) **现成连接器:** MQTT、KNX、WebSocket。编写自己的连接器只需一个 trait 实现。 深入阅读:[数据契约](https://aimdb.dev/blog/data-contracts-deep-dive) · [源/监听/转换](https://aimdb.dev/blog/source-tap-transform) · [schema 迁移](https://aimdb.dev/blog/schema-migration-without-ceremony) · [响应式管道](https://aimdb.dev/blog/reactive-pipelines) ### 数据流如何组装 ``` Producer Consumers ──────── ───────── ┌──────────────┐ ───► Tap (in-process subscriber) Source ───► │ Buffer │ (typed) │ SPMC / SL / │ ───► Tap (another subscriber) │ Mailbox │ └──────────────┘ ───► Link ──► MQTT / KNX / WebSocket ``` ## 向你的 AI 查询运行中的系统 AimDB 附带一个 MCP 服务器。将任何兼容 MCP 的客户端指向一个运行实例,并用自然语言查询它。 AimDB MCP demo 可以在实时演示中尝试 —— 无需安装。将此添加到你的工作空间: `.vscode/mcp.json`: ``` { "servers": { "aimdb-weather": { "type": "http", "url": "http://aimdb.dev/mcp" } } } ``` 然后问:*"慕尼黑的当前温度是多少?"* 查看 [MCP 服务器文档](tools/aimdb-mcp/) 了解 Claude Desktop 和其他编辑器的配置,或阅读深度文章:[AI 辅助的系统自省:AimDB 与模型上下文协议相遇](https://aimdb.dev/blog/ai-introspection-with-mcp)。 ## 了解更多 - [快速入门指南](https://aimdb.dev/docs/getting-started) —— 依赖、平台设置、你的第一个契约 - [API 参考 (docs.rs)](https://docs.rs/aimdb-core) —— 完整的 Rust API - [博客](https://aimdb.dev/blog) —— 设计笔记、深度文章、版本发布说明 - [实时演示](https://aimdb.dev) —— 运行中的传感器网格 ### 连接器 | 协议 | 状态 | 运行时 | |----------|--------|----------| | **MQTT** — `aimdb-mqtt-connector` | ✅ 就绪 | std, no_std | | **KNX** — `aimdb-knx-connector` | ✅ 就绪 | std, no_std | | **WebSocket** — `aimdb-websocket-connector` | ✅ 就绪 | std, wasm | | **Kafka** | 📋 计划中 | std | | **Modbus** | 📋 计划中 | std, no_std | ## 寻求帮助 我们是一个雄心勃勃的小团队。提供帮助最快的方式是承担一个范围明确的部分。以下每个任务都适合花几个小时完成,并包含文件指针、验收标准和提问的地方: - [#92 — `no_std` `Display` for `DbError` 应包含数字字段](https://github.com/aimdb-dev/aimdb/issues/92) · 2–3 小时 · core · embedded - [#93 — 最小示例: `hello-single-latest`](https://github.com/aimdb-dev/aimdb/issues/93) · 2–3 小时 · docs - [#95 — CLI: 添加 `aimdb instance ping` 子命令](https://github.com/aimdb-dev/aimdb/issues/95) · 3–4 小时 · cli - [#96 — CI: 在 rustdoc 链接损坏时失败](https://github.com/aimdb-dev/aimdb/issues/96) · 1–2 小时 · docs - [#97 — `BufferCfg` 变体的文档测试](https://github.com/aimdb-dev/aimdb/issues/97) · 2–3 小时 · core · docs - [#99 — 异步示例: `hello-mailbox-async`](https://github.com/aimdb-dev/aimdb/issues/99) · 2–3 小时 · docs - [#100 — 异步示例: `hello-single-latest-async`](https://github.com/aimdb-dev/aimdb/issues/100) · 2–3 小时 · docs - [#101 — 异步示例: `hello-spmc-ring-async`](https://github.com/aimdb-dev/aimdb/issues/101) · 2–3 小时 · docs [查看所有“good first issue” →](https://github.com/aimdb-dev/aimdb/labels/good%20first%20issue) 如果你想接手某个 issue,请在下面留言 —— 我们会在一天内回复。欢迎在 [讨论区](https://github.com/aimdb-dev/aimdb/discussions) 提出新想法。 ## 许可证 [Apache 2.0](LICENSE)

为分布式而设计。默认数据驱动。

开始使用 · 实时演示 · 加入讨论

标签:API设计, no_std, Rust, WebAssembly, 分布式系统, 包管理器, 可视化界面, 响应大小分析, 嵌入式开发, 序列化优化, 微控制器, 数据同步, 数据契约, 数据平面, 数据库, 数据管理, 模式定义, 模式迁移, 浏览器兼容, 物联网, 类型安全, 统一API, 网络流量审计, 跨平台开发, 边缘网关, 边缘计算, 迁移管理, 通知系统