This project provides a simple and efficient API for querying currency exchange rates and performing currency conversions. The API is designed to be easy to use, with straightforward endpoints for retrieving exchange rates and converting currency values.
- Retrieve currencies
- Register currencies
- Retrieve currency by name
- Retrieve currency by ID
- Ensure test coverage reaches 80% to guarantee robustness and reliability (Sonar).
The Hexagonal Architecture is a software design model that promotes the isolation of domain logic, located in the inner (business core), from external factors. Communication with domain logic occurs through ports and adapters, ensuring a clear separation between the internal and external parts of the application.
-
Application Layer:
- Interface through which users and other programs interact with the application.
- Includes elements such as user interfaces, RESTful controllers, and JSON serialization libraries.
- Responsible for exposing the entry point in the application and orchestrating the execution of domain logic.
-
Domain Layer:
- Contains the code that implements the business logic, serving as the core of the application.
- Isolated from application and infrastructure parts.
- Includes interfaces that define the API for communication with external parts, such as a database.
-
Infrastructure Layer:
- Contains all the resources necessary for the application to function.
- Includes database configuration, Spring configuration, and implementations of infrastructure-dependent interfaces from the domain layer.
In the infrastructure layer, we implement the principle of Dependency Inversion in the repository layer. This is achieved by creating an interface in the domain and a corresponding implementation in the infrastructure layer. This approach makes our domain service depend on abstractions, not specific implementations, making the code more flexible and adaptable to changes.
To install the dependencies required for this project, use the following command:
pip install -r requirements.txt
-
Navigate to the
docker-compose
directory:cd docker-compose
-
Start the MySQL database using Docker Compose:
docker-compose up -d
-
Navigate back to the project root directory:
python src/Application.py
- To run the tests with coverage
pytest --cov=src
- To generate test coverage report with html
pytest --cov=src --cov-report=html
GET /exchange-rates
This endpoint returns the latest exchange rates between different currencies.
GET /convert?from={source_currency}&to={target_currency}&amount={amount}
This endpoint converts a specified amount from one currency to another based on the provided exchange rates.
To prevent abuse, this API implements rate limiting. Each user is allowed a certain number of requests within a specified time period. If the rate limit is exceeded, subsequent requests will be rejected until the rate limit period resets.
Retrieve exchange rates:
GET /exchange-rates
Response:
{
"USD": 1.0,
"EUR": 0.87,
"GBP": 0.75,
...
}
Convert currency:
GET /convert?from=USD&to=EUR&amount=100
Response:
{
"from": "USD",
"to": "EUR",
"amount": 100,
"converted_amount": 87
}
Contributions to this project are welcome! If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.
This project is licensed under the MIT License. See the LICENSE file for more information.