A modern currency conversion API service with rate limiting, Redis caching, and MongoDB for user data storage. Built with TypeScript, Express, and Bun.
- TypeScript-based Express server with Bun runtime
- Docker and docker-compose setup for local development
- MongoDB integration for data persistence and request logging
- Redis caching for optimized performance and rate limiting
- Comprehensive error handling and logging system
- Hot reloading for development
- Rate limiting with configurable windows and limits
- Request logging and metrics tracking
- Health check endpoints with dependency status
- CI/CD pipeline with GitHub Actions
- TypeScript strict mode and best practices
- Bun (>= 1.2.0)
- Docker Desktop and Docker Compose
The easiest way to get started is using Docker Compose, which will set up the entire stack including MongoDB and Redis:
# Build and start all containers
bun run docker:up
# Seed the database with initial data
bun run seed
# View application logs
docker-compose logs -f app
# Stop all containers
bun run docker:down
The application will be available at http://localhost:8000
.
If you prefer to run the application directly on your machine (requires local MongoDB and Redis):
- Clone the repository and install dependencies:
# Install dependencies
bun install
- Copy the environment variables example file:
cp .env.example .env
- Start the service in development mode:
# Start with hot reloading
bun run dev
GET /health
- Basic health checkGET /health/detailed
- Detailed health check with dependency status
GET /api/v1/currency/convert
- Convert between currencies- Query parameters:
from
,to
,amount
- Query parameters:
GET /api/v1/currency/rates
- Get latest exchange rates- Query parameters:
base
(optional)
- Query parameters:
GET /api/v1/currency/supported
- List supported currenciesGET /api/v1/metrics
- Get application metrics and statistics
A Postman collection is available to help you test the API endpoints. You can find it in the documentation/
directory:
-
Import the collection:
- Open Postman
- Click "Import"
- Select
documentation/Trunk Tools POC.postman_collection.json
-
Set up environment variables:
- Create a new environment in Postman
- Add the following variables:
domain
: Set tolocalhost:8000
for local developmentUserId
: One of the user ids that you see after running the seed commandUserId2
: A different user id that you see after running the seed command
-
Available requests in the collection:
- Health Check (Basic and Detailed)
- Get Supported Currencies
- Get Exchange Rates
- Convert Currency
- Get Health Metrics
- Get Cache Metrics
The following environment variables are required:
NODE_ENV
: Application environment (local, production)PORT
: Port number for the HTTP server (default: 8000)
MONGODB_URI
: MongoDB connection string- Default:
mongodb://localhost:27017/currency-service
- Docker:
mongodb://mongodb:27017/currency-service
- Default:
REDIS_URI
: Redis connection string- Default:
redis://localhost:6379
- Docker:
redis://redis:6379
- Default:
RATE_LIMIT_WINDOW_MS
: Time window for rate limiting (default: 60000)RATE_LIMIT_MAX_REQUESTS
: Maximum requests per window (default: 100)RATE_LIMIT_WEEKDAY
: Maximum requests per day on weekdays (default: 100)RATE_LIMIT_WEEKEND
: Maximum requests per day on weekends (default: 200)
DECIMAL_PRECISION_BTC
: Number of decimal places for BTC (default: 8)DECIMAL_PRECISION_USD
: Number of decimal places for USD (default: 2)
MAX_AMOUNT_BTC
: Maximum BTC amount for conversions (default: 1000)
COINBASE_API_URL
: Base URL for Coinbase API (default: https://api.coinbase.com/v2)
currency-conversion-service/
├── src/
│ ├── controllers/ # Route controllers
│ ├── routes/ # Express route definitions
│ ├── middleware/ # Express middleware
│ ├── errors/ # Error handling
│ ├── utils/ # Utility functions
│ ├── types/ # TypeScript type definitions
│ ├── config/ # Configuration files
│ ├── repositories/ # Data access layer
│ └── index.ts # Application entry point
├── documentation/ # Project documentation
├── Dockerfile # Docker configuration
├── docker-compose.yml # Docker Compose configuration
├── .env.example # Example environment variables
├── tsconfig.json # TypeScript configuration
└── package.json # Project dependencies and scripts
bun run dev
- Start the server with hot reloadingbun run build
- Run TypeScript type checkingbun run start
- Start the server in production modebun run lint
- Run ESLintbun run lint:fix
- Fix ESLint issuesbun run format
- Format code with Prettierbun run format:check
- Check code formattingbun run docker:build
- Build Docker containersbun run docker:up
- Start Docker containersbun run docker:down
- Stop Docker containersbun run seed
- Seed initial databun run restart
- Restart the entire stack
Detailed documentation is available in the documentation/
directory:
- Follow TypeScript best practices and strict mode
- Use ES Module syntax for imports/exports
- Implement proper error handling with custom error types
- Write comprehensive tests for new features
- Follow the existing code style and formatting rules
- Document new features and API changes
The project uses Bun's built-in test runner. Run tests with:
bun test
- Create a feature branch
- Make your changes
- Run tests and linting
- Submit a pull request
This project is private and confidential.