This project implements a file sharing backend using Rust, featuring end-to-end encryption to ensure the privacy and security of shared files.
- Rust: The primary programming language for the backend.
- Axum: A lightweight and ergonomic web framework for building APIs in Rust.
- SQLx: An asynchronous, compile-time verified SQL crate supporting multiple databases (in this case, PostgreSQL).
- Argon2: A secure password hashing library.
- jsonwebtoken: A library for encoding and decoding JSON Web Tokens (JWT) for authentication.
- dotenv: For managing environment variables in development.
- Tokio: An asynchronous runtime for Rust, powering the non-blocking operations.
- Axum-Extra: Additional utilities for Axum, including cookie support.
- Tokio-Cron-Scheduler: A scheduler library for running tasks periodically based on cron-like expressions.
- Tower & Tower-HTTP: Middleware and utilities for building robust HTTP services, including CORS and tracing support.
- Serde & Serde JSON: A framework for serializing and deserializing Rust data structures efficiently, used with JSON data.
- Validator: A validation framework for input validation in Rust.
- Chrono: A date and time library, used with
serde
for working with time formats. - UUID: A library for generating and parsing universally unique identifiers (UUIDs).
- Tracing Subscriber: A logging library for Rust applications, providing structured logging.
- AES & Block Modes: Libraries for Advanced Encryption Standard (AES) encryption.
- RSA: A library for RSA encryption and decryption.
- Rand: A library for generating random values, used in cryptography and token generation.
- Base64: A library for encoding and decoding Base64, often used in file and cryptographic operations.
- Rust: The primary programming language for the backend.
- Actix Web: A powerful, pragmatic, and extremely fast web framework for Rust.
- SQLx: An asynchronous, compile-time verified SQL crate.
- Argon2: Password hashing library for secure user authentication.
- jsonwebtoken: Library for encoding and decoding JWT tokens.
- dotenv: To manage environment variables.
To get a local copy of this project up and running, follow these steps:
- Rust (1.58 or newer) installed. You can install Rust using rustup.
- PostgreSQL installed and running. Ensure you have a database created for this project.
-
Clone the repository:
git clone https://github.com/AarambhDevHub/file-share-rust-backend.git cd file-share-rust-backend
-
Create a .env file in the root of the project with the following variables:
# ----------------------------------------------------------------------------- # Database (PostgreSQL) # ----------------------------------------------------------------------------- DATABASE_URL=postgresql://username:password@localhost:5432/file_share_tutorial # ----------------------------------------------------------------------------- # JSON Web Token Credentials # ----------------------------------------------------------------------------- JWT_SECRET_KEY=my_ultra_secure_jwt_secret_key JWT_MAXAGE=60
-
Install the necessary dependencies:
cargo build
-
Run database migrations:
sqlx migrate run
-
Start the server
cargo run
- POST /api/auth/register: Register a new user.
- POST /api/auth/login: Login a user and return a JWT token.
- GET /api/users/me: Retrieve the authenticated user's information.
- PUT /api/users/name: Update the authenticated user's name.
- PUT /api/users/password: Change the authenticated user's password.
- GET /api/users/search-emails: Search for users by their email addresses.
- POST /api/file/upload: Upload a file (requires authentication).
- GET /api/file/retrieve: Retrieve an uploaded file by ID (requires authentication).
- POST /api/list/send: Send a list of files to another user.
- GET /api/list/receive: Retrieve the list of files received from another user.