amaters/lib.rs
1//! AmateRS - Fully Homomorphic Encrypted Distributed Database
2//!
3//! This is the meta crate that re-exports all AmateRS components for convenient access.
4//!
5//! # Overview
6//!
7//! AmateRS (天照RS) is a distributed database system providing Encryption-in-Use
8//! capabilities via TFHE (Fully Homomorphic Encryption). The name comes from
9//! Amaterasu (天照), the Japanese sun goddess.
10//!
11//! This crate provides a unified API to all AmateRS components:
12//!
13//! - **[`core`]**: Core types, storage engine (Iwato), and compute engine (Yata)
14//! - **[`net`]**: Network layer (Musubi) with gRPC and mTLS support
15//! - **[`cluster`]**: Consensus layer (Ukehi) with Raft implementation
16//! - **[`sdk`]**: Rust SDK for client applications
17//!
18//! # Architecture (Japanese Mythology Theme)
19//!
20//! | Component | Origin | Role |
21//! |-----------|--------|------|
22//! | **Iwato** (岩戸) | Heavenly Rock Cave | Storage Engine |
23//! | **Yata** (八咫鏡) | Eight-Span Mirror | Compute Engine |
24//! | **Ukehi** (宇気比) | Sacred Pledge | Consensus Layer |
25//! | **Musubi** (結び) | The Knot | Network Layer |
26//!
27//! # Quick Start
28//!
29//! ```rust,ignore
30//! use amaters::prelude::*;
31//!
32//! #[tokio::main]
33//! async fn main() -> anyhow::Result<()> {
34//! // Connect to AmateRS server
35//! let client = AmateRSClient::connect("http://localhost:50051").await?;
36//!
37//! // Store encrypted data
38//! let key = Key::from_str("user:123");
39//! let value = CipherBlob::new(vec![/* encrypted bytes */]);
40//! client.set("users", &key, &value).await?;
41//!
42//! // Retrieve data
43//! if let Some(data) = client.get("users", &key).await? {
44//! println!("Retrieved {} bytes", data.len());
45//! }
46//!
47//! Ok(())
48//! }
49//! ```
50//!
51//! # Features
52//!
53//! ## Storage Engine (Iwato)
54//!
55//! ```rust,ignore
56//! use amaters::core::storage::MemoryStorage;
57//! use amaters::core::traits::StorageEngine;
58//! use amaters::prelude::*;
59//!
60//! let storage = MemoryStorage::new();
61//! let key = Key::from_str("data");
62//! let value = CipherBlob::new(vec![1, 2, 3]);
63//!
64//! storage.put(&key, &value).await?;
65//! let retrieved = storage.get(&key).await?;
66//! ```
67//!
68//! ## Consensus (Ukehi)
69//!
70//! ```rust,ignore
71//! use amaters::cluster::{RaftNode, RaftConfig, Command};
72//!
73//! let config = RaftConfig::new(1, vec![1, 2, 3]);
74//! let node = RaftNode::new(config)?;
75//!
76//! let cmd = Command::from_str("SET key value");
77//! let index = node.propose(cmd)?;
78//! ```
79//!
80//! ## Query Builder
81//!
82//! ```rust,ignore
83//! use amaters::sdk::query;
84//! use amaters::prelude::*;
85//!
86//! let q = query("users")
87//! .where_clause()
88//! .eq(col("status"), CipherBlob::new(vec![1]))
89//! .build();
90//! ```
91//!
92//! # Module Structure
93//!
94//! | Module | Crate | Description |
95//! |--------|-------|-------------|
96//! | [`core`] | amaters-core | Storage, compute, types, and errors |
97//! | [`net`] | amaters-net | gRPC services and mTLS |
98//! | [`cluster`] | amaters-cluster | Raft consensus |
99//! | [`sdk`] | amaters-sdk-rust | Client SDK |
100//!
101//! # Feature Flags
102//!
103//! - `full` - Enable all features
104//! - `mtls` - Enable mTLS support in networking
105//! - `fhe` - Enable full FHE support with TFHE
106
107#![cfg_attr(docsrs, feature(doc_cfg))]
108
109/// Re-export of `amaters-core` - Core types, storage, and compute engines.
110pub use amaters_core as core;
111
112/// Re-export of `amaters-net` - Network layer with gRPC and mTLS.
113pub use amaters_net as net;
114
115/// Re-export of `amaters-cluster` - Raft consensus implementation.
116pub use amaters_cluster as cluster;
117
118/// Re-export of `amaters-sdk-rust` - Rust SDK for client applications.
119pub use amaters_sdk_rust as sdk;
120
121/// Prelude module for convenient imports.
122///
123/// Import everything commonly needed with:
124/// ```
125/// use amaters::prelude::*;
126/// ```
127pub mod prelude {
128 // ========================================
129 // From amaters-core
130 // ========================================
131
132 // Error types
133 pub use amaters_core::{AmateRSError, ErrorContext, Result as CoreResult};
134
135 // Core types
136 pub use amaters_core::{
137 CipherBlob, ColumnRef, Key, Predicate, Query, QueryBuilder, Update, col,
138 };
139
140 // Storage trait
141 pub use amaters_core::StorageEngine;
142
143 // ========================================
144 // From amaters-net
145 // ========================================
146
147 // Error types
148 pub use amaters_net::{NetError, NetResult};
149
150 // Server
151 pub use amaters_net::{AqlServerBuilder, AqlServiceImpl};
152
153 // ========================================
154 // From amaters-cluster
155 // ========================================
156
157 // Error types
158 pub use amaters_cluster::{RaftError, RaftResult};
159
160 // Raft types
161 pub use amaters_cluster::{
162 Command, LogEntry, LogIndex, NodeId, NodeState, RaftConfig, RaftLog, RaftNode, Term,
163 };
164
165 // Raft RPC
166 pub use amaters_cluster::{
167 AppendEntriesRequest, AppendEntriesResponse, RequestVoteRequest, RequestVoteResponse,
168 };
169
170 // Raft state
171 pub use amaters_cluster::{CandidateState, LeaderState, PersistentState, VolatileState};
172
173 // ========================================
174 // From amaters-sdk-rust
175 // ========================================
176
177 // Client
178 pub use amaters_sdk_rust::{AmateRSClient, QueryResult, ServerInfo};
179
180 // Config
181 pub use amaters_sdk_rust::{ClientConfig, RetryConfig, TlsConfig};
182
183 // Error
184 pub use amaters_sdk_rust::{Result as SdkResult, SdkError};
185
186 // FHE
187 pub use amaters_sdk_rust::{FheEncryptor, FheKeys};
188
189 // Query builder
190 pub use amaters_sdk_rust::{FilterBuilder, FluentQueryBuilder, PredicateBuilder, query};
191}
192
193/// Library version
194pub const VERSION: &str = env!("CARGO_PKG_VERSION");
195
196/// Library name
197pub const NAME: &str = env!("CARGO_PKG_NAME");
198
199#[cfg(test)]
200mod tests {
201 use super::*;
202
203 #[test]
204 fn test_version() {
205 assert!(VERSION.contains('.'), "VERSION should be semver format");
206 assert_eq!(NAME, "amaters");
207 }
208
209 #[test]
210 fn test_module_access() {
211 // Verify all modules are accessible
212 let _ = core::VERSION;
213 let _ = net::VERSION;
214 let _ = cluster::VERSION;
215 let _ = sdk::VERSION;
216 }
217
218 #[test]
219 fn test_prelude_imports() {
220 use crate::prelude::*;
221
222 // Verify prelude types are available
223 let key = Key::from_str("test");
224 assert!(!key.as_bytes().is_empty());
225 }
226}