amaters 0.2.0

AmateRS - Fully Homomorphic Encrypted Distributed Database with Zero Trust Architecture
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
//! # AmateRS - Fully Homomorphic Encrypted Distributed Database
//!
//! **AmateRS** (天照RS) is a distributed database system providing Encryption-in-Use
//! capabilities via TFHE (Fully Homomorphic Encryption). The name comes from
//! Amaterasu (天照), the Japanese sun goddess.
//!
//! This is the facade crate that re-exports all AmateRS components for
//! convenient, unified access. Instead of depending on individual crates
//! (`amaters-core`, `amaters-net`, `amaters-cluster`, `amaters-sdk-rust`),
//! you can depend on `amaters` alone and access everything through a
//! single namespace.
//!
//! # Architecture (Japanese Mythology Theme)
//!
//! | Component | Origin | Role |
//! |-----------|--------|------|
//! | **Iwato** (岩戸) | Heavenly Rock Cave | Storage Engine |
//! | **Yata** (八咫鏡) | Eight-Span Mirror | Compute Engine |
//! | **Ukehi** (宇気比) | Sacred Pledge | Consensus Layer |
//! | **Musubi** (結び) | The Knot | Network Layer |
//!
//! # Quick Start
//!
//! ```rust,ignore
//! use amaters::prelude::*;
//!
//! #[tokio::main]
//! async fn main() -> anyhow::Result<()> {
//!     // Connect to AmateRS server
//!     let client = AmateRSClient::connect("http://localhost:50051").await?;
//!
//!     // Store encrypted data
//!     let key = Key::from_str("user:123");
//!     let value = CipherBlob::new(vec![/* encrypted bytes */]);
//!     client.set("users", &key, &value).await?;
//!
//!     // Retrieve data
//!     if let Some(data) = client.get("users", &key).await? {
//!         println!("Retrieved {} bytes", data.len());
//!     }
//!
//!     Ok(())
//! }
//! ```
//!
//! # Storage Engine (Iwato)
//!
//! The storage engine is based on an LSM-Tree with WiscKey value separation,
//! WAL for durability, bloom filters, and block caching.
//!
//! ```rust
//! use amaters::core::storage::LsmTree;
//! use amaters::core::{CipherBlob, Key};
//!
//! # fn example() -> amaters::core::Result<()> {
//! let dir = std::env::temp_dir().join("amaters_doc_example");
//! let tree = LsmTree::new(&dir)?;
//!
//! // Put
//! tree.put(Key::from_str("hello"), CipherBlob::new(vec![1, 2, 3]))?;
//!
//! // Get
//! let val = tree.get(&Key::from_str("hello"))?;
//! assert!(val.is_some());
//!
//! // Delete
//! tree.delete(Key::from_str("hello"))?;
//! tree.close()?;
//! std::fs::remove_dir_all(&dir).ok();
//! # Ok(())
//! # }
//! ```
//!
//! # Query Builder
//!
//! Build queries with a fluent API. Queries can target both local storage
//! and remote servers via the SDK.
//!
//! ```rust
//! use amaters::core::{Key, CipherBlob, Predicate, col};
//! use amaters::sdk::query;
//!
//! // Point lookup
//! let q1 = query("users").get(Key::from_str("user:123"));
//!
//! // Filter with predicates
//! let q2 = query("users")
//!     .where_clause()
//!     .eq(col("status"), CipherBlob::new(vec![1]))
//!     .and(Predicate::Gt(col("age"), CipherBlob::new(vec![18])))
//!     .build();
//!
//! // Range scan
//! let q3 = query("events")
//!     .range(Key::from_str("2024-01-01"), Key::from_str("2024-12-31"));
//! ```
//!
//! # Compression
//!
//! The storage layer supports pluggable compression:
//!
//! ```rust
//! use amaters::core::storage::compression::{compress_block, decompress_block, CompressionType};
//!
//! # fn example() -> amaters::core::Result<()> {
//! let data = b"hello world, compressing with LZ4";
//! let compressed = compress_block(data, CompressionType::Lz4)?;
//! let decompressed = decompress_block(&compressed, CompressionType::Lz4, data.len())?;
//! assert_eq!(&decompressed, &data[..]);
//! # Ok(())
//! # }
//! ```
//!
//! # Consensus (Ukehi)
//!
//! ```rust,ignore
//! use amaters::cluster::{RaftNode, RaftConfig, Command};
//!
//! let config = RaftConfig::new(1, vec![1, 2, 3]);
//! let node = RaftNode::new(config)?;
//!
//! let cmd = Command::from_str("SET key value");
//! let index = node.propose(cmd)?;
//! ```
//!
//! # Module Structure
//!
//! | Module | Crate | Description |
//! |--------|-------|-------------|
//! | [`core`] | amaters-core | Storage, compute, types, and errors |
//! | [`net`] | amaters-net | gRPC services and mTLS |
//! | [`cluster`] | amaters-cluster | Raft consensus |
//! | [`sdk`] | amaters-sdk-rust | Client SDK |
//!
//! # Feature Flags
//!
//! | Feature | Description |
//! |---------|-------------|
//! | `full` | Enable all features (`mtls` + `fhe`) |
//! | `mtls` | Enable mTLS support in the networking layer |
//! | `fhe` | Enable full FHE support with TFHE in the SDK |

#![cfg_attr(docsrs, feature(doc_cfg))]

/// Re-export of `amaters-core` - Core types, storage, and compute engines.
///
/// Contains the LSM-Tree storage engine (Iwato), the FHE compute engine (Yata),
/// core types (`Key`, `CipherBlob`, `Query`, `Predicate`), error types,
/// compression utilities, and validation helpers.
pub use amaters_core as core;

/// Re-export of `amaters-net` - Network layer with gRPC and mTLS.
///
/// Provides the Musubi networking layer including gRPC service definitions,
/// connection pooling, rate limiting, circuit breakers, load balancing,
/// and optional mTLS support (feature-gated).
pub use amaters_net as net;

/// Re-export of `amaters-cluster` - Raft consensus implementation.
///
/// Implements the Ukehi consensus protocol based on Raft, including
/// leader election, log replication, snapshots, and persistence.
pub use amaters_cluster as cluster;

/// Re-export of `amaters-sdk-rust` - Rust SDK for client applications.
///
/// Provides the high-level client API (`AmateRSClient`), fluent query
/// builder, FHE key management, connection configuration, and
/// client-side query caching.
pub use amaters_sdk_rust as sdk;

/// Prelude module for convenient imports.
///
/// Import everything commonly needed with:
/// ```
/// use amaters::prelude::*;
/// ```
///
/// This re-exports the most frequently used types from all sub-crates:
/// - Core types: `Key`, `CipherBlob`, `Query`, `Predicate`, etc.
/// - Error types: `AmateRSError`, `NetError`, `RaftError`, `SdkError`
/// - Storage: `StorageEngine` trait
/// - Network: `AqlServerBuilder`, `AqlServiceImpl`
/// - Cluster: `RaftNode`, `RaftConfig`, `Command`, etc.
/// - SDK: `AmateRSClient`, `ClientConfig`, `query()`, etc.
pub mod prelude {
    // ========================================
    // From amaters-core
    // ========================================

    // Error types
    pub use amaters_core::{AmateRSError, ErrorContext, Result as CoreResult};

    // Core types
    pub use amaters_core::{
        CipherBlob, ColumnRef, Key, Predicate, Query, QueryBuilder, Update, col,
    };

    // Storage trait
    pub use amaters_core::StorageEngine;

    // ========================================
    // From amaters-net
    // ========================================

    // Error types
    pub use amaters_net::{NetError, NetResult};

    // Server
    pub use amaters_net::{AqlServerBuilder, AqlServiceImpl};

    // ========================================
    // From amaters-cluster
    // ========================================

    // Error types
    pub use amaters_cluster::{RaftError, RaftResult};

    // Raft types
    pub use amaters_cluster::{
        Command, LogEntry, LogIndex, NodeId, NodeState, RaftConfig, RaftLog, RaftNode, Term,
    };

    // Raft RPC
    pub use amaters_cluster::{
        AppendEntriesRequest, AppendEntriesResponse, RequestVoteRequest, RequestVoteResponse,
    };

    // Raft state
    pub use amaters_cluster::{CandidateState, LeaderState, PersistentState, VolatileState};

    // ========================================
    // From amaters-sdk-rust
    // ========================================

    // Client
    pub use amaters_sdk_rust::{AmateRSClient, QueryResult, ServerInfo};

    // Config
    pub use amaters_sdk_rust::{ClientConfig, RetryConfig, TlsConfig};

    // Error
    pub use amaters_sdk_rust::{Result as SdkResult, SdkError};

    // FHE
    pub use amaters_sdk_rust::{FheEncryptor, FheKeys};

    // Query builder
    pub use amaters_sdk_rust::{FilterBuilder, FluentQueryBuilder, PredicateBuilder, query};
}

/// Library version
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

/// Library name
pub const NAME: &str = env!("CARGO_PKG_NAME");

#[cfg(test)]
mod tests {
    // Use explicit imports to avoid `core` ambiguity with Rust's built-in core
    use crate::cluster;
    use crate::core;
    use crate::net;
    use crate::sdk;
    use crate::{NAME, VERSION};

    // =========================================================================
    // Basic sanity tests
    // =========================================================================

    #[test]
    fn test_version() {
        assert!(VERSION.contains('.'), "VERSION should be semver format");
        assert_eq!(NAME, "amaters");
    }

    #[test]
    fn test_module_access() {
        // Verify all modules are accessible
        let _ = core::VERSION;
        let _ = net::VERSION;
        let _ = cluster::VERSION;
        let _ = sdk::VERSION;
    }

    #[test]
    fn test_prelude_imports() {
        use crate::prelude::*;

        // Verify prelude types are available
        let key = Key::from_str("test");
        assert!(!key.as_bytes().is_empty());
    }

    // =========================================================================
    // Prelude coverage tests
    // =========================================================================

    #[test]
    fn test_prelude_core_error_types() {
        use crate::prelude::*;

        // AmateRSError and ErrorContext should be accessible
        let ctx = ErrorContext::new("test error".to_string());
        let err = AmateRSError::ValidationError(ctx);
        let msg = format!("{}", err);
        assert!(!msg.is_empty());
    }

    #[test]
    fn test_prelude_core_types() {
        use crate::prelude::*;

        // Key
        let key = Key::from_str("test_key");
        assert_eq!(key.as_bytes(), b"test_key");

        // CipherBlob
        let blob = CipherBlob::new(vec![1, 2, 3]);
        assert_eq!(blob.len(), 3);
        assert_eq!(blob.as_bytes(), &[1, 2, 3]);

        // ColumnRef
        let cr = col("my_column");
        assert_eq!(cr.name, "my_column");

        // Query variants
        let _get = Query::Get {
            collection: "users".into(),
            key: Key::from_str("k"),
        };
        let _filter = Query::Filter {
            collection: "users".into(),
            predicate: Predicate::Eq(col("x"), CipherBlob::new(vec![1])),
        };
        let _range = Query::Range {
            collection: "data".into(),
            start: Key::from_str("a"),
            end: Key::from_str("z"),
        };

        // QueryBuilder
        let q = QueryBuilder::new("test").get(Key::from_str("k"));
        match q {
            Query::Get { collection, .. } => assert_eq!(collection, "test"),
            _ => panic!("Expected Get query"),
        }
    }

    #[test]
    fn test_prelude_cluster_types() {
        use crate::prelude::*;

        // RaftConfig
        let config = RaftConfig::new(1, vec![1, 2, 3]);
        assert_eq!(config.node_id, 1);

        // Command
        let cmd = Command::from_str("SET key value");
        assert!(!cmd.data.is_empty());

        // LogEntry
        let entry = LogEntry::new(1, 1, cmd);
        assert_eq!(entry.index, 1);
        assert_eq!(entry.term, 1);

        // NodeState
        let state = NodeState::Follower;
        assert_eq!(state, NodeState::Follower);

        // Type aliases
        let _: NodeId = 1;
        let _: Term = 1;
        let _: LogIndex = 1;
    }

