Skip to content

Case Study - Crypto Exchange Api (Java 25, Spring Boot, Mongodb, JUnit, Docker, Prometheus , Grafana, Kubernetes, Github Action (CI/CD), TestContainer, Jenkins, FeignClient, AOP, Mapstruct, Resilience4j, Circuit Breaker)

Notifications You must be signed in to change notification settings

Rapter1990/cryptoexchangeapi

Repository files navigation

Case Study - Crypto Exchange Api

Main Information

📖 Information

Project Definition (CryptoExchange API)

A Spring Boot service that converts an amount from one cryptocurrency to another using CoinMarketCap (CMC), persists each conversion as a history record, and exposes pageable search & discovery endpoints. All responses are wrapped in CustomResponse<T>; paged payloads use CustomPagingResponse<T>.

End-to-end flow (convert API):

  • Client sends POST /api/convert with ConvertRequest: { from, to, amount } (e.g., BTCARB, amount=100).
  • Service fetches the conversion rate from CMC, computes convertedAmount, and persists a record:
    • transactionId (UUID)
    • createdAt (ISO-8601)
    • from, to, amount, convertedAmount
  • Returns 201 Created with CustomResponse<CryptoConvert> containing the saved record.

History search:

POST /api/convert/history accepts FilterServicePagingRequest and returns CustomPagingResponse<CryptoConvertResponse>. Filtering supports:

  • from, to (symbols)
  • amount range: minAmount .. maxAmount
  • convertedAmount range: minConvertedAmount .. maxConvertedAmount
  • createdAt range: createdAtFrom .. createdAtTo
  • transactionIdContains (substring)

Pagination & sorting are provided in the request (e.g., pageNumber, pageSize, sortBy, sortDirection).

Crypto map (name + symbol):

  • GET /api/convert/map returns a paged list of cryptocurrencies (name & symbol) via CMC /v1/cryptocurrency/map.
  • Query params:
    • page (1-based, default 1, min 1)
    • size (default 20, range 1..5000)
  • Response: CustomPagingResponse<CryptoNameSymbolResponse> with standard paging metadata.

Error semantics:

  • 201 Created — Successful conversion persisted (/api/convert)
  • 200 OK — Successful paged responses (/history, /map)
  • 400 Bad Request — Validation errors (invalid symbols, amounts, or paging inputs)
  • 502 Bad Gateway — Upstream CMC call failed or unavailable (convert/map)

Caching & invalidation:

CMC results are cached to reduce latency and request volume. Cache eviction runs on a fixed schedule configured via cmc.cache-ttl and a lifecycle hook (@PostConstruct) to ensure fresh state on startup.

OpenAPI (Swagger):

The controller is annotated with detailed @Operation and @ApiResponse metadata. Explore at: http://localhost:1927/swagger-ui/index.html (port configurable).

Explore Rest APIs

Endpoints Summary

Method URL Description Request Body Headers/Path Response Status Codes
POST /api/convert Convert an amount from one crypto to another and persist the result ConvertRequest CustomResponse<CryptoConvert> 201, 400, 502
POST /api/convert/history Paged search of conversion history with filters, pagination and sorting FilterServicePagingRequest CustomResponse<CustomPagingResponse<CryptoConvertResponse>> 200, 400
GET /api/convert/map List cryptocurrencies (name + symbol) with pagination Query: page (default 1), size (default 20, max 5000) CustomResponse<CustomPagingResponse<CryptoNameSymbolResponse>> 200, 502

Technologies


  • Java 25
  • Spring Boot 3.0
  • Restful API
  • Open Api (Swagger)
  • Maven
  • Junit5
  • Mockito
  • Integration Tests
  • Mapstruct
  • Resilience4j
  • Resilience4j Rate Limiter
  • Resilience4j Retry
  • Resilience4j Circuit Breaker
  • Spring Cache
  • Docker
  • Docker Compose
  • CI/CD (Github Actions)
  • Postman
  • Prometheus
  • Grafana
  • Kubernetes
  • JaCoCo (Test Report)
  • AOP
  • Jenkins

Postman

Import postman collection under postman_collection folder

Prerequisites

Define Variable in .env file

MONGO_DB_HOST=localhost
MONGO_DB_PORT=27017
MONGO_DB_NAME=cryptoexchangedatabase
COIN_MARKET_CAP_API_KEY={YOUR_COIN_MARKET_CAP_API_KEY}

Open Api (Swagger)

http://localhost:1927/swagger-ui/index.html

JaCoCo (Test Report)

After the command named mvn clean install completes, the JaCoCo report will be available at:

target/site/jacoco/index.html

Navigate to the target/site/jacoco/ directory.

Open the index.html file in your browser to view the detailed coverage report.


Maven, Docker and Kubernetes Running Process

Maven Run

To build and run the application with Maven, please follow the directions shown below;

$ cd git clone https://github.com/Rapter1990/cryptoexchangeapi.git
$ cd cryptoexchangeapi
$ mvn clean install
$ mvn spring-boot:run

Docker Run

The application can be built and run by the Docker engine. The Dockerfile has multistage build, so you do not need to build and run separately.

Please follow directions shown below in order to build and run the application with Docker Compose file;

$ cd cryptoexchangeapi
$ docker-compose up -d

If you change anything in the project and run it on Docker, you can also use this command shown below

$ cd cryptoexchangeapi
$ docker-compose up --build

To monitor the application, you can use the following tools:

  • Prometheus:
    Open in your browser at http://localhost:9090
    Prometheus collects and stores application metrics.

  • Grafana:
    Open in your browser at http://localhost:3000
    Grafana provides a dashboard for visualizing the metrics.
    Default credentials:

    • Username: admin
    • Password: admin

Define prometheus data source url, use this link shown below

http://prometheus:9090

Kubernetes Run

To run the application, please follow the directions shown below;

  • Start Minikube
$ minikube start
  • Open Minikube Dashboard
$ minikube dashboard
  • Revise CMC_API_KEY in cryptoexchangeapi-secrets.yml according to your usage

  • To deploy the application on Kubernetes, apply the Kubernetes configuration file underneath k8s folder

$ kubectl apply -f k8s
  • To open Prometheus, click tunnel url link provided by the command shown below to reach out Prometheus
minikube service prometheus-service
  • To open Grafana, click tunnel url link provided by the command shown below to reach out Prometheus
minikube service grafana-service
  • Define prometheus data source url, use this link shown below
http://prometheus-service.default.svc.cluster.local:9090

Docker Image Location

https://hub.docker.com/repository/docker/noyandocker/cryptoexchangeapi/general
https://hub.docker.com/repository/docker/noyandocker/cryptoexchangeapi-jenkins/general

Jenkins

  • Go to jenkins folder
  • Run docker-compose up -d
  • Open Jenkins in the browser via localhost:8080
  • Define credentials for Github General token used by GIT_REPO_ID and docker-hub-credentials for Docker Username and Password
  • Go to pipeline named cryptoexchangeapi
  • Run Pipeline
  • Show Pipeline Step to verify if it succeeded or failed

📸 Screenshots

Click here to show the screenshots of project

Figure 1

Figure 2

Figure 3

Figure 4

Figure 5

Figure 6

Figure 7

Figure 8

Figure 9

Figure 10

Figure 11

Figure 12

Figure 13

Figure 14

Figure 15

Figure 16

Figure 17

Contributors

About

Case Study - Crypto Exchange Api (Java 25, Spring Boot, Mongodb, JUnit, Docker, Prometheus , Grafana, Kubernetes, Github Action (CI/CD), TestContainer, Jenkins, FeignClient, AOP, Mapstruct, Resilience4j, Circuit Breaker)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages