Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
189 changes: 50 additions & 139 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,139 +1,50 @@
# Allo Bank Backend Developer Take-Home Test

Thank you for applying to our team! This take-home test is designed to evaluate your practical skills in building **production-ready** Spring Boot applications within a finance domain, focusing on architectural patterns and complex data handling.

## 📝 Objective

Your task is to create a single Spring Boot REST API endpoint capable of aggregating data from multiple, distinct resources provided by the public, keyless **Frankfurter Exchange Rate API**. The primary focus is on handling Indonesian Rupiah (IDR) data.

The focus of this test is not just functional correctness, but demonstrating clean code, advanced Spring concepts, thread-safe design, and architectural clarity.

## I. Core Task: The Polymorphic API

### 1. External API Integration (Frankfurter API)

* **Base URL (Public):** `https://api.frankfurter.app/`.

* You must integrate with three distinct data resources to enforce the architectural pattern:

1. `/latest?base=IDR` (The latest rates relative to IDR)

2. **Historical Data:** Query a specific, small time series (e.g., `/2024-01-01..2024-01-05?from=IDR&to=USD`). **Note:** *Use the date range provided in this example unless a different range is communicated separately.*

3. `/currencies` (The list of all supported currency symbols)

### 2. Internal API Endpoint

You must expose **one single endpoint** in your application: ```GET /api/finance/data/{resourceType}```

Where `{resourceType}` can be one of the three strings: `latest_idr_rates`, `historical_idr_usd`, or `supported_currencies`.

### 3. Required Functionality & Business Logic

* **Resource Handling:** Your service must correctly map the three incoming `resourceType` values to the correct data fetching strategies.

* **Data Load:** All three resources should be fetched from the external API.

* **Data Transformation (Latest IDR Rates only) - Unique Calculation:** For the **`latest_idr_rates`** resource, you must calculate and include a new field, `"USD_BuySpread_IDR"`. This is the Rupiah selling rate to USD after applying a banking spread/margin.

**The Spread Factor Must Be Unique :**

1. **Input:** Your GitHub username (e.g., `johndoe47`).
2. **Calculation:** Calculate the sum of the Unicode (ASCII) values of all characters in your lowercase GitHub username string.
3. **Spread Factor Derivation:** `Spread Factor = (Sum of Unicode Values % 1000) / 100000.0`
*(This will yield a unique factor between 0.00000 and 0.00999, ensuring a personalized result.)*

**Final Formula:** `USD_BuySpread_IDR = (1 / Rate_USD) * (1 + Spread Factor)` (where `Rate_USD` is the value from the API when `base=IDR`).

* **Other Resources:** The `historical_idr_usd` and `supported_currencies` resources can return their data with minimal transformation, but the final output must be a unified JSON array of results.

## II. Architectural Constraints

Meeting the core task is only one part of the solution. The following constraints must be strictly adhered to and will be heavily weighted during evaluation:

### Constraint A: The Strategy Pattern

The logic for handling the three different resources (`latest_idr_rates`, `historical_idr_usd`, `supported_currencies`) must be implemented using the **Strategy Design Pattern**.

1. Define a clear **Strategy Interface** (e.g., `IDRDataFetcher`).

2. Implement **three concrete strategy classes** (one for each resource).

3. The main `Controller` should dynamically select the correct strategy implementation using a map-based lookup injected by Spring, avoiding any manual `if/else` or `switch` logic in the controller layer.

### Constraint B: Client Factory Bean

The instance of your chosen external API client (`WebClient` or `RestTemplate`) **must be defined and created within a custom implementation of Spring's `FactoryBean<T>` interface**.

* This `FactoryBean` should be responsible for externalizing the API Base URL via `@Value` or `@ConfigurationProperties` and applying any initial configuration (e.g., timeouts, shared headers).

* ***You may not define the client as a simple `@Bean` in a `@Configuration` class.***

### Constraint C: Startup Data Runner & Immutability

The aggregated data for **ALL three resources** must be fetched **exactly once on application startup** and loaded into an in-memory store.

1. Use a Spring Boot **`ApplicationRunner`** or **`CommandLineRunner`** component to initiate the data fetching process.

