Local Development
Set up a local development environment for Rates API and start contributing to the project.
This project is a small monorepo with separate API and docs apps. The root scripts are the normal entry point for local work.
Prerequisites
- Bun: The JavaScript runtime and package manager used by the project
- Git: For version control
- A text editor or IDE such as VS Code or WebStorm
- A Cloudflare account if you need remote D1 access or deployment
Getting Started
1. Clone the Repository
git clone https://github.com/simonbetton/ratesapi.nz.git
cd ratesapi.nz
2. Install Dependencies
bun i
3. Run the API Worker
bun run dev
This starts Wrangler for the API Worker at http://localhost:8787 and uses the configured development environment.
4. Run the Docs App
bun run dev:docs
The docs app runs with Next.js. The docs content comes from MDX files under apps/docs/content/docs.
Local D1 Modes
The default API development command is configured for remote development data. Use the explicit local path when you need an offline Miniflare D1 database:
bun run dev:api:local
That command initializes and seeds the local D1 database before starting Wrangler.
Scraping Data
The project includes scripts to scrape rate data from financial institution websites. These scripts are located in the apps/api/bin/ directory.
bun run apps/api/bin/scrape-mortgage-rates.ts
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
To run all scrapers against local D1:
bun run scrape:all:local
Checks
Run the full local verification suite before opening a pull request:
bun run check
For docs-only type checking:
bun run typecheck:docs
Common Workflows
| Task | Files to start with |
|---|---|
| Add an endpoint | apps/api/src/routes/, apps/api/src/models/, test/api-contract.test.ts |
| Update docs content | apps/docs/content/docs/ |
| Update scraper behavior | apps/api/bin/ and apps/api/src/lib/schema.ts |
| Change deployment | apps/api/wrangler.toml, apps/docs/wrangler.toml, .github/workflows/ |