Skip to main content

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/// Async webhook delivery worker
100#[cfg(feature = "server")]
101pub mod webhook_worker;
102
103/// Ergonomic embedded-mode facade (requires `embedded` feature)
104#[cfg(feature = "embedded")]
105pub mod embedded;
106
107#[cfg(feature = "embedded")]
108pub use embedded::EmbeddedCore;
109
110// =============================================================================
111// Public API - Commonly Used Types
112// =============================================================================
113
114// Domain layer exports
115pub use domain::{entities, entities::Event, repositories};
116
117// Application layer exports
118pub use application::{
119    dto::{IngestEventRequest, QueryEventsRequest},
120    services::{
121        AnalyticsEngine, ExactlyOnceConfig, ExactlyOnceRegistry, Pipeline, PipelineConfig,
122        PipelineManager, ProjectionManager, ReplayManager, SchemaEvolutionManager, SchemaRegistry,
123        TenantManager,
124    },
125};
126
127// Infrastructure layer exports
128#[cfg(feature = "server")]
129pub use infrastructure::security::{AuthManager, Permission, Role};
130#[cfg(feature = "server")]
131pub use infrastructure::web::{WebSocketManager, serve};
132pub use infrastructure::{
133    persistence::{
134        CompactionConfig, CompactionManager, EventIndex, ParquetStorage, SnapshotConfig,
135        SnapshotManager, WALConfig, WriteAheadLog,
136    },
137    security::RateLimiter,
138};
139
140// Error handling
141pub use error::{AllSourceError, Result};
142
143// =============================================================================
144// Backward-Compatible Aliases (for binaries and external users)
145// =============================================================================
146
147/// Auth module re-export for backward compatibility
148#[cfg(feature = "server")]
149pub mod auth {
150    pub use crate::infrastructure::security::{AuthManager, Permission, Role};
151}
152
153/// Rate limiting module re-export
154pub mod rate_limit {
155    pub use crate::infrastructure::security::rate_limit::{RateLimitConfig, RateLimiter};
156}
157
158/// Tenant module re-export
159pub mod tenant {
160    pub use crate::{
161        application::services::tenant_service::{TenantManager, TenantQuotas},
162        domain::entities::Tenant,
163    };
164}
165
166/// Config module re-export
167pub mod config {
168    pub use crate::infrastructure::config::*;
169}
170
171/// Backup module re-export
172pub mod backup {
173    pub use crate::infrastructure::persistence::backup::*;
174}
175
176/// API v1 module re-export
177#[cfg(feature = "server")]
178pub mod api_v1 {
179    pub use crate::infrastructure::web::api_v1::{AppState, AtomicNodeRole, NodeRole, serve_v1};
180}
181
182/// Replication module re-export
183pub mod replication {
184    pub use crate::infrastructure::replication::{
185        FollowerReplicationStatus, ReplicationMode, ReplicationStatus, WalReceiver, WalShipper,
186    };
187}
188
189/// Cluster module re-export
190pub mod cluster {
191    pub use crate::infrastructure::cluster::{
192        ClusterManager, ClusterMember, ClusterStatus, ConflictResolution, CrdtResolver,
193        GeoReplicationConfig, GeoReplicationManager, GeoReplicationStatus, GeoSyncRequest,
194        GeoSyncResponse, HlcTimestamp, HybridLogicalClock, MemberRole, MergeStrategy, Node,
195        NodeRegistry, PeerHealth, PeerRegion, PeerStatus, ReplicatedEvent, RequestRouter,
196        VersionVector, VoteRequest, VoteResponse,
197    };
198}
199
200/// RESP3 (Redis wire protocol) server re-export
201#[cfg(feature = "server")]
202pub mod resp {
203    pub use crate::infrastructure::resp::RespServer;
204}
205
206/// Advanced query features re-export (v2.0)
207pub mod query {
208    #[cfg(feature = "analytics")]
209    pub use crate::infrastructure::query::eventql::{
210        EventQLRequest, EventQLResponse, execute_eventql,
211    };
212    pub use crate::infrastructure::query::{
213        geospatial::{
214            BoundingBox, Coordinate, GeoEventResult, GeoIndex, GeoQueryRequest, RadiusQuery,
215            execute_geo_query, haversine_distance,
216        },
217        graphql::{
218            GraphQLError, GraphQLRequest, GraphQLResponse, QueryField, event_to_json,
219            introspection_schema, parse_query,
220        },
221    };
222}
223
224// Main store facade
225pub use store::EventStore;
226
227// =============================================================================
228// Tests
229// =============================================================================
230
231#[cfg(test)]
232mod security_integration_tests;