2. The API endpoint (`GET /api/finance/data/{resourceType}`) must serve the data from this **in-memory store**, not by making a new call to the external API on every request.

3. The in-memory storage mechanism (e.g., a service holding the data) must be designed to be **thread-safe** and ensure the data is **immutable** once the `ApplicationRunner` has finished loading it.

## III. Production Readiness & Deliverables

Your final solution must demonstrate production quality through code, testing, and communication.

### 1. Robustness & Best Practices

* Graceful **Error Handling** for network failures or 4xx/5xx responses from the external API.

* Proper use of **Configuration Properties** (e.g., `application.yml`) for external service URLs.

* Clear separation of concerns (Controller, Service, Model/DTO, etc.).

### 2. Testing

* **Unit Tests** for all three `IDRDataFetcher` strategy implementations, ensuring data calculation and transformation logic is covered (using mock clients for external calls).

* **Integration Tests** to verify the `ApplicationRunner` successfully initializes and loads the data into the in-memory store before the application context is ready.

### 3. Documentation

A clear `README.md` is mandatory. It must include:

* **Setup/Run Instructions:** Clear steps to clone, build, and run the application and tests.

* **Endpoint Usage:** Example cURL commands to test the three different resource types.

* **Personalization Note:** Clearly state your GitHub username and show the exact **Spread Factor** (e.g., `0.00765`) calculated by your function.

* ---

* ### 🛠️ Architectural Rationale

This section should contain a brief, but detailed, explanation answering the following questions:

1. **Polymorphism Justification:** Explain *why* the Strategy Pattern was used over a simpler conditional block in the service layer for handling the multi-resource endpoint. Discuss the benefits in terms of **extensibility** and **maintainability**.

2. **Client Factory:** Explain the specific role and benefit of using a **`FactoryBean`** to construct the external API client. Why is this preferable to defining the client using a standard `@Bean` method in this scenario?

3. **Startup Runner Choice:** Justify the choice of using an `ApplicationRunner` (or `CommandLineRunner`) for the initial data ingestion over a simpler `@PostConstruct` method.

## IV. Submission & Review Process

1. **Fork** this repository.

2. Implement your solution on a dedicated feature branch (e.g., `feat/idr-rate-aggregator`).

3. When complete, submit your solution via a **Pull Request (PR)** back to the main repository.
4. Please complete the form to submit your technical test: [Click Here](https://forms.gle/nZKQ2EjTCPfAKHog7)

**Your PR will be evaluated on the following:**

* **Commit History:** Clean, atomic, and descriptive commit messages (e.g., "feat: Implement IDR latest rates strategy," "fix: Correctly calculate IDR spread in tests").

* **PR Description:** The description must clearly summarize the solution and **must contain the full answers** to the three "Architectural Rationale" questions from Section III.

* **Code Review Readiness:** The code should be well-structured and ready for immediate review.

Good luck!
# prerequisite
Java version 21.0.5
Gradle version 8.14.3

# step by step
* Clone
git clone <url>

* Open terminal (Use Powershell)

* Open application directory
cd </path/to/source/location>
example: cd Z:\bs

* Refresh Gradle Dependencies
gradle --refresh-dependencies

* Build using gradle command
gradle build

* Run application
cd <path/to/jar/location>
example: cd Z:\bs\build\libs

java -jar <jar_names>
example: java -jar bs-0.0.1-SNAPSHOT.jar

* Test API 'supported_currencies'
curl.exe "http://127.0.0.1:8080/api/finance/data/supported_currencies"

* Test API 'historical_idr_usd'
curl.exe "http://127.0.0.1:8080/api/finance/data/historical_idr_usd?dateFrom=2026-03-25&dateTo=2026-04-01"

* Test API 'latest_idr_rates'
curl.exe "http://127.0.0.1:8080/api/finance/data/latest_idr_rates"

# Personalization Note
* Spread Factor : 0.0037

# Architectural Rationale
i.
With the Strategy Pattern, the code will be easier to read, debug, and modify.
in extensibility, When adding a new resource type doesn’t require changing existing logic.
in maintainability, Each strategy is independent, making it easier to read, test, and modify.

ii.
If using a FactoryBean, it will define when it is created.

iii.
CommandLineRunner is preferable because it executes after the entire Spring Boot application context completed.
36 changes: 36 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
plugins {
id 'java'
id 'org.springframework.boot' version '3.2.5'
id 'io.spring.dependency-management' version '1.1.7'
}

group = 'com.self'
version = '0.0.1-SNAPSHOT'

java {
toolchain {
languageVersion = JavaLanguageVersion.of(21)
}
}

repositories {
mavenCentral()
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'
implementation 'org.springframework.boot:spring-boot-starter-webflux'
implementation 'org.springframework.boot:spring-boot-starter-cache'
testImplementation 'org.springframework.boot:spring-boot-starter-test'
testImplementation 'org.mockito:mockito-core:3.12.4'
}

dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:2023.0.1"
}
}

