Backend Setup
Guide for setting up and running the QsnDEX Rust backend locally.
Prerequisites
- Rust 1.75 or later (install via rustup)
- PostgreSQL 16
- Redis 7
Environment Configuration
Copy the example environment file and fill in the required values:
cp .env.example .env
Required environment variables:
| Variable | Description |
|---|---|
DATABASE_URL | PostgreSQL connection string (e.g., postgres://user:pass@localhost:5432/qsndex) |
REDIS_URL | Redis connection string (e.g., redis://localhost:6379) |
GROQ_API_KEY | API key for Groq LLM inference |
KEEPER_PRIVATE_KEY | Private key for keeper operations (limit orders, alerts) |
TAIKO_RPC_URL | Taiko mainnet RPC endpoint |
ARB_SEPOLIA_RPC_URL | Arbitrum 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:
- API: http://localhost:8080
- Swagger UI: http://localhost:8080/swagger-ui
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 runfor automatic recompilation during development. - Set
RUST_LOG=debugfor verbose logging. - Redis must be running for rate limiting and caching to function.