Set up monorepo Docker development

This commit is contained in:
2026-09-19 20:56:07 +02:00
parent ab4cfe40c8
commit 5b45203c14
13 changed files with 33 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
/target
.git
.env
.vscode
.DS_Store
+3
View File
@@ -0,0 +1,3 @@
/target
.env
.DS_Store
+4
View File
@@ -0,0 +1,4 @@
{
"editor.formatOnSave": true,
"rust-analyzer.check.command": "clippy"
}
+1204
View File
File diff suppressed because it is too large Load Diff
+15
View File
@@ -0,0 +1,15 @@
[package]
name = "server"
version = "0.1.0"
edition = "2024"
[dependencies]
axum = { version = "0.8.9", features = ["macros"] }
chrono = { version = "0.4.45", features = ["serde"] }
dotenv = "0.15.0"
serde = { version = "1.0.229", features = ["derive"] }
serde_json = "1.0.151"
tokio = { version = "1.53.1", features = ["full"] }
tracing = "0.1.44"
tracing-subscriber = { version = "0.3.23", features = ["env-filter"] }
uuid = { version = "1.26.1", features = ["serde", "v4"] }
+9
View File
@@ -0,0 +1,9 @@
FROM rust:bookworm
RUN cargo install cargo-watch --locked
WORKDIR /app
EXPOSE 3000
CMD ["cargo", "watch", "--watch", "src", "--watch", "Cargo.toml", "--watch", "Cargo.lock", "--exec", "run --locked"]
+2
View File
@@ -0,0 +1,2 @@
Expenses Server
===
+27
View File
@@ -0,0 +1,27 @@
use std::env;
use tokio::net::TcpListener;
mod models;
mod routes;
#[tokio::main]
#[tracing::instrument]
async fn main() {
dotenv::dotenv().ok();
tracing_subscriber::fmt()
.with_env_filter(tracing_subscriber::EnvFilter::from_default_env())
.init();
let host = env::var("HOST").unwrap_or_else(|_| "0.0.0.0".to_string());
let port = env::var("PORT").unwrap_or_else(|_| "3000".to_string());
let listener = TcpListener::bind(format!("{}:{}", host, port))
.await
.expect("Failed to bind to address");
tracing::info!("Starting server at {}:{}", host, port);
axum::serve(listener, routes::create_router().into_make_service())
.await
.expect("Failed to start server");
}
+1
View File
@@ -0,0 +1 @@
pub mod transaction;
+11
View File
@@ -0,0 +1,11 @@
use chrono::{DateTime, Utc};
use serde::Serialize;
use uuid::Uuid;
#[derive(Serialize)]
pub struct Transaction {
pub id: Uuid,
pub description: String,
pub amount: f64,
pub date: DateTime<Utc>,
}
+8
View File
@@ -0,0 +1,8 @@
mod transactions;
pub fn create_router() -> axum::Router {
axum::Router::new().nest(
"/api",
axum::Router::new().nest("/transactions", transactions::create_router()),
)
}
+23
View File
@@ -0,0 +1,23 @@
use crate::models::transaction::Transaction;
pub fn create_router() -> axum::Router {
axum::Router::new().route("/", axum::routing::get(get_transactions))
}
#[tracing::instrument]
pub async fn get_transactions() -> axum::Json<Vec<Transaction>> {
axum::Json(vec![
Transaction {
id: uuid::Uuid::new_v4(),
description: "Groceries".to_string(),
amount: 42.50,
date: chrono::Utc::now(),
},
Transaction {
id: uuid::Uuid::new_v4(),
description: "Coffee".to_string(),
amount: 4.25,
date: chrono::Utc::now(),
},
])
}