Repository for the Expense Manager backend API
This project is the backend for the Expense Manager, responsible for user authentication and full CRUD operations for expense management. It is built with Spring Boot 3.2.9 and JDK 21, using PostgreSQL as the main database.
The application is designed following RESTful principles and implements security and token-based authentication via JWT.
- User authentication and authorization using JWT.
- Full expense CRUD (Create, Read, Update, Delete).
- Role-based access control (e.g., default user role customer).
- Email notification support via SendGrid.
- Deployment-ready for Google Cloud Run and file storage with Google Cloud Storage.
- Monitoring and health checks using Actuator.
- In-memory H2 Database for development and testing environments.
-
spring-boot-starter-actuator:
Provides monitoring and management features for the Spring Boot application, including HTTP endpoints for health checks, metrics, and application info. -
spring-boot-starter-data-jpa:
Simplifies the use of Java Persistence API (JPA) in Spring Boot, providing configurations, JPA entities, and repository support for easy CRUD operations. -
h2-database:
An in-memory relational database used for development and testing, with a web console for database management. -
spring-boot-starter-security:
Provides authentication and authorization support, including protection against CSRF and XSS attacks. -
java-jwt:
A library for creating and validating JWT tokens, used for authentication and authorization in web apps and RESTful APIs. -
spring-boot-starter-oauth2-resource-server : Resource protection.
Adds support for implementing OAuth 2.0 resource servers in Spring Boot apps, protecting APIs via OAuth 2.0. -
lombok:
Reduces boilerplate code using annotations for generating getters, setters, constructors, and more during compile time. -
SendgridApi:
A platform for transactional and marketing email services with an easy-to-integrate API. Offers features like email tracking, analytics, and automation. -
Google Cloud run / Google Cloud Build :
A fully managed platform to build, deploy, and run containers with automatic scaling — without the need to manage servers or infrastructure. Cloud Build enables serverless CI/CD pipelines, making it easy to automate deployments to Cloud Run and other Google Cloud services. -
Google Cloud Storage :
A secure, scalable cloud storage solution by Google.
Code exemples
The project follows RESTful architecture, with a clear separation of services and controllers.
Test endpoints require proper credentials and roles.
⚙️ Account Creation & Authentication Flow:
- To create an account, send a POST request to /user with an email and password.
- Passwords are securely encrypted before being stored.
- Upon account creation, a JWT token is generated for authentication and authorization.
- By default, new users are assigned the "customer" role.
- Token validation and role-based access control are handled automatically in the background.
Before running the project, ensure that Java is installed on your machine. If not, you can download it from the official Oracle website (version 17 or later is recommended).
To verify your Java installation, run:
java -versionClone the repository to your local machine:
git clone https://github.com/kaikyMoura/backEnd-ExpenseManager.gitNavigate to the project's root directory:
cd backEnd-ExpenseManagerUse Maven to clean and package the application:
mvn clean packageOnce the build is complete, you can start the application with:
java -jar target/expenseManager-0.0.1-SNAPSHOT.jarOr you can run directly in your IDE.
http://localhost:8080
The deployment of the project is done on Google Cloud Run, leveraging Cloud Build for continuous integration. This setup ensures that any changes pushed to the repository on GitHub are automatically built and deployed to Cloud Run.
- Key Steps:
- Cloud Build: Automatically builds the Docker image from the GitHub repository and pushes it to Google Container Registry.
- Cloud Run Deployment: After the image is built, Cloud Run deploys the application using the newly created image.
- Service Account: A service account with appropriate permissions (such as access to Google Cloud Storage) is used to ensure the application can interact with required resources securely.
This setup enables automated and seamless deployment, reducing manual intervention and ensuring continuous delivery of updates to the production environment.
The API follows RESTful patterns, and endpoints include:
| Method | Endpoint | Description | Auth Required |
|---|---|---|---|
| POST | /user |
Register new user | No |
| POST | /auth/login |
Authenticate and get token | No |
| CRUD | /expense |
Manage user expenses | Yes |
- Non-commercial project.
- All rights related to user data and privacy are respected.
- External services (e.g., SendGrid, Google Cloud) follow their own Terms of Use.
- This project aims to serve as a learning and portfolio tool.