    #[test]
    fn test_prelude_cluster_rpc_types() {
        use crate::prelude::*;

        // RequestVoteRequest
        let rvr = RequestVoteRequest {
            term: 1,
            candidate_id: 1,
            last_log_index: 0,
            last_log_term: 0,
        };
        assert_eq!(rvr.term, 1);

        // RequestVoteResponse
        let rvresp = RequestVoteResponse {
            term: 1,
            vote_granted: true,
            leader_hint: None,
        };
        assert!(rvresp.vote_granted);

        // AppendEntriesRequest
        let aer = AppendEntriesRequest {
            term: 1,
            leader_id: 1,
            prev_log_index: 0,
            prev_log_term: 0,
            entries: vec![],
            leader_commit: 0,
            fencing_token: None,
        };
        assert_eq!(aer.leader_id, 1);

        // AppendEntriesResponse
        let aeresp = AppendEntriesResponse {
            term: 1,
            success: true,
            last_log_index: 0,
            conflict_index: None,
            conflict_term: None,
            leader_hint: None,
            fencing_token: None,
        };
        assert!(aeresp.success);
    }

    #[test]
    fn test_prelude_cluster_state_types() {
        use crate::prelude::*;

        // PersistentState
        let ps = PersistentState::new();
        assert_eq!(ps.current_term, 0);

        // VolatileState
        let vs = VolatileState::new();
        assert_eq!(vs.node_state, NodeState::Follower);
    }

    #[test]
    fn test_prelude_sdk_config_types() {
        use crate::prelude::*;

        // ClientConfig
        let config = ClientConfig::default();
        assert!(!config.server_addr.is_empty() || config.server_addr.is_empty()); // verify type exists

        // RetryConfig
        let retry = RetryConfig::default();
        let _ = retry.max_retries; // verify type exists

        // TlsConfig exists
        let _tls = TlsConfig::default();
    }

    #[test]
    fn test_prelude_sdk_query_builder() {
        use crate::prelude::*;

        // query() function
        let q = query("users").get(Key::from_str("user:1"));
        match q {
            Query::Get { collection, key } => {
                assert_eq!(collection, "users");
                assert_eq!(key.as_bytes(), b"user:1");
            }
            _ => panic!("Expected Get query"),
        }

        // FluentQueryBuilder
        let fb = FluentQueryBuilder::new("test");
        let q = fb.set(Key::from_str("k"), CipherBlob::new(vec![1]));
        match q {
            Query::Set { collection, .. } => assert_eq!(collection, "test"),
            _ => panic!("Expected Set query"),
        }

        // PredicateBuilder + FilterBuilder
        let q = query("users")
            .where_clause()
            .eq(col("status"), CipherBlob::new(vec![1]))
            .and(Predicate::Gt(col("age"), CipherBlob::new(vec![18])))
            .build();
        match q {
            Query::Filter { collection, .. } => assert_eq!(collection, "users"),
            _ => panic!("Expected Filter query"),
        }
    }

    #[test]
    fn test_prelude_net_error_types() {
        use crate::prelude::*;

        // NetError should be constructable
        let _err: NetError = NetError::Timeout("test".to_string());
        let _result: NetResult<()> = Ok(());
    }

    #[test]
    fn test_prelude_sdk_error_types() {
        use crate::prelude::*;

        // SdkError should be constructable
        let _err: SdkError = SdkError::Connection("test".to_string());
        let _result: SdkResult<()> = Ok(());
    }

    // =========================================================================
    // Re-export consistency tests
    // =========================================================================

    #[test]
    fn test_reexport_core_types_consistency() {
        // Types accessed via amaters::core:: should be the same as via amaters_core::
        let key_via_facade = core::Key::from_str("test");
        let key_via_direct = amaters_core::Key::from_str("test");
        assert_eq!(key_via_facade.as_bytes(), key_via_direct.as_bytes());

        let blob_via_facade = core::CipherBlob::new(vec![1, 2, 3]);
        let blob_via_direct = amaters_core::CipherBlob::new(vec![1, 2, 3]);
        assert_eq!(blob_via_facade.as_bytes(), blob_via_direct.as_bytes());
    }

