vm-pricing-api

Cloud VM Price Finder Documentation

Overview

Cloud VM Price Finder is designed to aggregate, store, and display virtual machine pricing data from multiple cloud providers. It features a high-performance FastAPI backend, a PostgreSQL database, and a modern, responsive React frontend built with Vite and Shadcn UI.

The application automatically keeps its pricing data up-to-date with a background scheduler and provides a powerful, filterable interface for users to find and compare virtual machine instances.


Features


Technical Stack


API Endpoints

All endpoints are available under the /api/v1 prefix.

Method Endpoint Description
GET /filters/options Provides unique, distinct values for all filter dropdowns on the frontend.
GET /instances Fetches a paginated list of VM instances with powerful filtering & sorting.
GET /providers Lists all providers that currently have data in the database.
GET /regions Lists all regions, optionally filtered by provider.
GET /metrics Returns basic metrics like total record count and last update times.
GET /health A simple health check endpoint.

Data Schema

VMInstance

All VM data is normalized to the following schema:


Adding a New Provider

  1. Create a new provider class in app/providers/ inheriting from BaseProvider.
  2. Implement the fetch_data() method to return a list of VMInstance objects.
  3. Register the provider in the scheduler and (optionally) in the API endpoints.

Local Development Setup

1. Backend Setup

1. Clone the Repository:

git clone https://github.com/frhanjav/vm-pricing-api.git
cd vm-pricing-api

2. Create and Activate a Python Virtual Environment:

python3 -m venv venv
source venv/bin/activate

3. Install Python Dependencies:

pip install -r requirements.txt

4. Configure Environment Variables:

# .env
DATABASE_URL="postgresql+asyncpg://user:password@localhost/cloud_pricing"
CORS_ORIGINS="http://localhost:5173"
AWS_ACCESS_KEY_ID="your_key"
AWS_SECRET_ACCESS_KEY="your_secret"

5. Testing Data Fetching

A standalone script test_fetch.py is provided to test fetching and saving AWS pricing data to CSV:

python -m app.test_fetch

6. Run the Database Migration:

python -m app.migrate_csv_to_postgres

2. Frontend Setup

1. Navigate to the Frontend Directory:

cd frontend

2. Install Node.js Dependencies:

npm install

3. Configure Environment Variables:

# frontend/.env.development
VITE_API_BASE_URL=http://127.0.0.1:8000/api/v1

3. Running the Application

Run the backend and frontend servers simultaneously in two separate terminals from the project root.

Terminal 1 (Backend):

uvicorn app.main:app --reload

Terminal 2 (Frontend):

cd frontend
npm run dev

You can now access the frontend at http://localhost:5173.