This Finance Manager project is a web application for managing personal finances. It allows users to register, log in, create budgets, and track transactions. The backend is built using Rust with Rocket and Diesel, and it includes user authentication and JWT-based authorization.
- User Registration
- User Login
- JWT-based Authentication
- Create, Read, Update, Delete (CRUD) operations for Budgets and Transactions
- Secure password hashing
- Validation of user inputs
- Rocket: Web framework for Rust.
- Diesel: ORM for interacting with the database.
- Bcrypt: Library for hashing passwords.
- JSON Web Token (JWT): Library for creating and verifying JWTs.
- Serde: Framework for serializing and deserializing Rust data structures.
- Validator: Library for validating data structures.
-
Clone the repository
git clone https://github.com/weldonkipchirchir/finance_manager.git cd finance_manager -
Install Rust and Cargo
Follow the instructions at rustup.rs to install Rust and Cargo.
-
Install Diesel CLI
cargo install diesel_cli --no-default-features --features postgres
-
Setup PostgreSQL Database
Create a PostgreSQL database and set the connection URL in the
.envfile. -
Run Database Migrations
diesel setup diesel migration run
-
Start the Application
cargo run --bin server
-
Access the API
The API will be available at
http://localhost:8000.
-
POST /user/register
Register a new user.
Request:
{ "username": "johndoe", "email": "johndoe@example.com", "password": "password123" }Response:
{ "user": { "id": 1, "username": "johndoe", "email": "johndoe@example.com" }, "token": "jwt_token" } -
POST /user/login
Log in an existing user.
Request:
{ "email": "johndoe@example.com", "password": "password123" }Response:
{ "user": { "id": 1, "username": "johndoe", "email": "johndoe@example.com" }, "token": "jwt_token" }
-
GET /budgets
Get all budgets for the authenticated user.
-
POST /budgets
Create a new budget.
Request:
{ "category": "Groceries", "amount": 200.00, "start_date": "2023-01-01", "end_date": "2023-01-31" }Response:
{ "id": 1, "user_id": 1, "category": "Groceries", "amount": 200.00, "start_date": "2023-01-01", "end_date": "2023-01-31" } -
PUT /budgets/:id
Update an existing budget.
-
DELETE /budgets/:id
Delete a budget.
-
GET /transactions
Get all transactions for the authenticated user.
-
POST /transactions
Create a new transaction.
Request:
{ "amount": 50.00, "category": "Groceries", "description": "Weekly grocery shopping", "date": "2023-01-05" }Response:
{ "id": 1, "user_id": 1, "amount": 50.00, "category": "Groceries", "description": "Weekly grocery shopping", "date": "2023-01-05" } -
PUT /transactions/:id
Update an existing transaction.
-
DELETE /transactions/:id
Delete a transaction.
Create a .env file in the project root and add the following environment variables:
DATABASE_URL=postgres://username:password@localhost/finance_manager
JWT_SECRET=your_jwt_secret
Replace username, password, and your_jwt_secret with your actual PostgreSQL username, password, and desired JWT secret.
This project is licensed under the MIT License. See the LICENSE file for details.
Contributions are welcome! Please open an issue or submit a pull request for any improvements or bug fixes.