Skip to main content

Backend Setup

Guide for setting up and running the QsnDEX Rust backend locally.

Prerequisites​

Environment Configuration​

Copy the example environment file and fill in the required values:

cp .env.example .env

Required environment variables:

VariableDescription
DATABASE_URLPostgreSQL connection string (e.g., postgres://user:pass@localhost:5432/qsndex)
REDIS_URLRedis connection string (e.g., redis://localhost:6379)
GROQ_API_KEYAPI key for Groq LLM inference
KEEPER_PRIVATE_KEYPrivate key for keeper operations (limit orders, alerts)
TAIKO_RPC_URLTaiko mainnet RPC endpoint
ARB_SEPOLIA_RPC_URLArbitrum Sepolia testnet RPC endpoint

Build​

cd backend
cargo build --release

The release binary is output to target/release/.

Run​

The backend.sh management script provides convenient commands:

./backend.sh build     # Build the release binary
./backend.sh start # Start the server in the background
./backend.sh stop # Stop the running server
./backend.sh restart # Restart the server
./backend.sh status # Check if the server is running
./backend.sh logs # Tail server logs

Alternatively, run directly:

cd backend
cargo run --release

Verify​

Once running, the API is available at:

Test with a simple request:

curl http://localhost:8080/api/tokens?chain_id=167000

Database Migrations​

SQL migrations are located in backend/migrations/. They are applied automatically on server startup via SQLx. To run migrations manually:

cd backend
sqlx migrate run

Development Tips​

  • Use cargo watch -x run for automatic recompilation during development.
  • Set RUST_LOG=debug for verbose logging.
  • Redis must be running for rate limiting and caching to function.