Skip to content

Commit

Permalink
Merge pull request #20 from rozachatz/transfer-notifications
Browse files Browse the repository at this point in the history
Added notification microservice, kafka brokers and modified the yml for CI
  • Loading branch information
rozachatz authored Oct 9, 2024
2 parents 7246b59 + d03a88a commit 123107c
Show file tree
Hide file tree
Showing 78 changed files with 876 additions and 510 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/ci-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This workflow will build a Java project with Maven, build the Docker images of
# the microservices # and push them to GitHubContainer Registry.

name: Java CI/CD

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set up JDK 17
uses: actions/setup-java@v4
with:
java-version: '17'
distribution: 'temurin'
cache: maven

- name: Build with Maven
run: mvn -B package --file pom.xml

- name: Build the MoneyTransfer microservice Docker image
run: docker build ./moneytransfer --file ./moneytransfer/Dockerfile --tag ghcr.io/${{ github.repository_owner }}/money-transfer-app:latest

- name: Build the Notifications microservice Docker image
run: docker build ./notifications --file ./notifications/Dockerfile --tag ghcr.io/${{ github.repository_owner }}/notifications-app:latest

- name: List Docker images
run: docker images

- name: Log in to GitHub Container Registry
run: echo "${{ secrets.PAT }}" | docker login ghcr.io -u ${{ github.actor }} --password-stdin

- name: Push MoneyTransfer microservice Docker image to GitHub Container Registry
run: docker push ghcr.io/${{ github.repository_owner }}/money-transfer-app:latest

- name: Push Notifications microservice Docker image to GitHub Container Registry
run: docker push ghcr.io/${{ github.repository_owner }}/notifications-app:latest

45 changes: 0 additions & 45 deletions .github/workflows/cicd-config.yml

This file was deleted.

24 changes: 13 additions & 11 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,18 @@
# Default ignored files
/shelf/
/workspace.xml
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr

### Eclipse ###
.apt_generated
.classpath
.factorypath
Expand All @@ -16,12 +21,6 @@ target/
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
Expand All @@ -34,3 +33,6 @@ build/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store
3 changes: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

109 changes: 49 additions & 60 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,57 +4,47 @@

