This project is a Spring Boot backend for a Splitwise-style expense sharing web application. It provides RESTful APIs that let users register, log in, create groups, add members, record shared expenses, split expenses between users, track balances, and settle debts.
The backend uses JWT-based authentication for protected endpoints and BCrypt password hashing for storing user passwords securely. Data is persisted in a MySQL database through Spring Data JPA and Hibernate.
Core capabilities include:
- User registration and login
- JWT-protected API access
- Group creation and group membership management
- Expense creation with custom split amounts
- Personal and group balance tracking
- Settle-up transaction recording
- Dashboard summaries for personal and group balances
backend/
pom.xml
src/
main/
java/
com/splitwise/
SplitwiseApplication.java
controller/
AuthController.java
DashboardController.java
ExpenseController.java
GroupController.java
UserController.java
dto/
AddGroupMembersRequest.java
AuthResponse.java
CreateExpenseRequest.java
CreateGroupRequest.java
DashboardResponseDTO.java
ExpenseDTO.java
GroupBalanceDTO.java
LoginRequest.java
PersonalBalanceDTO.java
RegisterRequest.java
UserBalanceDTO.java
UserBalanceResponse.java
entity/
Expense.java
Group.java
GroupMember.java
Split.java
Transaction.java
User.java
UserBalance.java
repository/
ExpenseRepository.java
GroupMemberRepository.java
GroupRepository.java
SplitRepository.java
TransactionRepository.java
UserBalanceRepository.java
UserRepository.java
security/
JwtFilter.java
JwtUtil.java
SecurityConfig.java
service/
DashboardService.java
ExpenseService.java
GroupService.java
TransactionService.java
UserBalanceService.java
UserService.java
resources/
application.properties
test/
java/
com/splitwise/
SplitwiseApplicationTests.java
service/
UserServiceTest.java
Important packages:
controller: REST API endpoints.dto: Request and response objects used by the APIs.entity: JPA entities mapped to relational database tables.repository: Spring Data JPA repositories for database access.security: JWT authentication and Spring Security configuration.service: Business logic for users, groups, expenses, balances, dashboard data, and transactions.
The backend follows a standard layered Spring Boot architecture:
Client
-> REST Controller
-> Service Layer
-> Repository Layer
-> MySQL Database
Authentication flow:
- A user registers through
POST /auth/register. - The password is hashed with BCrypt before being stored.
- The user logs in through
POST /auth/login. - Spring Security validates the username and password.
- A JWT is generated and returned to the client.
- Protected requests include the token in the
Authorization: Bearer <token>header. JwtFiltervalidates the token and sets the authenticated user in the security context.
Expense flow:
- A client sends an expense request to
POST /expenses. ExpenseControllerpasses the request toExpenseService.ExpenseServiceloads the payer and validates group membership when the expense belongs to a group.- An
Expenserecord is created with relatedSplitrecords. UserBalanceServiceupdates the amount owed from each split user to the payer.- Data is persisted using JPA repositories.
Balance flow:
GET /users/{userId}/balancereturns a user's net balances with other users.GET /dashboard?userId={userId}returns personal totals and group-level balance summaries.UserBalanceRepositoryprovides aggregate queries for amounts owed by and owed to a user.
Settle-up flow:
- A client calls
POST /users/{payerId}/settle-up/{receiverId}with an amount. TransactionServicecreates aTransactionrecord.UserBalanceServicereduces or removes the corresponding outstanding balance.
Main database tables:
usersuser_groupsgroup_membersexpensessplitsuser_balancestransactions
Prerequisites:
- Java 17
- Maven
- MySQL
Create a MySQL database and user matching backend/src/main/resources/application.properties:
spring.datasource.url=jdbc:mysql://localhost:3306/splitwise_db
spring.datasource.username=splitwise_user
spring.datasource.password=mypasswordFrom the project root, run:
cd backend
mvn spring-boot:runThe application starts as a Spring Boot service, typically on:
http://localhost:8080
Run tests with:
cd backend
mvn testCurrent test classes are present, but they are disabled with @Disabled.