allsource_core/lib.rs
1//! # AllSource Core - High-Performance Event Store
2//!
3//! A high-performance event sourcing platform built in Rust, following Clean Architecture principles.
4//!
5//! ## Architecture Overview
6//!
7//! The codebase follows a layered Clean Architecture:
8//!
9//! ```text
10//! ┌─────────────────────────────────────────────────────────────┐
11//! │ Infrastructure Layer │
12//! │ (HTTP handlers, WebSocket, persistence, security) │
13//! │ infrastructure::web, infrastructure::persistence, │
14//! │ infrastructure::security, infrastructure::repositories │
15//! ├─────────────────────────────────────────────────────────────┤
16//! │ Application Layer │
17//! │ (Use cases, services, DTOs) │
18//! │ application::use_cases, application::services, │
19//! │ application::dto │
20//! ├─────────────────────────────────────────────────────────────┤
21//! │ Domain Layer │
22//! │ (Entities, value objects, repository traits) │
23//! │ domain::entities, domain::value_objects, │
24//! │ domain::repositories │
25//! └─────────────────────────────────────────────────────────────┘
26//! ```
27//!
28//! ## Module Organization
29//!
30//! - **domain**: Core business entities, value objects, and repository traits
31//! - **application**: Use cases, services, and DTOs that orchestrate domain logic
32//! - **infrastructure**: Concrete implementations (web, persistence, security)
33//!
34//! ## Quick Start
35//!
36//! ```rust,ignore
37//! use allsource_core::{EventStore, Event, IngestEventRequest};
38//!
39//! let store = EventStore::new();
40//! let event = Event::from_strings(
41//! "user.created".to_string(),
42//! "user-123".to_string(),
43//! "default".to_string(),
44//! serde_json::json!({"name": "Alice"}),
45//! None,
46//! )?;
47//! store.ingest(event)?;
48//! ```
49
50// Safety: no unsafe code allowed in this crate
51#![forbid(unsafe_code)]
52// Development suppressions — tighten progressively
53#![allow(dead_code)]
54#![allow(unused_variables)]
55#![allow(deprecated)]
56// Clippy — allow patterns justified by architecture
57#![allow(clippy::too_many_arguments)]
58#![allow(clippy::type_complexity)]
59#![allow(clippy::module_inception)]
60
61// =============================================================================
62// Clean Architecture Layers
63// =============================================================================
64
65/// Layer 1: Domain Layer - Enterprise Business Rules
66///
67/// Contains pure business entities, value objects, and repository traits.
68/// This layer has ZERO external dependencies.
69pub mod domain;
70
71/// Layer 2: Application Layer - Application Business Rules
72///
73/// Contains use cases that orchestrate domain entities and services.
74/// Depends only on the domain layer.
75pub mod application;
76
77/// Layer 3: Infrastructure Layer - Interface Adapters
78///
79/// Contains concrete implementations of abstractions.
80/// Depends on domain and application layers.
81pub mod infrastructure;
82
83// =============================================================================
84// Shared Modules
85// =============================================================================
86
87/// Error types for the entire crate
88pub mod error;
89
90/// Main EventStore facade
91pub mod store;
92
93/// Advanced security module (anomaly detection, encryption, KMS)
94pub mod security;
95
96/// Shared test fixture builders for integration tests and cross-crate use
97pub mod test_utils;
98
99/// Test-only probe counting `Event` clones — lets unit tests assert on how much
100/// a call materializes, not just on what it returns. See issue #251.
101#[cfg(test)]
102mod clone_probe;
103
104/// Async webhook delivery worker
105#[cfg(feature = "server")]
106pub mod webhook_worker;
107
108/// AllSource Prime — unified agent memory engine (requires `prime` feature)
109#[cfg(feature = "prime")]
110pub mod prime;
111
112/// Ergonomic embedded-mode facade (requires `embedded` feature)
113#[cfg(feature = "embedded")]
114pub mod embedded;
115
116#[cfg(feature = "embedded")]
117pub use embedded::EmbeddedCore;
118
119// =============================================================================
120// Public API - Commonly Used Types
121// =============================================================================
122
123// Domain layer exports
124pub use domain::{entities, entities::Event, repositories};
125
126// Application layer exports
127pub use application::{
128 dto::{IngestEventRequest, QueryEventsRequest},
129 services::{
130 AnalyticsEngine, ExactlyOnceConfig, ExactlyOnceRegistry, Pipeline, PipelineConfig,
131 PipelineManager, ProjectionManager, ReplayManager, SchemaEvolutionManager, SchemaRegistry,
132 },
133};
134
135// Infrastructure layer exports
136#[cfg(feature = "server")]
137pub use infrastructure::security::{AuthManager, Permission, Role};
138#[cfg(feature = "server")]
139pub use infrastructure::web::{WebSocketManager, serve};
140pub use infrastructure::{
141 persistence::{
142 CompactionConfig, CompactionManager, EventIndex, ParquetStorage, SnapshotConfig,
143 SnapshotManager, WALConfig, WriteAheadLog,
144 },
145 security::RateLimiter,
146};
147
148// Error handling
149pub use error::{AllSourceError, Result};
150
151// =============================================================================
152// Backward-Compatible Aliases (for binaries and external users)
153// =============================================================================
154
155/// Auth module re-export for backward compatibility
156#[cfg(feature = "server")]
157pub mod auth {
158 pub use crate::infrastructure::security::{AuthManager, Permission, Role};
159}
160
161/// Rate limiting module re-export
162pub mod rate_limit {
163 pub use crate::infrastructure::security::rate_limit::{RateLimitConfig, RateLimiter};
164}
165
166/// Tenant module re-export
167pub mod tenant {
168 pub use crate::domain::entities::{Tenant, TenantQuotas};
169}
170
171/// Config module re-export
172pub mod config {
173 pub use crate::infrastructure::config::*;
174}
175
176/// Backup module re-export
177pub mod backup {
178 pub use crate::infrastructure::persistence::backup::*;
179}
180
181/// API v1 module re-export
182#[cfg(feature = "server")]
183pub mod api_v1 {
184 pub use crate::infrastructure::web::api_v1::{AppState, AtomicNodeRole, NodeRole, serve_v1};
185}
186
187/// Replication module re-export (enterprise feature)
188#[cfg(feature = "replication")]
189pub mod replication {
190 pub use crate::infrastructure::replication::{
191 FollowerReplicationStatus, ReplicationMode, ReplicationStatus, WalReceiver, WalShipper,
192 };
193}
194#[cfg(not(feature = "replication"))]
195pub mod replication {
196 pub use crate::infrastructure::replication::{
197 FollowerReplicationStatus, ReplicationMode, ReplicationStatus, WalReceiver, WalShipper,
198 };
199}
200
201/// Cluster module re-export
202pub mod cluster {
203 pub use crate::infrastructure::cluster::{
204 ClusterManager, ClusterMember, ClusterStatus, ConflictResolution, CrdtResolver,
205 GeoReplicationConfig, GeoReplicationManager, GeoReplicationStatus, GeoSyncRequest,
206 GeoSyncResponse, HlcTimestamp, HybridLogicalClock, MemberRole, MergeStrategy, Node,
207 NodeRegistry, PeerHealth, PeerRegion, PeerStatus, ReplicatedEvent, RequestRouter,
208 VersionVector, VoteRequest, VoteResponse,
209 };
210}
211
212/// RESP3 (Redis wire protocol) server re-export
213#[cfg(feature = "server")]
214pub mod resp {
215 pub use crate::infrastructure::resp::RespServer;
216}
217
218/// Advanced query features re-export (v2.0)
219pub mod query {
220 #[cfg(feature = "analytics")]
221 pub use crate::infrastructure::query::eventql::{
222 EventQLRequest, EventQLResponse, execute_eventql,
223 };
224 pub use crate::infrastructure::query::{
225 geospatial::{
226 BoundingBox, Coordinate, GeoEventResult, GeoIndex, GeoQueryRequest, RadiusQuery,
227 execute_geo_query, haversine_distance,
228 },
229 graphql::{
230 GraphQLError, GraphQLRequest, GraphQLResponse, QueryField, event_to_json,
231 introspection_schema, parse_query,
232 },
233 };
234}
235
236// Main store facade
237pub use store::EventStore;
238
239// =============================================================================
240// Tests
241// =============================================================================
242
243#[cfg(test)]
244mod security_integration_tests;