Well the project "Rust Manager" is a task manager which is a pretty basic one. But I am trying to learn Rust and I want to build a project which will help me learn Rust. So I decided to make a task manager such that with the help of this project I can learn the Axum framework on the go.
RustManager is a full-stack task management application that provides secure user authentication and task management capabilities. The backend is built with Rust using the Axum framework, MongoDB for data persistence, and JWT for secure authentication.
- Framework: Axum (async web framework)
- Database: MongoDB with official Rust driver
- Authentication: JWT (JSON Web Tokens)
- Password Hashing: bcrypt
- Async Runtime: Tokio
- User registration and authentication
- JWT-based secure API access
- CRUD operations for tasks
- MongoDB integration with ObjectId handling
- Middleware-based authentication
- Error handling and validation
RustManager/
βββ backend/
βββ src/
β βββ controller/
β β βββ auth_controller.rs
β β βββ task_controller.rs
β β βββ mod.rs
β βββ middleware/
β β βββ auth_middleware.rs
β β βββ mod.rs
β βββ models/
β β βββ user_model.rs
β β βββ task_model.rs
β β βββ mod.rs
β βββ routes/
β β βββ router.rs
β β βββ mod.rs
β βββ utils/
β β βββ db.rs
β β βββ mod.rs
β βββ main.rs
βββ Cargo.toml
βββ .gitignore
- Rust: Latest stable version (1.70+)
- MongoDB: Local or cloud instance
- Environment Variables: Configure required environment variables
git clone <https://github.com/avidhanorkar/RustManager>
cd RustManager/backendcargo buildCreate a .env file in the backend directory:
# Required environment variables
MONGODB_URI=mongodb://localhost:27017
JWT_SECRET=your-secret-key-here
PORT=3000Ensure MongoDB is running:
# Start MongoDB (if using local)
mongod# Development mode
cargo run
# Production build
cargo build --release
./target/release/backend| Method | Endpoint | Description |
|---|---|---|
| POST | /user/register |
Register new user |
| POST | /user/login |
User login |
| GET | /user |
Get current user data |
| Method | Endpoint | Description |
|---|---|---|
| POST | /task/create |
Create new task |
| PATCH | /task/update/{task_id} |
Update existing task |
| GET | /task/getAll |
Get all tasks for current user |
| Method | Endpoint | Description |
|---|---|---|
| GET | / |
Basic health check |
The API uses JWT tokens for authentication. After successful login, include the token in the Authorization header:
Authorization: Bearer <your-jwt-token>User {
user_id: Option<ObjectId>,
username: String,
email: String,
password: String, // Hashed
tasks: Vec<ObjectId>, // References to Task documents
}Task {
task_id: Option<ObjectId>,
taskname: String,
status: String, // "Pending", "In Progress", "Completed"
user_id: String, // Owner reference
}curl -X POST http://localhost:3000/user/register \
-H "Content-Type: application/json" \
-d '{
"username": "johndoe",
"email": "john@example.com",
"password": "securepassword"
}'curl -X POST http://localhost:3000/user/login \
-H "Content-Type: application/json" \
-d '{
"email": "john@example.com",
"password": "securepassword"
}'curl -X POST http://localhost:3000/task/create \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <your-jwt-token>" \
-d '{
"taskname": "Complete project documentation",
"status": "In Progress"
}'curl -X GET http://localhost:3000/task/getAll \
-H "Authorization: Bearer <your-jwt-token>"curl -X PATCH http://localhost:3000/task/update/<task-id> \
-H "Content-Type: application/json" \
-H "Authorization: Bearer <your-jwt-token>" \
-d '{
"taskname": "Updated task name",
"status": "Completed"
}'The API provides comprehensive error responses:
- 400 Bad Request: Invalid input data
- 401 Unauthorized: Invalid credentials or missing token
- 404 Not Found: Resource not found
- 500 Internal Server Error: Server-side errors
MONGODB_URI=mongodb+srv://<username>:<password>@cluster.mongodb.net/rustmanager
JWT_SECRET=your-production-secret-key
PORT=8080