Skip to content

terletskij/microservice-financial-tracker

Repository files navigation

Note

This project is under development. Some new features coming soon

📊 Financial Tracker

Microservice-based application for managing personal finances.

🛠 Tech Stack

  • Language & Framework: Java 17, Spring Boot, Spring Security, Spring Data JPA
  • Database: PostgreSQL
  • Testing: JUnit, Mockito
  • DevTools: Maven, Docker
  • API documentation: OpenAPI (Swagger)

📑 Table of Contents

🚀 Features

  • User registration & login (JWT-based authentication)
  • Track income and expenses
  • Modular microservices architecture
  • Unit & integration testing
  • API documentation via Swagger / OpenAPI

How to install & run

1. Clone the repository

git clone https://github.com/terletskij/microservice-financial-tracker.git
cd microservice-financial-tracker

2.Create and configure .env file:

In the root directory of the project, create a file named .env and add the following environment variables:

# === Database URLs ===
TRANSACTION_DATASOURCE_URL=jdbc:postgresql://transaction-db:5432/transaction_db
AUTH_DATASOURCE_URL=jdbc:postgresql://auth-db:5432/auth_db

# === Common Database Credentials ===
DB_USERNAME=your_db_username
DB_PASSWORD=your_db_password

# === Ports Configuration ===
POSTGRES_PORT=5432
TRANSACTION_SERVICE_PORT=8082
AUTH_SERVICE_PORT=8081

# === Database Names ===
TRANSACTION_DB_NAME=transaction_db
AUTH_DB_NAME=auth_db

# === JWT Configuration ===
JWT_SECRET=your_jwt_secret_key
JWT_EXPIRATION=3600000              # in milliseconds (e.g., 1 hour)
JWT_REFRESH_EXPIRATION=86400000     # in milliseconds (e.g., 24 hours)

Note

Replace the values (e.g., your_db_username, your_jwt_secret_key, etc.) with your own configuration. These values are used by Docker containers and Spring Boot services during startup.

3. Start the application (Docker)

Start the application by using the following command

docker-compose up --build

How to Use the API

After you have successfully launched the project (see steps above), you can test the API using tools like Postman, curl, or directly via Swagger UI.

Example: Register a New User POST auth/register
📍 URL via gateway:

http://localhost:<GATEWAY_PORT>/auth/register

Gateway port by default is 8080
Request Body:

{
  "username": "testuser",
  "email": "testuser@example.com",
  "password": "securePassword123"
}

Response Body:

{
  "token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
  "refreshToken": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}

Example: Add a Transaction POST /transactions

📍 URL via gateway:

http://localhost:<GATEWAY_PORT>/transactions

Gateway port by default is 8080 Headers:

Authorization: Bearer <your_token>

Request Body:

{
  "type": "INCOME",
  "amount": 1500.00,
  "description": "Salary"
}

🚀 ROADMAP

Note

New features soon

  • GitHub Repository:

    • Provide clear and beginner-friendly documentation (installation, usage, environment setup)
    • Add architecture diagram and service overview
    • Simplify project startup with improved docker-compose automation
  • Development Goals:

    • Refactor .env variables, remove redundant
    • Implement centralized logging (e.g., ELK stack or simple logger config)
    • Add rate limiting and request validation in API Gateway
    • Implement role-based access control (RBAC)
    • Add email verification and password reset flow in Auth Service
  • Discovery Service

    • Initialize service with Spring Cloud Netflix Eureka
    • Configure application.yml
    • Update docker-compose.yml to include the discovery-service with port mapping.
    • Configure application.yml in each service to point to http://discovery-service:8761/eureka/ as the defaultZone.
    • Verify that all services register with Eureka and that API calls work through the gateway.
  • API Gateway

    • Initialize Spring Cloud Gateway
    • Configure basic routes to auth-service and transaction-service
    • Implement JWT validation in API Gateway
    • Extract userId from token and forward to services via headers
    • Add CORS configuration for frontend
  • Auth Service

    • Entity & Database: create User entity and setup PostgreSQL table users with (id, username, email, password, role)
    • Security: Configure security, implement JWT token generation and validation
    • Service: Implement AuthService with registration and login
    • Controller: Implement AuthController with registration and login endpoints
  • Transaction Service

    • Entity & Database: create Transaction entity and configure PostgreSQL connection
    • Service & Repository: implement TransactionService and TransactionRepository for CRUD operations
    • Controller: implement TransactionController
    • Validation & Error Handling: Implement data validation and global error handling
    • Documentation: Integrate Swagger/OpenAPI for API documentation
    • Testing: Write unit and integration tests

About

Microservice-based Financial Tracker with Spring Boot, Security

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published