Skip to content

Commit

Permalink
Restructure file structure (#49)
Browse files Browse the repository at this point in the history
* Restructure packages to crates, combine common and db

* Fix docker image for new file structure
  • Loading branch information
sneakycrow authored Feb 2, 2025
1 parent 29122fe commit 74be47b
Show file tree
Hide file tree
Showing 48 changed files with 36 additions and 65 deletions.
26 changes: 8 additions & 18 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
[workspace]
members = [
"packages/db",
"packages/vod",
"packages/queue",
"services/forge-queue",
"services/silo-api", "packages/common",
]
members = ["crates/*", "services/forge-queue", "services/silo-api"]

resolver = "2"
2 changes: 1 addition & 1 deletion config/api.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ WORKDIR /app
COPY Cargo.toml Cargo.lock ./

# Copy all workspace members
COPY packages/ ./packages/
COPY crates/ ./crates/
COPY services/forge-queue ./services/forge-queue
COPY services/silo-api ./services/silo-api

Expand Down
2 changes: 1 addition & 1 deletion config/queue.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ WORKDIR /app
COPY Cargo.toml Cargo.lock ./

# Copy all workspace members
COPY packages/ ./packages/
COPY crates/ ./crates/
COPY services/forge-queue ./services/forge-queue
COPY services/silo-api ./services/silo-api

Expand Down
6 changes: 5 additions & 1 deletion packages/db/Cargo.toml → crates/common/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
[package]
name = "db"
name = "common"
version = "0.1.0"
edition = "2021"

[dependencies]
aws-sdk-s3 = "1.66.0"
aws-config = { version = "1.5.11", features = ["behavior-version-latest"] }
aws-types = "1.3.3"
walkdir = "2.5.0"
argon2 = { version = "0.5", features = ["password-hash"] }
chrono = { version = "0.4", features = ["serde"] }
serde = { version = "1.0", features = ["derive"] }
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions packages/common/src/lib.rs → crates/common/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pub mod db;
pub mod s3;

/// Get the directory for where to store videos
Expand Down
File renamed without changes.
5 changes: 2 additions & 3 deletions packages/queue/Cargo.toml → crates/queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2021"
anyhow = "1"
async-trait = "0.1"
chrono = "0.4"
db = { path = "../../packages/db" }
common = { path = "../common" }
futures = "0.3"
serde = { version = "1", features = ["derive"] }
thiserror = "1"
Expand All @@ -22,6 +22,5 @@ tokio = { version = "1", features = ["full"] }
tracing = "0.1"
ulid = { version = "1", features = ["uuid"] }
uuid = { version = "1", features = ["serde", "v4"] }
vod = { path = "../../packages/vod" }
vod = { path = "../vod" }
zip = "0.6"
common = { path = "../common" }
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use crate::queue::{Job, Message, Queue};
use anyhow::anyhow;
use common::get_storage_dir;
use common::s3::sync_directory_to_bucket;
use db::Video;
use common::db::Video;
use futures::{stream, StreamExt};
use sqlx::{Pool, Postgres};
use std::fs;
Expand Down
1 change: 0 additions & 1 deletion packages/vod/Cargo.toml → crates/vod/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,5 @@ edition = "2021"
[dependencies]
anyhow = "1.0"
tracing = "0.1"
db = { path = "../db" }
aws-sdk-s3 = "1.71.0"
common = { path = "../common" }
2 changes: 1 addition & 1 deletion packages/vod/src/lib.rs → crates/vod/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::path::PathBuf;

use anyhow::anyhow;
use aws_sdk_s3::Client;
use db::{DBPool, Video};
use common::db::{DBPool, Video};
use stream::{get_ffmpeg_location, HLSConverter};

pub mod stream;
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion justfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ create-db:
drop-db:
sqlx database drop

mig_source := "packages/db/migrations"
mig_source := "crates/common/migrations"

mig: migrate
migrate:
Expand Down
11 changes: 0 additions & 11 deletions packages/common/Cargo.toml

This file was deleted.

4 changes: 2 additions & 2 deletions services/forge-queue/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ edition = "2021"
[dependencies]
anyhow = "1"
axum = { version = "0.7.9", features = ["tracing"] }
db = { path = "../../packages/db" }
queue = { path = "../../packages/queue" }
common = { path = "../../crates/common" }
queue = { path = "../../crates/queue" }
tokio = { version = "1", features = ["full"] }
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
2 changes: 1 addition & 1 deletion services/forge-queue/src/main.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use db::connect_to_database;
use common::db::connect_to_database;
use queue::{runner, PostgresQueue, Queue};
use std::sync::Arc;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt};
Expand Down
5 changes: 2 additions & 3 deletions services/silo-api/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ edition = "2021"
axum = { version = "0.7", features = ["multipart", "tracing", "ws", "macros"] }
axum-extra = "0.3"
chrono = { version = "0.4.31", features = ["serde"] }
db = { path = "../../packages/db" }
futures = "0.3"
hex = "0.4"
sha2 = "0.10"
jsonwebtoken = "8.1"
lazy_static = "1.4"
nanoid = "0.4.0"
queue = { path = "../../packages/queue" }
queue = { path = "../../crates/queue" }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
sqlx = { version = "0.8", features = [
Expand All @@ -35,4 +34,4 @@ reqwest = { version = "0.12.9", features = ["json"] }
aws-sdk-s3 = "1.66.0"
aws-config = { version = "1.5.11", features = ["behavior-version-latest"] }
aws-types = "1.3.3"
common = { path = "../../packages/common" }
common = { path = "../../crates/common" }
2 changes: 1 addition & 1 deletion services/silo-api/src/app_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ pub struct AppState {
impl AppState {
pub async fn new(config: Config) -> Result<Self, Box<dyn std::error::Error>> {
// Initialize a connection to the database
let db = db::connect_to_database()
let db = common::db::connect_to_database()
.await
.expect("Could not connect to database");
// Initialize the queue
Expand Down
6 changes: 1 addition & 5 deletions services/silo-api/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@ mod routes;

pub use app_state::AppState;
use axum::{
extract::State,
middleware as axum_mw,
response::IntoResponse,
routing::{delete, get, post},
Json, Router,
Router,
};
use config::Config;
use reqwest::StatusCode;

use serde_json::json;

use std::sync::Arc;
use tower_http::{
Expand Down
2 changes: 1 addition & 1 deletion services/silo-api/src/middleware/auth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use axum::{
http::{self, Response, StatusCode},
middleware::Next,
};
use db::users::User;
use common::db::users::User;
use uuid::Uuid;

/// A middleware for checking the validity of the JWT token
Expand Down
2 changes: 1 addition & 1 deletion services/silo-api/src/routes/auth/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pub mod oauth;
use std::sync::Arc;

use axum::{extract::State, http::StatusCode, response::IntoResponse, Json};
use db::users::User;
use common::db::users::User;
use serde::{Deserialize, Serialize};

use crate::{jwt::encode_jwt, AppState};
Expand Down
2 changes: 1 addition & 1 deletion services/silo-api/src/routes/auth/oauth/twitch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use axum::{
Extension,
};
use chrono::{Duration, Utc};
use db::{accounts::Account, users::User};
use common::db::{accounts::Account, users::User};
use reqwest::Client;
use serde::{Deserialize, Serialize};
use std::{env, sync::Arc};
Expand Down
2 changes: 1 addition & 1 deletion services/silo-api/src/routes/upload/cloud.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::sync::Arc;

use aws_sdk_s3::types::{CompletedMultipartUpload, CompletedPart};
use axum::{extract::State, Extension, Json};
use db::{User, Video};
use common::db::{User, Video};
use reqwest::StatusCode;
use serde::{Deserialize, Serialize};

Expand Down
2 changes: 1 addition & 1 deletion services/silo-api/src/routes/upload/on_disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use axum::{
http::StatusCode,
Extension,
};
use db::{users::User, Video};
use common::db::{users::User, Video};
use sha2::{Digest, Sha256};
use std::sync::atomic::{AtomicU64, Ordering};
use std::{collections::HashMap, path::Path, sync::Arc};
Expand Down
2 changes: 1 addition & 1 deletion services/silo-api/src/routes/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use axum::{
response::IntoResponse,
Extension, Json,
};
use db::users::{User, UserRole};
use common::db::users::{User, UserRole};
use serde::{Deserialize, Serialize};

use crate::AppState;
Expand Down
2 changes: 1 addition & 1 deletion services/silo-api/src/routes/video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use axum::{
response::IntoResponse,
Extension, Json,
};
use db::{ProcessingStatus, User, Video};
use common::db::{self, ProcessingStatus, User, Video};
use serde::{Deserialize, Serialize};
use std::sync::Arc;

Expand Down

0 comments on commit 74be47b

Please sign in to comment.