Production-ready Rust backend with Axum + PostgreSQL + JWT Auth, fully containerized with Docker.
| Layer | Crate |
|---|---|
| Web framework | axum |
| Database | sqlx + PostgreSQL |
| Documentation | utoipa + swagger-ui |
| Auth | jsonwebtoken (HS256) |
| Password hashing | argon2 (Argon2id) |
| Validation | validator |
| Config | dotenvy |
| Logging | tracing + tracing-subscriber |
| CORS | tower-http |
The project is optimized for Docker. You don't need Rust or PostgreSQL installed locally.
Copy the example environment file and set your variables (especially JWT_SECRET and ADMIN_PASSWORD):
cp .env.example .envdocker compose up --build- API Server:
http://localhost:3000 - Interactive API Docs (Swagger):
http://localhost:3000/docs
To apply changes made in .rs files, rebuild the container:
docker compose up --buildTo clear all data (e.g., after changing the admin password or SQL migrations):
docker compose down -v
docker compose up --buildThe -v flag removes volumes, including the physical PostgreSQL data files.
It is recommended to run tests inside the container to ensure they have access to the database:
docker compose run --rm testtests/api_tests.rs: Integration tests for the full router usingtower::oneshot(no network sockets required).- Unit tests can be added directly within the
src/modules.
GET /: Simple welcome message.GET /health: System health status (JSON).
POST /auth/register: Register a new user.POST /auth/login: Login and receive access/refresh tokens.POST /auth/refresh: Refresh your access token.
GET /dashboard: User dashboard (Requires JWT).GET /admin/users: List all users (Requires Admin JWT).
src/lib.rs: Main logic and router definition (used bymain.rsand tests).src/main.rs: Server entry point.src/routes/: API handlers grouped by module.src/middleware/: Custom middleware (Auth, etc.).src/db.rs: Database connection and migrations.tests/: Integration tests.