Skip to main content

perfgate_server/
lib.rs

1//! perfgate-server - REST API server for centralized baseline management.
2//!
3//! This crate provides a REST API server for storing and managing performance
4//! baselines. It supports multiple storage backends (in-memory, SQLite, PostgreSQL)
5//! and includes authentication via API keys.
6//!
7//! # Features
8//!
9//! - **Multi-tenancy**: Projects/namespaces for isolation
10//! - **Version history**: Track baseline versions over time
11//! - **Rich metadata**: Git refs, tags, custom metadata
12//! - **Access control**: Role-based permissions (Viewer, Contributor, Promoter, Admin)
13//! - **Multiple backends**: In-memory, SQLite, PostgreSQL (planned)
14//!
15//! # Quick Start
16//!
17//! ```rust,no_run
18//! use perfgate_server::{ServerConfig, StorageBackend, run_server};
19//!
20//! #[tokio::main]
21//! async fn main() {
22//!     let config = ServerConfig::new()
23//!         .bind("0.0.0.0:8080").unwrap()
24//!         .storage_backend(StorageBackend::Sqlite)
25//!         .sqlite_path("perfgate.db");
26//!
27//!     run_server(config).await.unwrap();
28//! }
29//! ```
30//!
31//! # API Endpoints
32//!
33//! | Method | Path | Description |
34//! |--------|------|-------------|
35//! | POST | `/projects/{project}/baselines` | Upload a baseline |
36//! | GET | `/projects/{project}/baselines/{benchmark}/latest` | Get latest baseline |
37//! | GET | `/projects/{project}/baselines/{benchmark}/versions/{version}` | Get specific version |
38//! | GET | `/projects/{project}/baselines` | List baselines |
39//! | DELETE | `/projects/{project}/baselines/{benchmark}/versions/{version}` | Delete baseline |
40//! | POST | `/projects/{project}/baselines/{benchmark}/promote` | Promote version |
41//! | GET | `/health` | Health check |
42
43pub mod auth;
44pub mod error;
45pub mod handlers;
46pub mod models;
47pub mod server;
48pub mod storage;
49
50#[cfg(any(test, feature = "test-utils"))]
51pub mod testing;
52
53pub use auth::{ApiKey, ApiKeyStore, AuthContext, AuthState, JwtClaims, JwtConfig, Role, Scope};
54pub use error::{AuthError, ConfigError, StoreError};
55pub use models::*;
56pub use server::{ServerConfig, StorageBackend, run_server};
57pub use storage::{BaselineStore, InMemoryStore, SqliteStore, StorageHealth};
58
59/// Server version string.
60pub const VERSION: &str = env!("CARGO_PKG_VERSION");
61
62#[cfg(test)]
63mod tests {
64    use super::*;
65
66    #[test]
67    fn test_version() {
68        assert!(!VERSION.is_empty());
69    }
70}