This project implements a notification service for cryptocurrency price alerts using a clean hexagonal architecture. The application monitors crypto price updates and dispatches notifications when configured thresholds are met. Ktor is used as a web server and KMongo for interacting with a MongoDB database.
- Features
- Architecture
- Getting Started
- Building the Project
- Running the Application
- Testing
- Docker
- CI/CD
- Code Quality
- License
- Alert Management: Create, update, and delete price alerts.
- Price Updates: Process real-time cryptocurrency price updates coming from Event Dispatcher.
- Notifications: Dispatch notifications to Event Dispatcher when price thresholds are met.
- JWT Authentication: Secure sensible endpoints using JWT tokens for authentication.
- Clean Architecture: Domain, Application, and Infrastructure layers are clearly separated.
- Unit & Integration Tests: Tests provided with JUnit5 and Konsist for architectural validations.
The project follows a hexagonal architecture:
- Domain Layer: Contains business models such as
it.unibo.domain.PriceAlertandit.unibo.domain.Currency. - Application Layer: Implements business rules and notifications in
it.unibo.application.NotificationServiceImpl. - Infrastructure Adapter: Adapters for external systems like MongoDB (
it.unibo.infrastructure.adapter.MongoPriceAlertRepository), HTTP routing (it.unibo.infrastructure.adapter.WebServer), and JWT authentication (it.unibo.infrastructure.adapter.AuthAdapter).
git clone https://github.com/CryptoMonitorASW-SPE/notification.git
cd notification
Use the Gradle wrapper to build the project. The build configuration is defined in build.gradle.kts.
Run the following command:
./gradlew build
This will compile the code, run tests, and generate the fat JAR in the build output.
The application starts a Ktor server. The main entry point is Main.kt.
Run the application with:
./gradlew run
Or execute the generated JAR:
java -jar build/libs/notification-service.jar
The server listens on port 8080 by default. You can access the following endpoints:
- POST
/data: Submit cryptocurrency price updates. - POST
/createAlert: Create a new alert (JWT authentication required). - GET
/alerts: Get alerts for a user (JWT authentication required). - PUT
/active: Update alert status (JWT authentication required). - DELETE
/alerts: Delete an alert.
The project includes unit and integration tests with JUnit5.
To run tests:
./gradlew test
Test files can be found in:
NotificationServiceTest.ktAuthenticationTest.ktDependencyRuleTest.kt
A Dockerfile is provided to build a Docker image of the application.
To build and run the Docker container:
docker build -t notification .\
docker run -p 8080:8080 notification
When a push is made to the main branch, an automatic release process is triggered. If a new release is detected, a new Docker package is built and published to GitHub Container Registry.
The CI/CD pipeline ensures that every release includes an updated Docker image. When a new release is created:
-
A Docker image is built.
-
The image is pushed to GHCR.
-
The latest tag is updated.
For each pull request, the following checks are performed:
-
Code Quality and Smell Analysis: The code is analyzed using Detekt to ensure it adheres to Kotlin best practices and to check for code smells.
-
Test Validation: The test suite is executed to verify that all tests pass before merging.
The project uses KtLint for Kotlin code style enforcement.
It is integrated into the commit process using Husky, meaning you cannot commit code that violates style rules.
Commitlint is configured to enforce commit message conventions.
It ensures that all commits follow a standardized format, improving readability and maintainability.