Skip to main content

ceres_core/
lib.rs

1//! Ceres Core - Domain types, business logic, and services.
2//!
3//! This crate provides the core functionality for Ceres, including:
4//!
5//! - **Domain models**: [`Dataset`], [`SearchResult`], [`Portal`], etc.
6//! - **Business logic**: Delta detection, statistics tracking
7//! - **Services**: [`HarvestService`] for portal synchronization, [`SearchService`] for semantic search, [`ExportService`] for streaming exports
8//! - **Traits**: [`EmbeddingProvider`], [`DatasetStore`], [`PortalClient`] for dependency injection
9//! - **Progress reporting**: [`ProgressReporter`] trait for decoupled logging/UI
10//!
11//! # Architecture
12//!
13//! This crate is designed to be reusable by different frontends (CLI, server, etc.).
14//! Business logic is decoupled from I/O concerns through traits:
15//!
16//! # REST API (ceres-server)
17//!
18//! The REST API uses `utoipa` for automatic OpenAPI documentation with Swagger UI
19//! at `/swagger-ui`. See `ceres_server::openapi` for the implementation.
20//!
21//! - [`EmbeddingProvider`] - abstracts embedding generation (e.g., Gemini API)
22//! - [`DatasetStore`] - abstracts database operations (e.g., PostgreSQL)
23//! - [`PortalClient`] - abstracts portal access (e.g., CKAN API)
24//!
25//! # Example
26//!
27//! ```ignore
28//! use ceres_core::{HarvestService, PortalType, SearchService};
29//! use ceres_core::progress::TracingReporter;
30//!
31//! // Create services with your implementations
32//! let harvest = HarvestService::new(store, embedding, portal_factory);
33//! let reporter = TracingReporter;
34//! let stats = harvest
35//!     .sync_portal_with_progress("https://data.gov/api/3", None, "en", &reporter, PortalType::Ckan)
36//!     .await?;
37//!
38//! // Semantic search
39//! let search = SearchService::new(store, embedding);
40//! let results = search.search("climate data", 10).await?;
41//! ```
42
43pub mod circuit_breaker;
44pub mod config;
45pub mod error;
46pub mod export;
47pub mod harvest;
48pub mod i18n;
49pub mod job;
50pub mod job_queue;
51pub mod models;
52pub mod parquet_export;
53pub mod progress;
54pub mod search;
55pub mod sync;
56pub mod traits;
57pub mod worker;
58
59// Circuit breaker
60pub use circuit_breaker::{
61    CircuitBreaker, CircuitBreakerConfig, CircuitBreakerError, CircuitBreakerStats, CircuitState,
62};
63
64// Configuration
65pub use config::{
66    DbConfig, HttpConfig, PortalEntry, PortalType, PortalsConfig, SyncConfig, default_config_path,
67    load_portals_config,
68};
69
70// Error handling
71pub use error::AppError;
72
73// Internationalization
74pub use i18n::LocalizedField;
75
76// Domain models
77pub use models::{DatabaseStats, Dataset, NewDataset, SearchResult};
78
79// Sync types and business logic
80pub use sync::{
81    AlwaysReprocessDetector, AtomicSyncStats, BatchHarvestSummary, ContentHashDetector,
82    DeltaDetector, PortalHarvestResult, ReprocessingDecision, SyncOutcome, SyncResult, SyncStats,
83    SyncStatus, needs_reprocessing,
84};
85
86// Progress reporting
87pub use progress::{HarvestEvent, ProgressReporter, SilentReporter, TracingReporter};
88
89// Traits for dependency injection
90pub use traits::{DatasetStore, EmbeddingProvider, PortalClient, PortalClientFactory};
91
92// Services (generic over trait implementations)
93pub use export::{ExportFormat, ExportService};
94pub use harvest::HarvestService;
95pub use parquet_export::{ParquetExportConfig, ParquetExportResult, ParquetExportService};
96pub use search::SearchService;
97
98// Job queue types
99pub use job::{CreateJobRequest, HarvestJob, JobStatus, RetryConfig, WorkerConfig};
100pub use job_queue::JobQueue;
101
102// Worker service
103pub use worker::{
104    SilentWorkerReporter, TracingWorkerReporter, WorkerEvent, WorkerReporter, WorkerService,
105};