This project consists of two Spring Boot microservices:
- Transaction Service: Manages cards, accounts, and transactions for a card management system.
- Fraud Detection Service: Flags potentially fraudulent transactions based on configurable limits and frequency.
- Docker & Docker Compose (see your version with
docker --versionanddocker compose version) - (Optional) Java 21 (JDK) and Maven (only needed if you want to build/test outside Docker)
docker compose up --build- This will:
- Start a PostgreSQL 14.18 container with two databases:
card_transactionandcard_fraud_detection - Build the JARs for both services inside the containers using Maven (multi-stage Docker build)
- Run the transaction and fraudDetection services as separate containers with the correct JDK (Temurin 21)
- Start a PostgreSQL 14.18 container with two databases:
You do NOT need to run Maven manually to build the JARs. Docker will do it for you.
- Transaction Service: http://localhost:8080/swagger-ui.html
- Fraud Detection Service: http://localhost:8081/swagger-ui.html
- To stop all containers:
docker compose down - To remove all data (including databases and all data inside):
docker compose down -v
- All configuration is handled via environment variables in
docker-compose.ymland picked up by the services via${ENV_VAR:default}syntax inapplication.properties. - You do NOT need to manually create databases or users. The
init.sqlscript and Docker Compose handle this.
SPRING_DATASOURCE_URL,SPRING_DATASOURCE_USERNAME,SPRING_DATASOURCE_PASSWORD: Set by Docker Compose for each service.FRAUD_DETECTION_URL: Used by the transaction service to call the fraudDetection service.SERVER_PORT: Used by fraudDetection to set its port (default 8081).
- Can be set in
fraudDetection/src/main/resources/application.propertiesbefore first run, or updated in theparameterstable in the fraudDetection database:fraud.limit(max transaction amount)fraud.time-interval(ISO-8601 duration, e.g., PT30M for 30 minutes)fraud.transaction-frequency-limit(max transactions per interval)
- Transaction logs:
transaction/logs/transaction.log - FraudDetection logs:
fraudDetection/logs/fraudDetection.log
- To run unit tests (outside Docker):
./mvnw test - For integration tests, ensure the database is up and the required data (card/account) is present.
-
Database "card_fraud_detection" does not exist:
Make sure you have not removed theinit.sqlmount in the postgres service indocker-compose.yml. If you change the DB setup, rundocker compose down -vto reset the data volume (Warning: This will delete all the previous data in databases). -
Port conflicts:
Ensure 8080 (transaction) and 8081 (fraudDetection) are available. -
Environment variables:
All sensitive and environment-specific configs are injected via Docker Compose.