https://github.com/tushar-swarnkar/expense-tracker
Expense Tracker is a secure and role-based backend application built using Spring Boot and JWT that allows users to log, manage, and retrieve their personal expenses month-wise and year-wise. Admins can manage user roles and ensure data integrity, making it a robust system for financial tracking and control.
https://github.com/tushar-swarnkar/expense-tracker
hibernate java jjwt-api jjwt-impl jjwt-jackson jwt-authentication jwt-authorization lombok maven maven-pom mysql mysql-workbench spring-data-jpa spring-mvc spring-security springboot
Last synced: 2 months ago
JSON representation
Expense Tracker is a secure and role-based backend application built using Spring Boot and JWT that allows users to log, manage, and retrieve their personal expenses month-wise and year-wise. Admins can manage user roles and ensure data integrity, making it a robust system for financial tracking and control.
- Host: GitHub
- URL: https://github.com/tushar-swarnkar/expense-tracker
- Owner: tushar-swarnkar
- Created: 2025-06-22T14:59:17.000Z (12 months ago)
- Default Branch: master
- Last Pushed: 2025-06-22T15:19:25.000Z (12 months ago)
- Last Synced: 2025-06-22T16:28:34.451Z (12 months ago)
- Topics: hibernate, java, jjwt-api, jjwt-impl, jjwt-jackson, jwt-authentication, jwt-authorization, lombok, maven, maven-pom, mysql, mysql-workbench, spring-data-jpa, spring-mvc, spring-security, springboot
- Language: Java
- Homepage:
- Size: 20.5 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Expense Tracker (Backend)
## ๐ Project Overview
This repository contains the backend implementation of the **Expense Tracker** application built using **Java** and **Spring Boot**. It provides secure APIs for user authentication, expense logging, and data retrieval, with role-based access control using **JWT** and **Spring Security**.
## ๐ Features
โ๏ธ User Registration & Login
โ๏ธ JWT-based Authentication
โ๏ธ Role-Based Access Control (User/Admin)
โ๏ธ Secure Endpoints using Spring Security
โ๏ธ Users can log their monthly expenses
โ๏ธ Fetch all expenses for the logged-in user
โ๏ธ Filter expenses by month or year
โ๏ธ Admin can update user roles (e.g., promote to admin)
โ๏ธ Clean error handling and logging
## ๐ ๏ธ Tech Stack
- **Java 17**
- **Spring Boot 3.x**
- **Spring Security 6**
- **JWT (Java JWT - jjwt)**
- **Maven**
- **MySQL**
- **Postman** (for testing)
### ๐ฆ Spring Boot Dependencies
- **spring-boot-starter-web** โ REST APIs
- **spring-boot-starter-security** โ Authentication & Authorization
- **spring-boot-starter-data-jpa** โ Database interaction
- **jjwt-api, jjwt-impl, jjwt-jackson** โ JWT token generation and validation
- **spring-boot-devtools** โ Development-time utilities
- **lombok** โ Reduces boilerplate code
## ๐ Authentication & Security
### ๐ JWT Package Overview
- **JwtUtil.java** โ Utility for creating and validating JWTs
- **JwtFilter.java** โ Filters requests and sets authentication context from JWT
- **CustomUserDetailsService.java** โ Loads user credentials from the database for Spring Security
- **SecurityConfig.java** โ Spring Security configuration with JWT filter and role-based access
## ๐ API ENDPOINT GUIDE
### ๐ฅ Public Endpoints
- **`POST /user/signup`** โ Register a new user
- **`POST /user/login`** โ Authenticate user and receive JWT token
### ๐ Secured Endpoints (require JWT token)
#### ๐งพ Expenses
- **`POST /expense/add`** โ Add a new expense
- **`GET /expense/all`** โ Get all expenses for the logged-in user
- **`GET /expense/month/{month}`** โ Get expenses by month
- **`GET /expense/year/{year}`** โ Get expenses by year
#### โ๏ธ Admin-only
- **`PUT /admin/set-role/{userId}`** โ Promote user to admin
## Spring configurations for the project:
### add the following configurations in the "/src/main/resources/application.properties" file:
```properties
# Application Info
spring.application.name=expense-tracker
# Server Configuration
server.port=9999
# Database Configuration
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver # tells Spring Boot to use the MySQL Connector/J (JDBC driver)
spring.datasource.url=jdbc:mysql://localhost:3306/expense_tracker # configuration key to set the JDBC URL
spring.datasource.username=YOUR_DB_USERNAME
spring.datasource.password=YOUR_DB_PASSWORD
# JPA & Hibernate Settings
spring.jpa.show-sql=true # shows the SQL query
spring.jpa.hibernate.ddl-auto=update # automatically updates your database schema
spring.jpa.properties.hibernate.format_sql=true # formatting the SQL query in readable form
```
## ๐ Package Structure
```yaml
๐ฆ com.stew.expense_tracker
โโโ ๐ config # Spring Security Configuration
โโโ ๐ constants # Enum for user roles
โโโ ๐ controller # REST controllers
โโโ ๐ model # Entity classes (User, Expense)
โโโ ๐ repository # JPA Repositories
โโโ ๐ service # Service classes with business logic
โโโ ๐ jwt # JWT utilities and filter
โโโ ๐ wrapper # DTOs for requests/responses
โโโ ๐ Application.java # Main Spring Boot class