A production‑ready Spring Boot REST API for managing personal expenses with JWT authentication, PostgreSQL, validation, and Swagger docs.
Built step‑by‑step as a real‑world backend project.
- User Registration
- Login with JWT token
- BCrypt password hashing
- JWT validation filter
- Protected APIs
- User‑specific data isolation
- Add expense
- Get my expenses only
- Update expense
- Delete expense
- Bean validation (@Valid)
- Global exception handling
- Clean error responses
- Swagger documentation
- Environment variable config
- Cloud ready (Render)
| Layer | Tech |
|---|---|
| Backend | Spring Boot 3 |
| Security | Spring Security + JWT |
| Database | PostgreSQL |
| ORM | JPA / Hibernate |
| Build Tool | Maven |
| Docs | Swagger (springdoc-openapi) |
| Deployment | Render |
src/main/java/com/expensetracker
├── controller
├── service
├── repository
├── entity
├── security
├── dto
├── exception
└── ExpenseTrackerBackendApplication.java
git clone <https://github.com/variables-dev-coder/expense-tracker-backend>
cd expense-tracker-backend
Create database:
expense_tracker
application.properties already supports local + cloud:
spring.datasource.url=${DB_URL:jdbc:postgresql://localhost:5432/expense_tracker}
spring.datasource.username=${DB_USERNAME:postgres}
spring.datasource.password=${DB_PASSWORD:root}
mvn spring-boot:run
After running:
http://localhost:8080/swagger-ui/index.html
Test all APIs directly in browser.
POST /api/auth/register
POST /api/auth/login
Response:
{
"token": "JWT_TOKEN"
}
Header:
Authorization: Bearer JWT_TOKEN
| Method | Endpoint | Description |
|---|---|---|
| POST | /api/auth/register | Register user |
| POST | /api/auth/login | Login |
| GET | /api/expenses | Get my expenses |
| POST | /api/expenses | Add expense |
| PUT | /api/expenses/{id} | Update |
| DELETE | /api/expenses/{id} | Delete |
- Create PostgreSQL on Render
- Create Web Service
- Add environment variables:
DB_URL
DB_USERNAME
DB_PASSWORD
- Deploy
Example:
https://expense-tracker-api.onrender.com
Swagger:
https://expense-tracker-api.onrender.com/swagger-ui/index.html
This project demonstrates:
- JWT authentication
- Spring Security filters
- REST API design
- JPA relationships
- Validation
- Exception handling
- Cloud deployment
Aziz Backend Developer (Java + Spring Boot)
Give it a ⭐ on GitHub!