Dockerised FastAPI web app that sizes a VM for a selection of Federated Computer apps (Base/Good/Better/Best tiers or custom) and prices it across 14 cloud providers and ~250 regions, grouped by continent. - Sizing model per app with shared databases, headroom and disk growth - Live pricing from Vultr, Akamai/Linode and Azure (DigitalOcean and Hetzner with tokens); dated catalog for the rest - Hand-maintained Contabo price sheet with editor and table paste, including the one-time setup fee - HIPAA/SOC2/PCI DSS/GDPR status, SMTP port 25, IPv4 and egress notes - Estimated latency to 40 cities, real RTT via Globalping probes - Versioned REST API (/api/v1) with OpenAPI docs and CSV export - Accounts with admin/user roles, first admin from ADMIN_USERNAME / ADMIN_PASSWORD, per-account API keys, SQLite storage Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
326 lines
18 KiB
Markdown
326 lines
18 KiB
Markdown
# Coremarket
|
||
|
||
Size a VM for a chosen set of [Federated Computer](https://federated.computer/product/software-library/)
|
||
apps, then price that VM across 14 cloud providers and ~250 regions. Results are grouped by
|
||
North America, Europe, Asia, Australia, Africa and South America. Each option shows HIPAA / SOC 2 /
|
||
PCI DSS / GDPR status and estimated latency to 40 cities.
|
||
|
||
## Run
|
||
|
||
```bash
|
||
cp .env.example .env # then set ADMIN_USERNAME and ADMIN_PASSWORD (at least 10 characters)
|
||
docker compose up -d --build
|
||
open http://localhost:8080 # sign in as the admin
|
||
```
|
||
|
||
On first run, Coremarket creates the admin account from `ADMIN_USERNAME` / `ADMIN_PASSWORD`. If no
|
||
account exists and those aren't set, it refuses to start and says so in `docker compose logs`. After
|
||
that the two variables are ignored, so changing them later does not change any password. You can
|
||
remove `ADMIN_PASSWORD` from `.env` once you've signed in.
|
||
|
||
| Env var | Default | Purpose |
|
||
|---|---|---|
|
||
| `LIVE_PRICING` | `1` | Pull live prices from provider APIs at startup, then every `LIVE_REFRESH_HOURS` |
|
||
| `LIVE_REFRESH_HOURS` | `24` | Refresh interval |
|
||
| `EUR_USD` | `1.16` | FX rate for EUR-priced providers (Hetzner, Scaleway) |
|
||
| `DIGITALOCEAN_TOKEN` | – | Read-only token enables live DigitalOcean pricing |
|
||
| `HCLOUD_TOKEN` | – | Read-only token enables live Hetzner pricing |
|
||
| `GLOBALPING_TOKEN` | – | Higher rate limit for real latency measurements |
|
||
| `ADMIN_USERNAME` / `ADMIN_PASSWORD` | – | First run only: creates the admin account (see [Accounts](#accounts-and-sign-in)) |
|
||
| `SESSION_HOURS` | `12` | How long a browser sign-in lasts |
|
||
| `COOKIE_SECURE` | `0` | Set to `1` when Coremarket is served over HTTPS, so the session cookie is only sent encrypted |
|
||
| `CORS_ORIGINS` | – | Comma-separated browser origins allowed to call the API from other sites |
|
||
|
||
Live pricing works with no keys for **Vultr, Akamai/Linode and Azure**. **Contabo** has no pricing
|
||
API: its prices are kept in an editable sheet. Use **Edit Contabo prices** in the header (or "Edit
|
||
prices" in the Notes tab) to change plans, prices, currency/FX, setup fee and per-region surcharges, or
|
||
paste a price table copied from Contabo's site. Saved edits go to `/data/manual_prices.json`, and
|
||
"Reset to built-in" goes back to the defaults. The other providers use the
|
||
bundled catalog in `app/data/providers.py`, which is dated. Each row shows its price source and a
|
||
confidence level.
|
||
|
||
## Accounts and sign-in
|
||
|
||
Everything needs a signed-in account or an API key. The only exceptions are the sign-in page and
|
||
`/healthz`.
|
||
|
||
| Role | Can |
|
||
|---|---|
|
||
| **admin** | Everything a user can, plus: create, disable, delete and re-role accounts, reset passwords, see and revoke every API key, create keys for any account, edit Contabo prices, refresh live prices |
|
||
| **user** | Use the web page and API (sizing, quotes, latency measurements), create and revoke their own API keys, change their own password |
|
||
|
||
In the web page, the account menu (your username, top right) has **API keys**, **Users** (admins),
|
||
**Change password**, **API docs** and **Sign out**.
|
||
|
||
- **API keys** belong to an account and act with that account's role. A key is shown only once, when
|
||
it's created; Coremarket stores only a hash of it. A key can have an expiry (in days) or never
|
||
expire. A key stops working when it's revoked, expires, or its account is disabled or deleted.
|
||
- **Safety rules:** the last active admin can't be demoted, disabled or deleted, and you can't disable
|
||
or delete your own account. Disabling an account, or resetting its password, signs it out
|
||
everywhere.
|
||
- **Passwords** need at least 10 characters and are stored as scrypt hashes. After 5 failed sign-ins
|
||
for the same username from the same address, sign-in is blocked for 5 minutes.
|
||
- **Storage:** accounts, keys and sessions live in `/data/coremarket.db` (SQLite) in the
|
||
`coremarket-data` volume. Back up that volume to keep them.
|
||
- **Lost the only admin password?** Stop the app, delete `/data/coremarket.db`, set
|
||
`ADMIN_USERNAME`/`ADMIN_PASSWORD`, and start again. This removes all accounts and keys.
|
||
|
||
## How it works
|
||
|
||
- **Sizing** (`app/engine.py`, `app/data/software.py`): each app has an idle RAM/CPU/disk footprint,
|
||
plus per-concurrent-user RAM/CPU and per-named-user disk. Shared databases are counted once, and
|
||
Federated Core (Traefik, PowerDNS, Authelia) is always included. Presets: Base (email, Headscale),
|
||
Good, Better, Best. Concurrent
|
||
users are assumed to be active in about 1.5 apps at a time, not all of them. Headroom and 12-month
|
||
disk growth are then added.
|
||
- **Matching**: in each region, the cheapest plan with at least the required vCPU and RAM wins. Block
|
||
storage is added if the plan's bundled disk is too small, and paid public IPv4 is included. You can
|
||
override the computed vCPU/RAM/disk in the UI.
|
||
- **Latency**: estimated from great-circle distance × 1.3 route factor at 204 km/ms, + 3 ms, plus
|
||
per-market penalties and +35 ms across the mainland-China border. For regions with a public probe
|
||
host, the detail view can measure real RTT through [Globalping](https://globalping.io) probes.
|
||
- **Compliance**: provider-level attestations for IaaS compute (yes / partial / no), with notes and
|
||
links in the Notes tab. HIPAA always needs a signed BAA.
|
||
|
||
## API
|
||
|
||
Coremarket has a JSON REST API. The web page uses the same API.
|
||
|
||
- **Base URL:** `http://localhost:8080/api/v1`
|
||
- **Authentication:** every call needs an API key in the `X-API-Key` header (or
|
||
`Authorization: Bearer <key>`). Create keys under **Account → API keys**. See
|
||
[Authentication](#authentication).
|
||
- **Interactive docs:** `http://localhost:8080/docs` (Swagger UI, where you can try every call; sign in
|
||
first). There's also `http://localhost:8080/redoc`.
|
||
- **OpenAPI spec:** `http://localhost:8080/openapi.json` (for generating client code; needs a key or
|
||
sign-in)
|
||
- **Prices** are USD per month unless a field says otherwise. Latencies are estimated round-trip times
|
||
in milliseconds.
|
||
|
||
### Quick start
|
||
|
||
```bash
|
||
export KEY=cmk_... # your API key (Account → API keys)
|
||
alias cm='curl -s -H "X-API-Key: $KEY"'
|
||
|
||
# Cheapest GDPR-compliant European option per provider for the Good tier,
|
||
# with average/worst latency to Paris and Berlin
|
||
cm "http://localhost:8080/api/v1/quote?tier=good&continent=europe&compliance=gdpr&cities=par,ber&best_per_provider=true&limit=5"
|
||
|
||
# HIPAA-eligible options for the Best tier, closest to Bogota and Lima first
|
||
cm "http://localhost:8080/api/v1/quote?tier=best&compliance=hipaa&cities=bog,lim&sort=rtt_max_ms&limit=5"
|
||
|
||
# Just the VM size for Base plus Vaultwarden, 20 concurrent users
|
||
cm -X POST http://localhost:8080/api/v1/size -H 'Content-Type: application/json' \
|
||
-d '{"tier": "base", "apps": ["vaultwarden"], "concurrent": 20}'
|
||
|
||
# Every option as a spreadsheet (one column per city latency)
|
||
cm -o quote.csv "http://localhost:8080/api/v1/quote?tier=better&format=csv"
|
||
```
|
||
|
||
### Endpoints
|
||
|
||
All paths are under `/api/v1`. "Role" is the minimum role needed.
|
||
|
||
| Method | Path | Purpose | Role |
|
||
|---|---|---|---|
|
||
| POST | `/auth/login` | Sign in with `{"username", "password"}`; sets the session cookie (browser use) | none |
|
||
| POST | `/auth/logout` | Sign out | none |
|
||
| GET | `/auth/me` | The signed-in account, or the API key's owner | user |
|
||
| POST | `/auth/password` | Change your password: `{"current_password", "new_password"}` | user |
|
||
| GET | `/keys` | Your API keys. Admin: `?all=true` or `?user_id=` | user |
|
||
| POST | `/keys` | Create a key: `{"name", "expires_days"?}`. Admin may add `"user_id"`. Returns the key once. | user |
|
||
| DELETE | `/keys/{key_id}` | Revoke a key (your own; admin: any) | user |
|
||
| GET | `/users` | List accounts (with key counts and last sign-in) | admin |
|
||
| POST | `/users` | Create an account: `{"username", "password", "role"}` (`role` is `user` or `admin`) | admin |
|
||
| GET | `/users/{user_id}` | One account | admin |
|
||
| PATCH | `/users/{user_id}` | Change `role`, set `disabled` true/false, or set a new `password` | admin |
|
||
| DELETE | `/users/{user_id}` | Delete an account and its keys | admin |
|
||
| GET | `/status` | API version, catalog date, live-pricing status, price source per provider | user |
|
||
| GET | `/apps` | All apps with resource profiles. Filters: `?tier=core\|library\|on_demand`, `?category=` | user |
|
||
| GET | `/apps/{app_id}` | One app | user |
|
||
| GET | `/tiers` | Federated tiers (base, good, better, best): apps, Federated price and storage | user |
|
||
| GET | `/cities` | The 40 latency target cities (`id` is used in `cities=`) | user |
|
||
| GET | `/continents` | Continent names used for filtering | user |
|
||
| GET | `/providers` | Providers: compliance, storage, IPv4, egress, SMTP, API doc links, price source | user |
|
||
| GET | `/providers/{provider_id}` | One provider with its regions and plans | user |
|
||
| GET | `/regions` | All regions. Filters: `?continent=`, `?provider=` | user |
|
||
| POST | `/size` | Compute the VM size for a workload | user |
|
||
| POST | `/quote` | Size the workload and price it in every matching region (JSON body) | user |
|
||
| GET | `/quote` | Same as POST `/quote`, using query parameters | user |
|
||
| GET | `/catalog` | Everything the web page needs in one call | user |
|
||
| POST | `/latency/measure` | Measure real RTT from a city to a region (uses Globalping quota) | user |
|
||
| GET | `/providers/{provider_id}/price-sheet` | Read a hand-maintained price sheet (Contabo) | user |
|
||
| PUT | `/providers/{provider_id}/price-sheet` | Replace that price sheet | admin |
|
||
| DELETE | `/providers/{provider_id}/price-sheet` | Reset it to the built-in defaults | admin |
|
||
| POST | `/prices/refresh` | Pull live prices from provider APIs now | admin |
|
||
|
||
Health check: `GET /healthz` (outside `/api/v1`, no sign-in).
|
||
|
||
### Managing accounts and keys with the API
|
||
|
||
```bash
|
||
# Admin: create an account, then a 90-day key for it
|
||
cm -X POST http://localhost:8080/api/v1/users -H 'Content-Type: application/json' \
|
||
-d '{"username": "alice", "password": "a-long-password", "role": "user"}'
|
||
# -> {"id": 2, "username": "alice", "role": "user", "disabled": false, ...}
|
||
|
||
cm -X POST http://localhost:8080/api/v1/keys -H 'Content-Type: application/json' \
|
||
-d '{"name": "alice reporting", "expires_days": 90, "user_id": 2}'
|
||
# -> {"key": "cmk_1a2b3c4d_...", "id": 5, "prefix": "cmk_1a2b3c4d_…", "username": "alice", "expires_at": ..., "warning": "..."}
|
||
|
||
# Disable, re-enable, or delete the account
|
||
cm -X PATCH http://localhost:8080/api/v1/users/2 -H 'Content-Type: application/json' -d '{"disabled": true}'
|
||
cm -X PATCH http://localhost:8080/api/v1/users/2 -H 'Content-Type: application/json' -d '{"disabled": false}'
|
||
cm -X DELETE http://localhost:8080/api/v1/users/2
|
||
|
||
# Any user: list and revoke your own keys
|
||
cm http://localhost:8080/api/v1/keys
|
||
cm -X DELETE http://localhost:8080/api/v1/keys/5
|
||
```
|
||
|
||
### Sizing and quote parameters
|
||
|
||
`POST /size` and `POST /quote` take a JSON body. `GET /quote` takes the same fields as query
|
||
parameters. For lists, repeat the parameter (`continent=europe&continent=asia`) or separate values
|
||
with commas (`continent=europe,asia`).
|
||
|
||
| Field | Type | Default | Meaning |
|
||
|---|---|---|---|
|
||
| `tier` | string | – | `base`, `good`, `better` or `best`. Its apps are included. |
|
||
| `apps` | list of app ids | `[]` | Apps to include, added to the tier's apps. Core apps (Traefik, PowerDNS, Authelia) are always included. |
|
||
| `concurrent` | int | `5` | Concurrent active users (drives CPU/RAM) |
|
||
| `named` | int | `10` | Named user accounts (drives disk) |
|
||
| `headroom` | float | `0.25` | Extra CPU/RAM (0.25 = 25%) |
|
||
| `disk_growth` | float | `0.3` | Extra disk for 12-month growth |
|
||
| `extra_disk_gb` | int | `0` | Disk to add on top, GB |
|
||
| **Quote only:** | | | |
|
||
| `continents` (GET: `continent`) | list | all | `North America`, `Europe`, `Asia`, `Australia`, `Africa`, `South America`. Case-insensitive; `north-america` also works. |
|
||
| `providers` (GET: `provider`) | list | all | Provider ids, e.g. `aws`, `hetzner`, `contabo` (see `/providers`) |
|
||
| `compliance` | list | none | `hipaa`, `soc2`, `pci`, `gdpr`. The provider must be `yes` for all of them. |
|
||
| `allow_partial_compliance` | bool | `false` | Also accept `partial` |
|
||
| `require_smtp` | bool | `false` | Exclude providers that hard-block outbound port 25 (needed by the email server) |
|
||
| `allow_arm` / `allow_burstable` / `dedicated_only` | bool | `false` / `true` / `false` | CPU type filters |
|
||
| `override` (GET: `vcpu`, `ram_gb`, `disk_gb`) | object | – | Use these instead of the computed size, e.g. `{"vcpu": 8, "ram_gb": 32}` |
|
||
| `cities` | list of city ids | `[]` | Cities used for `rtt_avg_ms` / `rtt_max_ms` |
|
||
| `max_rtt_ms` | int | – | Drop results whose worst RTT to `cities` is higher |
|
||
| `best_per_provider` | bool | `false` | Keep only each provider's cheapest region |
|
||
| `sort` | string | `total` | `total`, `recurring`, `rtt_avg_ms`, `rtt_max_ms`, `vcpu`, `ram_gb`, `provider` |
|
||
| `limit` | int | all | Return at most this many results (`count` still reports the full number) |
|
||
| `include_latency` | bool | POST `true`, GET `false` | Include RTT to all 40 cities per result |
|
||
| `include_alternatives` | bool | POST `true`, GET `false` | Include next-best plans in the same region |
|
||
| `format` (query) | string | `json` | `csv` returns a spreadsheet instead (always includes all city latencies) |
|
||
|
||
Unknown tiers, apps, continents, providers, cities or compliance names return **422** with a message
|
||
listing the valid values.
|
||
|
||
### Quote response
|
||
|
||
```jsonc
|
||
{
|
||
"sizing": { "need": {...}, "standard": {...}, "family": "...", "raw": {...}, "lines": [...], "notes": [...], "apps": [...] },
|
||
"need": { "vcpu": 4, "ram_gb": 12, "disk_gb": 270, "ram_exact": 11.8, "cpu_exact": 3.17 },
|
||
"count": 13, // matching results before `limit`
|
||
"returned": 2,
|
||
"results": [
|
||
{
|
||
"provider_id": "contabo", "provider": "Contabo",
|
||
"region": "eu-de-nue", "location": "Nuremberg", "country": "DE", "continent": "Europe",
|
||
"model": "Cloud VPS 8 (V155)", "vcpu": 8, "ram_gb": 24, "disk_gb": 300,
|
||
"cpu_type": "shared", "arch": "x86_64", "plan_note": "SSD, 600 Mbit/s",
|
||
"base_price": 16.24, // VM, per month
|
||
"extra_storage_gb": 0, "extra_storage_cost": 0.0,
|
||
"ipv4": 0.0,
|
||
"recurring": 16.24, // VM + extra storage + IPv4, per month
|
||
"setup_fee": 2.32, // one-time
|
||
"total": 18.56, // first month = recurring + setup_fee
|
||
"storage_price_gb": null, // additional block storage, $/GB-month (null = not offered)
|
||
"compliance": { "hipaa": "no", "soc2": "no", "pci": "no", "gdpr": "yes" },
|
||
"smtp25": "open", // open | on request | blocked
|
||
"egress": { "included_gb": null, "per_gb": null, "note": "Unmetered (32 TB fair use)" },
|
||
"price_source": "manual sheet 2026-12-01 (defaults)", "price_confidence": "medium",
|
||
"rtt_avg_ms": 10, "rtt_max_ms": 11, // over the requested `cities`
|
||
"latency": { "nyc": 85, "par": 10, ... }, // when include_latency
|
||
"alternatives": [ ... ], // when include_alternatives
|
||
"ping_host": null // host for /latency/measure, if available
|
||
}
|
||
]
|
||
}
|
||
```
|
||
|
||
`need` is what the plans are matched against. It equals `sizing.need` unless you send `override`.
|
||
|
||
### Price sheets (Contabo)
|
||
|
||
Contabo has no pricing API, so its prices live in an editable sheet:
|
||
|
||
```bash
|
||
# Read the current sheet
|
||
cm http://localhost:8080/api/v1/providers/contabo/price-sheet
|
||
|
||
# Replace it (admin; prices in the sheet's currency, per month; surcharge is % per region code)
|
||
cm -X PUT http://localhost:8080/api/v1/providers/contabo/price-sheet -H 'Content-Type: application/json' \
|
||
-d '{
|
||
"currency": "EUR", "fx": 1.16, "setup_fee": 2.00,
|
||
"plans": [
|
||
{"code": "V153", "name": "Cloud VPS 4", "vcpu": 4, "ram_gb": 8, "disk_gb": 100, "price": 5.50},
|
||
{"code": "V154", "name": "Cloud VPS 6", "vcpu": 6, "ram_gb": 12, "disk_gb": 200, "price": 7.50}
|
||
],
|
||
"region_surcharge_pct": {"us-east": 0, "us-west": 20, "sin": 40}
|
||
}'
|
||
|
||
# Go back to the built-in sheet
|
||
cm -X DELETE http://localhost:8080/api/v1/providers/contabo/price-sheet
|
||
```
|
||
|
||
Plan fields: `name`, `vcpu`, `ram_gb` and `price` are required. `code`, `disk_gb`, `cpu_type`
|
||
(`shared`/`dedicated`) and `note` are optional. Regions missing from `region_surcharge_pct` get 0%.
|
||
|
||
### Latency measurement
|
||
|
||
```bash
|
||
cm -X POST http://localhost:8080/api/v1/latency/measure -H 'Content-Type: application/json' \
|
||
-d '{"host": "ash-speed.hetzner.com", "city": "was"}'
|
||
# -> {"host": "...", "city": "Washington DC", "probe_scope": "city", "min_ms": ..., "results": [{"probe": "Washington, US (...)", "avg_ms": ...}, ...]}
|
||
```
|
||
|
||
`host` must be a region's `ping_host` from `/regions` or a quote result. If Globalping has no probe in the city, the
|
||
measurement falls back to the whole country and `probe_scope` says `country`. Probe hosts are available for AWS,
|
||
Hetzner and OVHcloud regions. Other providers don't publish one that answers, so they show estimates only. This calls the free
|
||
[Globalping](https://globalping.io) service, which limits how often it can be used. Set
|
||
`GLOBALPING_TOKEN` for a higher limit.
|
||
|
||
### Authentication
|
||
|
||
- **Scripts and integrations:** send an API key with every request, as `X-API-Key: <key>` or
|
||
`Authorization: Bearer <key>`. Keys look like `cmk_<8 characters>_<secret>`. The request runs with
|
||
the key owner's role.
|
||
- **Browsers:** sign in at `/login`. The session is an HttpOnly cookie that lasts `SESSION_HOURS`.
|
||
Requests that change data using a session must also send the header `X-Coremarket: 1`, so other
|
||
websites can't submit forms on a signed-in user's behalf. The web page does this automatically; API
|
||
key requests don't need it.
|
||
- **Swagger UI (`/docs`):** sign in first. Then use **Authorize** to paste an API key, which also lets
|
||
you try write calls.
|
||
|
||
A missing, invalid, expired or revoked key returns **401**. A valid key or session without the
|
||
needed role returns **403**.
|
||
|
||
### Errors
|
||
|
||
Errors return JSON `{"detail": "..."}`: **401** not signed in or invalid key, **403** role not allowed
|
||
(or missing `X-Coremarket` header on a session write), **404** not found, **409** conflict (e.g.
|
||
duplicate username, removing the last admin), **422** invalid parameters, **429** too many failed
|
||
sign-ins, **502** an upstream service (Globalping) failed.
|
||
|
||
### Versioning
|
||
|
||
Everything lives under `/api/v1`. Fields may be added within v1. Removing or renaming fields would
|
||
mean a new `/api/v2`.
|
||
|
||
## Updating data
|
||
|
||
- Prices and regions: `app/data/providers.py` (bump `CATALOG_DATE`)
|
||
- App profiles: `app/data/software.py`
|
||
- Cities: `app/data/cities.py`
|
||
- New live adapter: add a function to `ADAPTERS` in `app/live.py`
|