    #[test]
    fn test_reexport_net_consistency() {
        // Version via facade should match
        assert_eq!(net::VERSION, amaters_net::VERSION);
    }

    #[test]
    fn test_reexport_cluster_consistency() {
        // Version via facade should match
        assert_eq!(cluster::VERSION, amaters_cluster::VERSION);
        assert_eq!(cluster::NAME, amaters_cluster::NAME);
    }

    #[test]
    fn test_reexport_sdk_consistency() {
        // Version via facade should match
        assert_eq!(sdk::VERSION, amaters_sdk_rust::VERSION);
    }

    // =========================================================================
    // Cross-crate type compatibility tests
    // =========================================================================

    #[test]
    fn test_cross_crate_key_compatibility() {
        // Key from core can be used in SDK query builder
        let key = core::Key::from_str("cross_crate_key");
        let q = sdk::query("test").get(key);
        match q {
            core::Query::Get { key, .. } => {
                assert_eq!(key.as_bytes(), b"cross_crate_key");
            }
            _ => panic!("Expected Get query"),
        }
    }

    #[test]
    fn test_cross_crate_cipher_blob_compatibility() {
        // CipherBlob from core can be used in SDK
        let blob = core::CipherBlob::new(vec![10, 20, 30]);
        let q = sdk::query("test").set(core::Key::from_str("k"), blob);
        match q {
            core::Query::Set { value, .. } => {
                assert_eq!(value.as_bytes(), &[10, 20, 30]);
            }
            _ => panic!("Expected Set query"),
        }
    }

    #[test]
    fn test_cross_crate_predicate_compatibility() {
        // Predicate from core can be used in SDK's filter builder
        let pred = core::Predicate::Eq(core::col("status"), core::CipherBlob::new(vec![1]));

        let q = sdk::query("users").filter(pred);
        match q {
            core::Query::Filter { predicate, .. } => match predicate {
                core::Predicate::Eq(col_ref, value) => {
                    assert_eq!(col_ref.name, "status");
                    assert_eq!(value.as_bytes(), &[1]);
                }
                _ => panic!("Expected Eq predicate"),
            },
            _ => panic!("Expected Filter query"),
        }
    }

    #[test]
    fn test_cross_crate_query_with_planner() {
        // Query built with SDK can be planned with core's QueryPlanner
        let q = sdk::query("users").get(core::Key::from_str("user:1"));

        let planner = core::compute::QueryPlanner::new();
        let plan = planner.plan(&q);
        assert!(plan.is_ok(), "Planning should succeed for Get query");
    }

    // =========================================================================
    // Feature gate propagation tests
    // =========================================================================

    #[test]
    fn test_feature_flags_defined() {
        // These feature flags should exist in the crate
        // They are tested implicitly by compilation
        // full = ["mtls", "fhe"]
        // mtls -> amaters-net/mtls
        // fhe -> amaters-sdk-rust/fhe
        //
        // We verify that the default (no features) compiles correctly
        // by the fact that this test suite compiles at all.
        // Default features compile successfully — verified by this test compiling
    }

    #[test]
    fn test_storage_engine_accessible() {
        // StorageEngine trait should be accessible via multiple paths
        fn _check_trait_via_prelude() {
            use crate::prelude::StorageEngine;
            // Verify the trait exists and can be named
            fn _takes_engine<T: StorageEngine>(_e: &T) {}
        }

        fn _check_trait_via_core() {
            use crate::core::StorageEngine;
            fn _takes_engine<T: StorageEngine>(_e: &T) {}
        }
    }

    #[test]
    fn test_storage_types_accessible_via_facade() {
        // Verify storage types are accessible through the facade
        let _ = std::mem::size_of::<core::storage::LsmTreeConfig>();
        let _ = std::mem::size_of::<core::storage::MemtableConfig>();
        let _ = std::mem::size_of::<core::storage::SSTableConfig>();
        let _ = std::mem::size_of::<core::storage::CompactionConfig>();
        let _ = std::mem::size_of::<core::storage::BloomFilterConfig>();
        let _ = std::mem::size_of::<core::storage::BlockCacheConfig>();
    }

