added initial roadmap and implementation

This commit is contained in:
2026-03-11 22:23:16 +02:00
parent 39b97a6db5
commit c0792f2e1d
62 changed files with 12410 additions and 1 deletions

15
common/Cargo.toml Normal file
View File

@@ -0,0 +1,15 @@
[package]
name = "common"
version = "0.1.0"
edition = "2021"
[dependencies]
tokio = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
tracing = { workspace = true }
sqlx = { workspace = true }
thiserror = { workspace = true }
anyhow = { workspace = true }
config = { workspace = true }
dotenvy = { workspace = true }

60
common/src/config.rs Normal file
View File

@@ -0,0 +1,60 @@
use serde::{Deserialize, Serialize};
use std::env;
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct Config {
pub database_url: String,
pub jwt_secret: String,
pub port: u16,
pub google_client_id: Option<String>,
pub google_client_secret: Option<String>,
pub github_client_id: Option<String>,
pub github_client_secret: Option<String>,
pub redirect_uri: String,
pub rate_limit_per_second: u64,
}
impl Config {
pub fn new() -> Result<Self, config::ConfigError> {
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be set");
let jwt_secret =
env::var("JWT_SECRET").unwrap_or_else(|_| "super-secret-key-please-change".to_string());
let port = env::var("PORT")
.unwrap_or_else(|_| "8000".to_string())
.parse()
.unwrap_or(8000);
let rate_limit_per_second = env::var("RATE_LIMIT_PER_SECOND")
.unwrap_or_else(|_| "10".to_string())
.parse()
.unwrap_or(10);
let google_client_id = env::var("GOOGLE_CLIENT_ID").ok();
let google_client_secret = env::var("GOOGLE_CLIENT_SECRET").ok();
let github_client_id = env::var("GITHUB_CLIENT_ID").ok();
let github_client_secret = env::var("GITHUB_CLIENT_SECRET").ok();
let redirect_uri = env::var("REDIRECT_URI")
.unwrap_or_else(|_| "http://localhost:8000/auth/v1/callback".to_string());
Ok(Config {
database_url,
jwt_secret,
port,
google_client_id,
google_client_secret,
github_client_id,
github_client_secret,
redirect_uri,
rate_limit_per_second,
})
}
}
// New struct for Project Context
#[derive(Clone, Debug)]
pub struct ProjectContext {
pub project_ref: String,
pub db_url: String,
pub jwt_secret: String,
pub anon_key: Option<String>,
pub service_role_key: Option<String>,
}

10
common/src/db.rs Normal file
View File

@@ -0,0 +1,10 @@
use sqlx::postgres::{PgPool, PgPoolOptions};
use std::time::Duration;
pub async fn init_pool(database_url: &str) -> Result<PgPool, sqlx::Error> {
PgPoolOptions::new()
.max_connections(20)
.acquire_timeout(Duration::from_secs(3))
.connect(database_url)
.await
}

5
common/src/lib.rs Normal file
View File

@@ -0,0 +1,5 @@
pub mod config;
pub mod db;
pub use config::{Config, ProjectContext};
pub use db::init_pool;