- [Introduction](#introduction)
- [API Documentation](#API-Documentation)
- [Architecture](#architecture)
- [Testing](#testing)
- [Docker](#docker)
- [MoneyTransfer Microservice](#moneytransfer-microservice)
- [Notifications Microservice](#notifications-microservice)
- [App Events](#app-events)
- [Docker Guidelines](#docker-guidelines)

## Introduction

CashFlowz is a money transfer microservice application written in Java for seamless and secure financial transfers 💸 .

CashFlowz is a Java-based microservices application for money transfers. It features an idempotent API and uses event-driven architecture for asynchronous communication between services.
## API Documentation

Power-up the application (preferably with [Docker](#docker)) and
visit "http://localhost:8080/api/swagger-ui/index.html" to explore endpoints and read the API documentation! 😊

## Architecture
The app architecture follows a domain-driven design pattern.

### Presentation Layer

All endpoints and their documentation are defined in MoneyTransferAPIController.

### Application Layer
Includes all the services and DTOs.
Power-up the application (preferably with [Docker](#docker-guidelines)) and
visit "http://localhost:8080/api/swagger-ui/index.html" to explore endpoints of the app and read the API documentation! 😊

- #### GetTransferService
## MoneyTransfer Microservice
### Architecture
The moneytransfer REST microservice architecture follows a domain-driven design pattern.

Gets all transfers within the system.

- #### GetAccountService
#### Presentation Layer
Includes the endpoints and their Swagger documentation (MoneyTransferAPIController).
___
#### Application Layer
**Services**:

Gets all accounts within the system.
- GetTransferService: retrieves transfers.

- #### MoneyTransferService
- GetAccountService: retrieves bank accounts.

Performs the money transfer operation.
- MoneyTransferService: performs the money transfer operation.

- #### CurrencyExchangeService
- CurrencyExchangeService: Gets the exchange rates from third party API (provided by https://freecurrencyapi.com/) using CurrencyExchangeDao. Performs currency exchange for a given rate and amount.

Performs currency exchange by retrieving the latest exchange rates from "https://freecurrencyapi.com/"! 💱
- TransferRequestService: gets, creates and completes transfer requests.

- #### TransferRequestService
**Aspects**:

Gets, submits and resolves all transfer requests.
- IdempotentTransferAspect: An @Around aspect providing the functionality for idempotent transfer requests. It publishes a Kafka consumer topic for sending transfer notifications.
___
#### Domain Layer

- #### CurrencyExchangeService
Gets the exchange rates from third party API using CurrencyExchangeDao and performs the currency exchange for a given amount.

### Domain Layer

#### Account

The Account entity represents a bank account with the following properties:
The **Account** entity represents a bank account with the following properties:

| Field | Description |
|------------|----------------------------------|
Expand All @@ -64,9 +54,7 @@ The Account entity represents a bank account with the following properties:
| currency | Currency of the Account |
| created_at | Creation date. |

#### Transfer

The Transfer entity represents a financial transfer between two accounts:
The **Transfer** entity represents a financial transfer between two accounts:

| Field | Description |
|-------------------|---------------------------------------|
Expand All @@ -76,9 +64,7 @@ The Transfer entity represents a financial transfer between two accounts:
| amount | The transfer amount |
| currency | Transfer currency |

#### TransferRequest

The TransferRequest entity represents a transfer request:
The **TransferRequest** entity represents a transfer request:

| Field | Description |
|-------------------------|--------------------------------------------------------|
Expand All @@ -90,35 +76,38 @@ The TransferRequest entity represents a transfer request:
| transfer | the associated Transfer of a completed TransferRequest |
| http_status | http status of a completed TransferRequest |
| info_message | includes the exception message or a success message |
___
#### Persistence Layer
Includes all (**JPA**) repositories and Data Access Objects (DAOs).

### Persistence Layer
Includes all (JPA) repositories and Data Access Objects (DAOs).
_______________________________________

## Aspect Oriented Programming

### IdempotentTransferAspect

An @Around aspect providing the functionality for idempotent transfer requests.
______________________________

## Logging & Exception Handling

---
### Exception Handling & Logging
Using @ControllerAdvice for exception handling and logging.

## Testing
Unit and integration tests with Junit-5 and @TestContainers.

### Acceptance Criteria
### Testing
Unit and integration tests with **Junit-5** and **@TestContainers**.
#### Acceptance Criteria

- AC 1: Happy path
- AC 2: Insufficient balance
- AC 3: Transfer in the same account
- AC 4: Source/target account does not exist
___
## Notifications Microservice
The microservice features a Kafka consumer subscribed to the notification topic. This consumer listens for **TransferCompletedEvent** events and sends a transfer notification (log) message.

The **TransferNotificationsService** includes the logic for sending a transfer notification.


## Docker
### Testing
Unit and integration tests with **Junit-5**.
____
## App Events
The money transfer and notifications microservices communicate asynchronously with events (**TransferCompletedEvent**) using **Kafka** with **Redpanda**.
___
## Docker Guidelines

Build the project and let the magic ✨ happen by executing:
Build the project using Maven and let the magic ✨ happen by executing:

````bash
docker compose up --build
Expand Down
20 changes: 20 additions & 0 deletions common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.example</groupId>
<artifactId>CashFlowz</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>

<artifactId>common</artifactId>

<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

</project>
4 changes: 4 additions & 0 deletions common/src/main/java/com/cashflowz/common/events/Event.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package com.cashflowz.common.events;

public interface Event {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.cashflowz.common.events;

import java.io.Serializable;

public record TransferCompletedEvent(String message) implements Event, Serializable {
}
Loading

0 comments on commit 123107c

Please sign in to comment.