tasks.named('test') {
useJUnitPlatform()
}
7 changes: 7 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
pluginManagement {
repositories {
maven { url = 'https://repo.spring.io/snapshot' }
gradlePluginPortal()
}
}
rootProject.name = 'bs'
15 changes: 15 additions & 0 deletions src/main/java/com/self/bs/BsApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.self.bs;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;

import com.self.bs.source.config.ExchangeRateProperties;

@SpringBootApplication
@EnableConfigurationProperties(ExchangeRateProperties.class)
public class BsApplication {
public static void main(String[] args) {
SpringApplication.run(BsApplication.class, args);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.self.bs.source.component;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.stereotype.Component;

import com.self.bs.source.config.ExchangeRateProperties;

@Component
public class CacheManagerFactoryBean implements FactoryBean<ConcurrentMapCacheManager>{

@Autowired
protected ExchangeRateProperties exchangeRateProperties;

@Override
public ConcurrentMapCacheManager getObject() {
return new ConcurrentMapCacheManager(exchangeRateProperties.getCacheName());
}

@Override
public Class<?> getObjectType() {
return ConcurrentMapCacheManager.class;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.self.bs.source.component;

import org.springframework.beans.factory.FactoryBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.reactive.function.client.WebClient;

import com.self.bs.source.config.ExchangeRateProperties;

@Component
public class ExternalApiClientFactory implements FactoryBean<WebClient>{
@Autowired
protected ExchangeRateProperties exchangeRateProperties;

@Override
public WebClient getObject() {
return WebClient.builder()
.baseUrl(exchangeRateProperties.getExternalUrl())
.build();
}

@Override
public Class<?> getObjectType() {
return WebClient.class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.self.bs.source.config;

import org.springframework.boot.context.properties.ConfigurationProperties;

@ConfigurationProperties(prefix = "bs.exchange-rate")
public class ExchangeRateProperties {
private String cacheName;
private String externalUrl;
private String baseCurrency;
private String targetCurrency;
private int defaultHistoricalRangeDate = 7;
private String dateFormat = "yyyy-MM-dd";
private String rangeDateSeparator = "..";
private String personalName;

public String getCacheName() {
return cacheName;
}
public void setCacheName(String cacheName) {
this.cacheName = cacheName;
}
public String getExternalUrl() {
return externalUrl;
}
public void setExternalUrl(String externalUrl) {
this.externalUrl = externalUrl;
}
public String getBaseCurrency() {
return baseCurrency;
}
public void setBaseCurrency(String baseCurrency) {
this.baseCurrency = baseCurrency;
}
public String getTargetCurrency() {
return targetCurrency;
}
public void setTargetCurrency(String targetCurrency) {
this.targetCurrency = targetCurrency;
}
public int getDefaultHistoricalRangeDate() {
return defaultHistoricalRangeDate;
}
public void setDefaultHistoricalRangeDate(int defaultHistoricalRangeDate) {
this.defaultHistoricalRangeDate = defaultHistoricalRangeDate;
}
public String getDateFormat() {
return dateFormat;
}
public void setDateFormat(String dateFormat) {
this.dateFormat = dateFormat;
}
public String getRangeDateSeparator() {
return rangeDateSeparator;
}
public void setRangeDateSeparator(String rangeDateSeparator) {
this.rangeDateSeparator = rangeDateSeparator;
}
public String getPersonalName() {
return personalName;
}
public void setPersonalName(String personalName) {
this.personalName = personalName;
}
}
Loading