    #[test]
    fn test_compute_types_accessible_via_facade() {
        // Verify compute types are accessible through the facade
        let _ = std::mem::size_of::<core::compute::QueryPlanner>();
        let _ = std::mem::size_of::<core::compute::PhysicalPlan>();
        let _ = std::mem::size_of::<core::compute::LogicalPlan>();
        let _ = std::mem::size_of::<core::compute::PlanCost>();
        let _ = std::mem::size_of::<core::compute::CircuitBuilder>();
        let _ = std::mem::size_of::<core::compute::FheExecutor>();
    }

    #[test]
    fn test_cluster_types_accessible_via_facade() {
        // Verify cluster types are accessible through the facade
        let _ = std::mem::size_of::<cluster::RaftConfig>();
        let _ = std::mem::size_of::<cluster::Command>();
        let _ = std::mem::size_of::<cluster::LogEntry>();
        let _ = std::mem::size_of::<cluster::RaftLog>();
        let _ = std::mem::size_of::<cluster::PersistentState>();
        let _ = std::mem::size_of::<cluster::VolatileState>();
        let _ = std::mem::size_of::<cluster::Snapshot>();
        let _ = std::mem::size_of::<cluster::SnapshotConfig>();
    }

    #[test]
    fn test_sdk_types_accessible_via_facade() {
        // Verify SDK types are accessible through the facade
        let _ = std::mem::size_of::<sdk::ClientConfig>();
        let _ = std::mem::size_of::<sdk::RetryConfig>();
        let _ = std::mem::size_of::<sdk::TlsConfig>();
        let _ = std::mem::size_of::<sdk::FheKeys>();
        let _ = std::mem::size_of::<sdk::QueryCacheConfig>();
    }

    #[test]
    fn test_compression_accessible_via_facade() {
        // Verify compression utilities are accessible
        use core::storage::compression::{CompressionType, compress_block, decompress_block};

        let data = b"test data for compression";
        let compressed =
            compress_block(data, CompressionType::Lz4).expect("LZ4 compression should succeed");
        let decompressed = decompress_block(&compressed, CompressionType::Lz4, data.len())
            .expect("LZ4 decompression should succeed");
        assert_eq!(&decompressed, &data[..]);
    }

    // =========================================================================
    // Integration tests that combine multiple sub-crates
    // =========================================================================

    #[test]
    fn test_lsm_tree_via_facade() {
        use core::storage::LsmTree;

        let dir = std::env::temp_dir().join("amaters_facade_lsm_test");
        if dir.exists() {
            std::fs::remove_dir_all(&dir).ok();
        }

        let tree = LsmTree::new(&dir).expect("LsmTree creation should succeed");

        let key = core::Key::from_str("facade_test");
        let value = core::CipherBlob::new(vec![42, 43, 44]);

        tree.put(key.clone(), value.clone())
            .expect("put should succeed");

        let retrieved = tree
            .get(&key)
            .expect("get should succeed")
            .expect("key should exist");

        assert_eq!(retrieved.as_bytes(), &[42, 43, 44]);

        tree.delete(key.clone()).expect("delete should succeed");
        let gone = tree.get(&key).expect("get should succeed");
        assert!(gone.is_none());

        tree.close().expect("close should succeed");
        std::fs::remove_dir_all(&dir).ok();
    }

    #[test]
    fn test_query_planner_via_facade() {
        use core::compute::planner::QueryPlanner;

        let planner = QueryPlanner::new();

        // Plan a filter query
        let q = core::QueryBuilder::new("items").filter(core::Predicate::Gt(
            core::col("price"),
            core::CipherBlob::new(vec![100]),
        ));

        let plan = planner.plan(&q).expect("planning should succeed");
        let cost = planner.estimate_cost(&plan);

        assert!(cost.total_cost > 0.0, "Cost should be positive");
        assert!(cost.estimated_rows > 0, "Should estimate some rows");
    }

    #[test]
    fn test_raft_config_via_facade() {
        let config = cluster::RaftConfig::new(1, vec![1, 2, 3]);
        let node = cluster::RaftNode::new(config);
        assert!(node.is_ok(), "RaftNode creation should succeed");
    }
}