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