mockforge_collab/
config.rs

1//! Configuration for collaboration server
2
3use serde::{Deserialize, Serialize};
4use std::time::Duration;
5
6/// Collaboration server configuration
7#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct CollabConfig {
9    /// JWT secret for authentication
10    pub jwt_secret: String,
11    /// Database URL (SQLite or PostgreSQL)
12    pub database_url: String,
13    /// Server bind address
14    pub bind_address: String,
15    /// Maximum connections per workspace
16    pub max_connections_per_workspace: usize,
17    /// Event bus capacity
18    pub event_bus_capacity: usize,
19    /// Enable auto-commit for changes
20    pub auto_commit: bool,
21    /// Session timeout duration
22    pub session_timeout: Duration,
23    /// WebSocket ping interval
24    pub websocket_ping_interval: Duration,
25    /// Maximum message size (bytes)
26    pub max_message_size: usize,
27}
28
29impl Default for CollabConfig {
30    fn default() -> Self {
31        Self {
32            jwt_secret: "change-me-in-production".to_string(),
33            database_url: "sqlite://mockforge-collab.db".to_string(),
34            bind_address: "127.0.0.1:8080".to_string(),
35            max_connections_per_workspace: 100,
36            event_bus_capacity: 1000,
37            auto_commit: true,
38            session_timeout: Duration::from_secs(24 * 3600), // 24 hours
39            websocket_ping_interval: Duration::from_secs(30),
40            max_message_size: 1024 * 1024, // 1 MB
41        }
42    }
43}
44
45impl CollabConfig {
46    /// Load configuration from environment variables
47    pub fn from_env() -> Self {
48        Self {
49            jwt_secret: std::env::var("MOCKFORGE_JWT_SECRET")
50                .unwrap_or_else(|_| "change-me-in-production".to_string()),
51            database_url: std::env::var("MOCKFORGE_DATABASE_URL")
52                .unwrap_or_else(|_| "sqlite://mockforge-collab.db".to_string()),
53            bind_address: std::env::var("MOCKFORGE_BIND_ADDRESS")
54                .unwrap_or_else(|_| "127.0.0.1:8080".to_string()),
55            ..Default::default()
56        }
57    }
58}