Advanced Expense Splitting & Settlement Engine
Features β’ Tech Stack β’ API Docs β’ Getting Started β’ Deployment
GroupPay is a high-performance backend system engineered to simplify complex group finances. Think of it as the engine behind a "Pro" version of Splitwise. It handles user authentication, complex expense splitting (Equal, Exact, Percentage), and features a smart settlement algorithm to minimize the number of transactions needed to settle up.
Current Status: β Core Backend Complete (Deployed)
| Phase | Feature | Status |
|---|---|---|
| Phase 1 | JWT Auth, Groups, Settlements | β Completed |
| Phase 1 | Dockerization & Cloud Deployment | β Completed |
| Phase 2 | Password Reset Flow | β Completed |
| Phase 3 | WebSocket Notifications | π§ In Progress |
| Future | Social Login (Google/FB) | π Planned |
| Future | Native Android App Integration | π Planned |
|
|
|
|
| Component | Technology | Description |
|---|---|---|
| Language | Java 21 | Latest LTS version for performance. |
| Framework | Spring Boot 3.4 | Core framework for DI & Web MVC. |
| Database | MySQL 8 / TiDB | Relational persistence. Cluster-ready. |
| Security | Spring Security 6 | JWT + BCrypt + CSRF protection. |
| Docs | SpringDoc OpenAPI | Automated Swagger UI generation. |
| Ops | Docker | Multi-stage build for optimized image size. |
GroupPay isn't just a CRUD app; it solves the NP-hard problem of debt simplification efficiently using a Greedy Minimum Cash Flow Algorithm.
Imagine 3 friends: Ram, Sham, and Krishna.
- Ram pays βΉ50 for Sham.
- Sham pays βΉ50 for Krishna.
Naive Approach (2 Transactions):
- Sham gives Ram βΉ50.
- Krishna gives Sham βΉ50.
- Sham is just a middleman moving money!
Our algorithm calculates the Net Balance for each person:
- Ram: +βΉ50 (He is owed)
- Sham: 0 (Owes 50, Owed 50 -> Net 0)
- Krishna: -βΉ50 (He owes)
Optimized Result:
- Krishna pays Ram βΉ50 directly.
- Sham does nothing.
Drastically reduces bank transfers in large groups.
- Input: N people with M transactions.
- Output: At most N-1 transactions to settle EVERYONE.
Explore the API interactively. No external tools needed.
| Environment | URL | Status |
|---|---|---|
| Live Demo | **Launch Swagger UI ** | π’ Online |
| Localhost | View Local Docs | π‘ When running |
| Method | Endpoint | Description | Auth? |
|---|---|---|---|
POST |
/auth/register |
Register a new user | β |
POST |
/auth/login |
Login & receive JWT | β |
POST |
/auth/forgot-password |
Request password reset token | β |
GET |
/groups |
List all groups for user | β |
POST |
/groups |
Create a new group | β |
POST |
/expenses |
Add a split expense | β |
GET |
/settlements/group/{id} |
Calculate settlement graph | β |
Register a User:
curl -X POST "https://your-app-url.onrender.com/auth/register" \
-H "Content-Type: application/json" \
-d '{
"username": "mahir_dev",
"email": "mahir@example.com",
"password": "securePassword123"
}'Ensure you have the following installed before running locally:
- Java 21 (JDK)
- MySQL 8.0 (or compatible)
- Maven 3.9+
- Docker & Docker Compose (Optional, for containerization)
Option 1: Run with Docker (Recommended)
# 1. Build the image
docker build -t grouppay-backend .
# 2. Run container (With env vars)
docker run -p 8081:8081 \
-e SPRING_DATASOURCE_URL="jdbc:mysql://host:port/db" \
-e SPRING_DATASOURCE_USERNAME="root" \
-e SPRING_DATASOURCE_PASSWORD="password" \
grouppay-backendOption 2: Run from Source
- Clone & Configure:
Update
src/main/resources/application.ymlwith your DB creds. - Run:
./mvnw spring-boot:run
- Access:
Server starts at
http://localhost:8081
The project is built as a Modular Monolith, ensuring strict boundaries exist between features (User, Group, Expense) while keeping the deployment simple.
graph TD
Client[Mobile/Web Client] -->|REST API| LoadBalancer
LoadBalancer -->|HTTPS| SpringBoot[Spring Boot Backend]
SpringBoot -->|Read/Write| DB[(TiDB / MySQL)]
subgraph "Modular Monolith"
Auth[User Module]
Grp[Group Module]
Exp[Expense Module]
Set[Settlement Engine]
end
SpringBoot --> Auth
SpringBoot --> Grp
SpringBoot --> Exp
Exp --> Set
The project follows a Domain-Driven Design (DDD) architecture. Each feature (User, Group, Expense) is a self-contained module with its own API, Service, and Repository layers.
com.grouppay
βββ user
β βββ api # AuthController (Login, Register, ForgotPwd)
β βββ application # PasswordResetService, LoginUserService
β βββ domain # User Entity, PasswordResetToken
βββ group
β βββ api # GroupController
β βββ application # GroupService, MemberService
βββ expense
β βββ api # ExpenseController
β βββ domain # Expense, ExpenseSplit (Polymorphic inputs)
βββ settlement
β βββ application
β β βββ MinimumCashFlowService.java # The Greedy Algorithm
β β βββ BalanceCalculationService.java
β βββ domain # Settlement Entity
βββ notification
β βββ event # ExpenseAddedEvent, MemberAddedEvent
βββ security # JwtAuthenticationFilter, SecurityConfigEngineered and Developed by Mahir Aggarwal