This repository demonstrates a test-driven development (TDD) approach for building a Python-based microservice that performs real-time currency conversion. The service exposes a REST API using Flask, accepts query parameters for source_currency, target_currency, and amount, and returns the converted amount as JSON. It fetches exchange rates from an external API (exchangerate.host) and includes robust error handling and fallback behavior.
- REST API endpoint for currency conversion (
/convert) - Real-time exchange rate fetching with fallback to static rates
- Modular code structure (API, validation, external integration)
- Comprehensive test suite using
pytestandrequests-mock - Clean code practices and robust error handling
-
Install dependencies:
pip install -r src/requirements.txt
-
Run the Flask app:
python src/app.pyThe app will start on http://127.0.0.1:5000 by default.
-
Run the test suite:
python -m pytest srcNote: The tests require
pytestandrequests-mock(both included inrequirements.txt).
Request:
GET /convert?source_currency=USD&target_currency=EUR&amount=100
Response:
{
"source_currency": "USD",
"target_currency": "EUR",
"amount": 100,
"converted_amount": 92.34,
"rate": 0.9234
}src/app.py- Flask application and API endpointsrc/exchange.py- External API integration and fallback logicsrc/validation.py- Request validation logicsrc/test_app.py- Test suite for the microservicesrc/requirements.txt- Python dependenciesnotes/- TDD plans, best practices, and documentation
This project was developed using TDD principles, with phases for planning, test writing, minimal implementation, and refactoring. The codebase emphasizes modularity, maintainability, and robust error handling.
See notes/tdd-best-practices-notes.md and notes/currency-microservice-tdd-plan.md for detailed TDD process, prompting examples, and best practices.
This project was developed in close collaboration with GitHub Copilot, leveraging AI-assisted coding to:
- Rapidly prototype and iterate on requirements, tests, and implementation
- Apply test-driven development (TDD) at every stage
- Refactor and modularize code for maintainability and clarity
- Accelerate feedback cycles by automating test writing and validation
By integrating Copilot into the workflow, I was able to:
- Break down features and tasks into actionable TDD phases
- Use Copilot to generate, review, and refine both tests and production code
- Quickly adapt to changes and resolve issues with AI-powered suggestions
This approach embodies hyper velocity engineering practices—emphasizing automation, rapid iteration, and continuous improvement—resulting in a robust, well-tested, and maintainable microservice.