Skip to content

mrjackwills/staticpi_backend

Repository files navigation

The simple messaging service

staticpi.com backend

currently powering staticpi.com

Built in Rust for Docker, using PostgreSQL & Redis.
This is the backend for staticpi_vue front-end, and is an on-going work in progress.



The backend is a CRUD api, token server, and websocket message forwarder, with the following features;

  • axum based with tokio async mutlithreading
  • Websocket connection & message forwarding
  • Time sensitive, IP locked, token generation
  • Password hashing with argon2
  • Weak password resolution & rejection, powered by hibp
  • Time based Two-Factor Authentication
  • Two-Factor Authentication backup codes
  • User sessions using private cookie with a redis backend
  • Redis based multitudinous rate limiting
  • Automated email templating & sending, using mjml
  • User & Admin user accounts
  • Restricted User area
  • Restricted Admin user area
  • strict CORS settings for API, but open CORS for websocket & token server
  • Customised incoming serde serialization & extraction
  • Error tracing
  • Internal "Contact Us" messaging
  • Redis based cache
  • Postgres main data store
  • Scheduled automated database backup & encryption
  • (attempted complete) test coverage
  • Automated github build step
  • Fully Dockerised production environment
  • Development remote container (using vscode)

Download

See releases

download (x86_64_linux one liner)

wget https://www.github.com/mrjackwills/staticpi_backend/releases/latest/download/staticpi_linux_x86_64.tar.gz &&
tar xzvf staticpi_linux_x86_64.tar.gz staticpi

Run

Operate docker compose containers via

./run.sh

Build

cargo build --release
Build using cross-rs, for x86_64 linux musl targets, in order to run in an Alpine based container
cross build --target x86_64-unknown-linux-musl --release

Tests

Requires postgres & redis to both be operational and built with valid structure - init_db.sql.

# Watch
cargo watch -q -c -w src/ -x 'test -- --test-threads=1 --nocapture'

# Run all 
cargo test -- --test-threads=1 --nocapture


# cargo taupalin -- --test-threads=1
# Test coverage, requires cargo-llvm-cov to be installed globally
# then: `rustup component add llvm-tools-preview --toolchain 1.61.0-x86_64-unknown-linux-gnu
cargo llvm-cov -- --test-threads=1