Initial Rust/Axum API skeleton

This commit is contained in:
Jonas Müller 2026-01-08 10:00:00 +00:00
commit 3693a19411
7 changed files with 84 additions and 0 deletions

5
.env.example Normal file
View file

@ -0,0 +1,5 @@
DATABASE_URL=postgres://nexus:@localhost:5432/nexus_dev
JWT_SECRET=
JWT_EXPIRY_SECS=3600
PORT=8080
RUST_LOG=info

4
.gitignore vendored Normal file
View file

@ -0,0 +1,4 @@
/target
.env
*.log
Cargo.lock

23
Cargo.toml Normal file
View file

@ -0,0 +1,23 @@
[package]
name = "nexus-api"
version = "1.3.0"
edition = "2021"
[dependencies]
axum = "0.7"
tokio = { version = "1", features = ["full"] }
sqlx = { version = "0.7", features = ["postgres", "runtime-tokio", "uuid", "time"] }
serde = { version = "1", features = ["derive"] }
serde_json = "1"
uuid = { version = "1", features = ["v4"] }
jsonwebtoken = "9"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tower = "0.4"
tower-http = { version = "0.5", features = ["trace", "cors"] }
anyhow = "1"
thiserror = "1"
[dev-dependencies]
tokio-test = "0.4"
reqwest = { version = "0.12", features = ["json"] }

27
README.md Normal file
View file

@ -0,0 +1,27 @@
# nexus/backend-api
Core REST API for the Nexus platform. Built with Rust (Axum).
## Development
cargo build
cargo test
cargo run -- --port 8080
## Environment
Copy `.env.example` to `.env` before running locally.
## API Reference
| Endpoint | Method | Description |
|----------|--------|-------------|
| `/health` | GET | Liveness check |
| `/api/v1/users` | GET | List users |
| `/api/v1/users/:id` | GET | Get user by ID |
| `/api/v1/auth/login` | POST | Authenticate |
| `/api/v1/auth/refresh` | POST | Refresh JWT |
## Architecture
Request → Axum router → middleware (auth, logging) → handler → SQLx → PostgreSQL

6
src/api/health.rs Normal file
View file

@ -0,0 +1,6 @@
use axum::{http::StatusCode, Json};
use serde_json::{json, Value};
pub async fn health_check() -> (StatusCode, Json<Value>) {
(StatusCode::OK, Json(json!({ "status": "ok", "version": env!("CARGO_PKG_VERSION") })))
}

3
src/api/mod.rs Normal file
View file

@ -0,0 +1,3 @@
pub mod health;
pub mod users;
pub mod auth;

16
src/models/user.rs Normal file
View file

@ -0,0 +1,16 @@
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Serialize, Deserialize, sqlx::FromRow)]
pub struct User {
pub id: Uuid,
pub username: String,
pub email: String,
}
#[derive(Debug, Deserialize)]
pub struct CreateUserRequest {
pub username: String,
pub email: String,
pub password: String,
}