A Spring Boot REST API for managing shared expenses between roommates. Track apartments, expenses, and payments all in one place.
This is a backend service that helps roommates split bills and track who's paid what. You can create apartments, add expenses (like rent, utilities, groceries), and record payments. The API uses JWT authentication so each user only sees their own data.
- Spring Boot 4.0.1 - Main framework
- PostgreSQL - Database
- Spring Security - Authentication and authorization
- JWT - Token-based auth
- Maven - Dependency management
- Java 17 or higher
- Maven
- PostgreSQL (or use Docker Compose)
- Clone the repo:
git clone <your-repo-url>
cd p3project- Start PostgreSQL with Docker Compose:
docker-compose up -dOr set up PostgreSQL manually and update application.properties with your database credentials.
-
The database schema will be created automatically from
src/main/resources/schema.sqlwhen you first run the app. -
Run the application:
./mvnw spring-boot:runThe API will be available at http://localhost:8080
POST /api/users/register- Create a new accountPOST /api/users/login- Login and get a JWT token
GET /api/apartments- Get all apartments for the current userGET /api/apartments/{id}- Get apartment by IDPOST /api/apartments- Create a new apartment (requires auth)PUT /api/apartments/{id}- Update apartment (requires auth)DELETE /api/apartments/{id}- Delete apartment (requires auth)POST /api/apartments/{apartmentId}/members/{userId}- Add a member to an apartment
GET /api/expenses/apartment/{apartmentId}- Get all expenses for an apartmentPOST /api/expenses- Create a new expense (requires auth)
GET /api/payments/expense/{expenseId}- Get all payments for an expensePOST /api/payments- Record a payment (requires auth)
GET /api/admin/users- Get all users (admin only)DELETE /api/admin/users/{id}- Delete a user (admin only)
Most endpoints require a JWT token. After logging in, you'll get a token that you need to include in the Authorization header:
Authorization: Bearer <your-token-here>
Tokens expire after 24 hours by default (configurable in application.properties).
Edit src/main/resources/application.properties to change:
- Database connection details
- JWT secret and expiration time
- Connection pool settings
The app uses these main tables:
users- User accountsapartments- Apartment listingsapartment_members- Links users to apartments (many-to-many)expenses- Bills/expenses tied to apartmentspayments- Individual payments toward expenses
There's a test file at src/main/resources/api.http with example requests you can use with REST Client extensions in VS Code or IntelliJ.
- Passwords are hashed using Spring Security's BCrypt
- Users can only access apartments they're members of
- Expenses are tied to apartments, not individual users
- The first user you create will have the USER role by default