Skip to content

avidhanorkar/RustManager

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

9 Commits
Β 
Β 
Β 
Β 

Repository files navigation

RustManager - Task Management System

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.

πŸš€ Project Overview

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.

πŸ—οΈ Architecture

Backend (Rust + Axum)

  • Framework: Axum (async web framework)
  • Database: MongoDB with official Rust driver
  • Authentication: JWT (JSON Web Tokens)
  • Password Hashing: bcrypt
  • Async Runtime: Tokio

Key Features

  • 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

πŸ“ Project Structure

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
                      

πŸ”§ Prerequisites

  • Rust: Latest stable version (1.70+)
  • MongoDB: Local or cloud instance
  • Environment Variables: Configure required environment variables

πŸ› οΈ Installation & Setup

1. Clone the Repository

git clone <https://github.com/avidhanorkar/RustManager>
cd RustManager/backend

2. Install Dependencies

cargo build

3. Environment Configuration

Create a .env file in the backend directory:

# Required environment variables
MONGODB_URI=mongodb://localhost:27017
JWT_SECRET=your-secret-key-here
PORT=3000

4. Database Setup

Ensure MongoDB is running:

# Start MongoDB (if using local)
mongod

5. Run the Application

# Development mode
cargo run

# Production build
cargo build --release
./target/release/backend

πŸ“‘ API Endpoints

Authentication Endpoints

Method Endpoint Description
POST /user/register Register new user
POST /user/login User login
GET /user Get current user data

Task Management Endpoints

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

Health Check

Method Endpoint Description
GET / Basic health check

πŸ” Authentication

The API uses JWT tokens for authentication. After successful login, include the token in the Authorization header:

Authorization: Bearer <your-jwt-token>

πŸ“Š Data Models

User Model

User {
    user_id: Option<ObjectId>,
    username: String,
    email: String,
    password: String, // Hashed
    tasks: Vec<ObjectId>, // References to Task documents
}

Task Model

Task {
    task_id: Option<ObjectId>,
    taskname: String,
    status: String, // "Pending", "In Progress", "Completed"
    user_id: String, // Owner reference
}

πŸ§ͺ API Usage Examples

Register New User

curl -X POST http://localhost:3000/user/register \
  -H "Content-Type: application/json" \
  -d '{
    "username": "johndoe",
    "email": "john@example.com",
    "password": "securepassword"
  }'

User Login

curl -X POST http://localhost:3000/user/login \
  -H "Content-Type: application/json" \
  -d '{
    "email": "john@example.com",
    "password": "securepassword"
  }'

Create Task (with authentication)

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"
  }'

Get All Tasks

curl -X GET http://localhost:3000/task/getAll \
  -H "Authorization: Bearer <your-jwt-token>"

Update Task

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"
  }'

🚨 Error Handling

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

Environment Variables for Production

MONGODB_URI=mongodb+srv://<username>:<password>@cluster.mongodb.net/rustmanager
JWT_SECRET=your-production-secret-key
PORT=8080

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages