Local Development
Set up a local development environment for Rates API and start contributing to the project.
Local Development Setup
This guide will help you set up a local development environment for Rates API, allowing you to make changes, test new features, and contribute to the project.
Prerequisites
Before you begin, make sure you have the following installed:
- Bun: The JavaScript runtime and package manager used by the project
- Git: For version control
- A text editor or IDE: Such as VS Code, WebStorm, etc.
Getting Started
1. Clone the Repository
2. Install Dependencies
Using Bun to install dependencies:
3. Run the Development Server
Start the local development server:
This will start the server at http://localhost:8787
. You can access the API and Swagger UI documentation at this URL.
Scraping Data
The project includes scripts to scrape rate data from financial institution websites. These scripts are located in the bin/
directory.
To run a scraper script:
Available scraper scripts:
scrape-mortgage-rates.ts
: Fetches current mortgage ratesscrape-personal-loan-rates.ts
: Fetches personal loan ratesscrape-car-loan-rates.ts
: Fetches car loan ratesscrape-credit-card-rates.ts
: Fetches credit card rates
The scraped data is stored in the CloudFlare D1 database, allowing for comprehensive historical data management.
CloudFlare D1 Database
The project uses CloudFlare D1, a serverless SQL database built on SQLite, for data storage. This allows for efficient storage and querying of both current and historical rate data.
Local Development with D1
For local development, you’ll need to set up a local D1 database:
Database Schema
The database schema includes tables for:
- Current rates (mortgage, personal loan, car loan, credit card)
- Historical time series data
- Institution information
- Metadata and audit logs
Development Tips
Project Structure
-
src/
: Contains the main application codeindex.ts
: The entry point for the applicationmodels/
: Data schemas and typesroutes/
: API endpoint handlerslib/
: Utility functions and helpers
-
bin/
: Scripts for scraping data -
schema.sql
: Database schema definition file
Testing Your Changes
Before submitting changes, make sure to:
- Test all affected endpoints locally
- Run any necessary data scraper scripts
- Ensure the project builds without errors
Common Tasks
- Add a new endpoint: Create a new route handler in
src/routes/
- Update data models: Modify schemas in
src/models/
- Enhance scrapers: Modify the scraper scripts in
bin/