Starting from scratch? Read DEPLOY.md instead. It is the linear walkthrough for GitHub -> Neon -> Render -> Vercel. This document is the reference you reach for when something goes wrong, or when you need the option this walkthrough did not take.
Step-by-step deployment of shouldcost-sg to Render (backend + PostgreSQL) and Vercel (frontend). Written because the capability probe found no Render or Vercel credentials in the environment, so milestone M6 could not be executed and these steps are manual.
Total time: ~25 minutes. No step requires a paid plan.
Replace every <placeholder> with your own value. Never commit a real credential.
| Component | Host | Name | Notes |
|---|---|---|---|
| Web service (FastAPI) | Render | shouldcost-backend |
root dir backend/ |
| PostgreSQL | Render | shouldcost-db |
plan free, region singapore |
| Static SPA | Vercel | your project name | root dir frontend/ |
- A GitHub account (or GitLab/Bitbucket - Render and Vercel both support them).
- A Render account - https://dashboard.render.com/register
- A Vercel account - https://vercel.com/signup
- git installed locally:
git --version - Node.js 20+ and Python 3.11 for local verification before deploying.
Verify your local build passes before pushing. Deploying a broken repo wastes a build cycle:
make install && make seed && make test && make buildcd shouldcost-sg
git init
git add .
git commit -m "shouldcost-sg: FastAPI + React BoQ should-cost benchmarking"
git branch -M main
git remote add origin https://github.com/<your-account>/shouldcost-sg.git
git push -u origin mainConfirm nothing secret was pushed. .gitignore excludes .env, *.db, node_modules/ and
dist/. Double-check with:
git ls-files | grep -E "(^|/)\.env$|\.db$" # must print nothingDefault branch must be main - render.yaml pins branch: main.
- Go to https://dashboard.render.com/ -> New -> Blueprint.
- Connect your GitHub account and select the
shouldcost-sgrepository. - Render detects
render.yamlat the repo root and shows a preview of the resources it will create. Confirm you see 1 web service and 1 database. - Name the Blueprint and click Apply.
- Render prompts for the two variables marked
sync: false:FRONTEND_URL- leave blank for now. Step 9 sets it after the Vercel deploy exists.FRONTEND_PREVIEW_REGEX- optional, leave blank to deny all preview origins.
- Render starts building the backend. The first build will fail its health check if the database has not been seeded - that is expected, continue to step 5 below.
services:
- type: web
name: shouldcost-backend
runtime: python # Render deprecates the older `env:` field
rootDir: backend
plan: free
region: singapore
buildCommand: pip install -r requirements.txt
startCommand: uvicorn app.main:app --host 0.0.0.0 --port $PORT
healthCheckPath: /api/healthzTwo deliberate deviations from a naive reading of the brief, both verified against https://render.com/docs/blueprint-spec:
- The brief asked for
env: python. Render documentsruntimeas the current field and states it replaces the deprecatedenvfield.env: pythonstill parses today but is legacy, soruntime: pythonis used.- The brief asked for
PYTHON_VERSION=3.11. Render's docs are explicit: with the environment- variable method you must specify a fully qualified version. A bare3.11is ignored and the service silently builds on Render's default Python instead.3.11.6is pinned.
- In the dashboard, open the shouldcost-db database. Its status should reach Available.
- Open the shouldcost-backend web service -> Environment. Confirm
DATABASE_URLis present and marked as coming fromshouldcost-db. - Do not edit it by hand. If you ever need to copy it manually, note that Render may present
the legacy
postgres://scheme; the backend normalisespostgres://andpostgresql://topostgresql+psycopg2://inapp/config.py, so either form works.
FastAPI creates any missing tables on startup (init_db() in the lifespan handler), so a brand-new
database is immediately usable - it is simply empty until step 5.
Chosen approach: (a) a one-off job.
The brief allows either. preDeployCommand: python -m app.etl is cleaner in principle, but
pre-deploy commands are only available on paid instance types, and this Blueprint deliberately
runs on the free plan so it can be deployed at zero cost. The line is present in render.yaml,
commented out, so you can enable it in one edit if you upgrade.
-
Render dashboard -> shouldcost-backend -> Shell tab (available on free web services) and run:
python -m app.etl
After a schema change, use
python -m app.etl --resetinstead.create_all()adds missing tables but never ALTERs an existing one, so a new column stays invisible until the table is rebuilt.--resetdrops every table and destroys any uploaded BoQs.Expected output:
ETL: reading seed CSVs from /opt/render/project/src/backend/data ETL: row counts after load tpi_series 32 material_prices 36 benchmark_rates 10 boq_uploads 1 boq_items 20 ETL: complete (published index series are real; benchmark rates, regional multipliers and the construction cost index quarters are indicative seed values, every one carrying is_placeholder = true)If the Shell tab is unavailable to you, add a temporary Job to
render.yaml(type: job,runtime: python,rootDir: backend,startCommand: python -m app.etl) and run it once from the dashboard, then remove it. -
The ETL is idempotent. Every row is upserted on its natural key, and the sample BoQ upload is replaced rather than duplicated. Running it twice produces identical row counts - this is verified by the M1 gate (
python -m app.etltwice, same counts). It is therefore safe to re-run after any redeploy. -
Verify:
curl https://<your-service>.onrender.com/api/healthzmust return{"status":"ok","db":"connected",...}.
- https://vercel.com/new -> import the same GitHub repository.
- Root Directory:
frontend. This is the single most common mistake - without it Vercel tries to build the repository root and fails. - Framework Preset: Vite.
- Build Command:
npm run build(also set infrontend/vercel.json). - Output Directory:
dist(also set infrontend/vercel.json). - Do not deploy yet - set the environment variable first (step 7).
-
Project -> Settings -> Environment Variables.
-
Add:
Name Value Environments VITE_API_BASE_URLhttps://<your-service>.onrender.comProduction, Preview, Development -
No trailing slash. The frontend strips any it finds, but keep it clean.
-
This value is inlined into the JavaScript bundle at BUILD time. Vite substitutes
import.meta.env.VITE_API_BASE_URLduringnpm run build. It is not read at runtime, so changing it does nothing until you redeploy.
- Click Deploy (or push to
mainif you already connected the project). - Note the production URL, e.g.
https://shouldcost-sg.vercel.app. - Open it. The status strip in the header should read
API ok | db connected | production. - If it instead shows "Cannot reach the backend", the cause is almost always CORS - the backend does not yet know this origin. Do step 9 and then reload.
SPA routing. frontend/vercel.json declares:
{ "rewrites": [{ "source": "/(.*)", "destination": "/" }] }so that entering a deep link or pressing refresh does not 404. This app does not proxy /api
through Vercel - the browser calls Render directly using the baked-in VITE_API_BASE_URL.
There is a real trade-off here. The proxy hides the Render URL, gives you a same-origin setup with no CORS preflight, and lets you swap backends without rebuilding the frontend. It also puts a CDN between the user and a dynamic, per-request benchmark response, adds a hop of latency, and consumes Vercel bandwidth - and you must defeat the caching explicitly.
If you want that pattern, add this to frontend/vercel.json, set VITE_API_BASE_URL to your
Vercel domain, and exclude /api from the SPA catch-all:
"rewrites": [
{ "source": "/api/:path*", "destination": "https://<your-service>.onrender.com/api/:path*" },
{ "source": "/((?!api/).*)", "destination": "/" }
],
"headers": [
{
"source": "/api/(.*)",
"headers": [{ "key": "x-vercel-enable-rewrite-caching", "value": "0" }]
}
]x-vercel-enable-rewrite-caching: 0 is required - without it the CDN may serve a stale benchmark
response for the wrong upload. The default configuration in this repo does not need it because no
requests are rewritten to the backend.
The backend builds its CORS allowlist from the environment. A wildcard is never used.
-
Render dashboard -> shouldcost-backend -> Environment.
-
Set
FRONTEND_URLto the Vercel production URL, e.g.https://shouldcost-sg.vercel.app. No trailing slash. -
(Optional) Set
FRONTEND_PREVIEW_REGEXto allow Vercel preview deployments, e.g.^https://shouldcost-.*\.vercel\.app$Leave it unset to deny every preview origin. Previews are opt-in by design - an open preview pattern lets anyone who can trigger a branch build talk to your API.
-
Save. Render redeploys the service automatically; wait for the deploy to go Live.
curl https://<your-service>.onrender.com/api/healthzExpected: {"status":"ok","db":"connected","environment":"production"}
curl -X OPTIONS \
-H "Origin: https://<your-vercel-url>" \
-H "Access-Control-Request-Method: POST" \
-H "Access-Control-Request-Headers: content-type" \
https://<your-service>.onrender.com/api/boq/upload -vExpect HTTP/1.1 200 OK and a response header:
< access-control-allow-origin: https://<your-vercel-url>
If access-control-allow-origin is missing, FRONTEND_URL does not match the calling origin
exactly. Compare it character by character - a trailing slash or http:// instead of https:// is
enough to break it.
curl -X POST https://<your-service>.onrender.com/api/boq/upload \
-F "file=@backend/data/sample_boq.csv"Expected: row_count: 20, classified_count: 18, unclassified_count: 2, upload_id: 1.
curl -X POST https://<your-service>.onrender.com/api/boq/1/benchmark \
-H "Content-Type: application/json" \
-d '{"tender_quarter":"2024Q4","tpi_series_name":"RLB","variance_threshold":15}'Expect warnings[] to contain a line naming Piling and RLB, and waterfall[] to reconcile:
boq_total + sum(waterfall amounts) == should_cost_total to the cent.
curl https://<your-service>.onrender.com/api/countries
curl "https://<your-service>.onrender.com/api/indices/tpi?country=IN"
curl -X POST "https://<your-service>.onrender.com/api/boq/2/benchmark" \
-H "Content-Type: application/json" \
-d '{"tender_quarter":"2024Q4","tpi_series_name":"CPWD","variance_threshold":15}'Expect INR amounts, classification_standard: "IS 1200 / CPWD DSR", and a warnings[] entry
naming Piling and CPWD. Also check the downloads:
curl -o template.csv "https://<your-service>.onrender.com/api/boq/template?format=csv&country=IN"
curl -o template.xlsx "https://<your-service>.onrender.com/api/boq/template?format=xlsx&country=SG"Both must be non-empty; the CSV must upload cleanly through /api/boq/upload?country=IN.
# India's regional multipliers
curl "https://<your-service>.onrender.com/api/indices/regions?country=IN"
# The same BoQ at two regional multipliers - should-cost must differ
curl -X POST "https://<your-service>.onrender.com/api/boq/2/benchmark" -H "Content-Type: application/json" \
-d '{"tender_quarter":"2024Q4","tpi_series_name":"WPI-CONST","variance_threshold":15,"region_code":"DEL"}'
curl -X POST "https://<your-service>.onrender.com/api/boq/2/benchmark" -H "Content-Type: application/json" \
-d '{"tender_quarter":"2024Q4","tpi_series_name":"WPI-CONST","variance_threshold":15,"region_code":"MUM"}'
# The full self-describing report
curl -X POST "https://<your-service>.onrender.com/api/boq/2/export?format=csv&level=report" \
-H "Content-Type: application/json" \
-d '{"tender_quarter":"2024Q4","tpi_series_name":"WPI-CONST","variance_threshold":15,"region_code":"MUM"}' \
-o report.csvExpect Mumbai's should-cost to be ~12.8% above Delhi's, and report.csv to contain the blocks
report, totals, section, waterfall, line, adjustment, warning, assumption and
source.
curl "https://<your-service>.onrender.com/api/indices/materials?country=SG" | head -c 400
curl "https://<your-service>.onrender.com/api/indices/coverage?country=IN" | head -c 400Every Singapore material row must carry "is_placeholder": false and a provenance_note
starting REAL DATA.. If any row says true, the seed did not load correctly.
The coverage call must show "producer_series_count": 16 and "uncovered_sections": [] (or just
Unclassified) for India: that proves the producer price index seed loaded and that every canonical
section has a published series able to re-price it. Singapore must show
"producer_series_count": 0 and a notes entry naming M213461/M213411 - the documented gap, not a
failed seed.
- Open the Vercel URL. The header strip shows
API ok | db connected | production. - Upload tab -> upload
backend/data/sample_boq.csv-> classification counts render. - Variance table -> threshold-breaching rows are highlighted red/blue, section subtotals appear, click any description to expand its benchmark provenance.
- Waterfall -> the reconciliation banner reads "Reconciled ... within S$0.01".
- Switch TPI series to
RLB-> the benchmark re-runs live and the scope warning for Piling appears in the assumptions panel. - Open the browser console. There must be no CORS errors.
| Symptom | Cause | Fix |
|---|---|---|
| Console: "blocked by CORS policy: No 'Access-Control-Allow-Origin' header" | FRONTEND_URL on Render does not exactly match the browser origin |
Set it to the exact origin: scheme + host, no trailing slash, no path. Redeploy. Re-run 10b. |
| Console: "No response from ... Is the backend running..." and the network tab is empty | VITE_API_BASE_URL was set after the last build |
Vite inlines it at build time. Redeploy on Vercel (a redeploy, not just an env change). |
Frontend calls http://localhost:8000 in production |
VITE_API_BASE_URL is unset, so the documented local-dev fallback kicked in |
Set it in Vercel -> Settings -> Environment Variables -> Production, then redeploy. |
404 when refreshing a deep link, or on any route other than / |
SPA rewrite missing or overridden | Confirm frontend/vercel.json contains the /(.*) -> / rewrite and that Vercel's Root Directory is frontend, so the file is actually read from there. |
/api/healthz returns {"status":"degraded","db":"error: ..."} |
DATABASE_URL missing or the database is unavailable |
Check the env var exists on the web service and references shouldcost-db. Confirm the database status is Available. On a free instance that has passed 30 days, the database is deleted - see below. |
| Deploy fails: "Application exited early" or the port never binds | The start command does not bind $PORT |
It must be exactly uvicorn app.main:app --host 0.0.0.0 --port $PORT. A hardcoded port fails on Render. |
| Deploy fails: "No module named app" | Render is building from the repo root | rootDir: backend must be set (it is, in render.yaml). |
| Upload returns 500 or "no space left on device" | The upload was written to Render's ephemeral disk | This app never writes uploads to disk - it parses in memory. If you added code that does, remove it; Render wipes the disk on every redeploy and the file will vanish mid-request. |
| Upload returns 413 | File exceeds the 10 MB in-memory limit | Split the BoQ, or remove unused columns. The limit protects the 512 MB free instance. |
| Upload returns 422 naming a missing column | The CSV headers were not recognised | Required: description, unit, quantity, rate. Common aliases are accepted; see COLUMN_ALIASES in backend/app/routers/boq.py. |
Upload returns 422 for a .xls file |
Legacy BIFF Excel is not supported | Re-save as .xlsx or .csv. |
| Health check passes but the first page load is slow | Free Render web services sleep after 15 minutes of inactivity | Expected on the free plan. The first request after a sleep takes ~30-60 s. Upgrade to a paid instance to avoid it. |
| Everything worked, then stopped ~30 days later | Free Render PostgreSQL instances are deleted after 30 days | Create a paid database (plan: 0.1c-256mb or higher) and update the Blueprint, or re-provision and re-run step 5. Data is not recoverable after deletion. |
make test fails but the service runs fine |
Locally the tests use a throwaway SQLite database | Check nothing else is holding backend/shouldcost.db. The suite itself never touches it. |
# Render: dashboard -> shouldcost-backend -> Events -> pick a previous deploy -> Rollback
# Vercel: dashboard -> Deployments -> pick a previous deployment -> Promote to ProductionBecause the seed data is idempotent and the schema is created on boot, a rollback needs no manual database step unless the schema itself changed.
-
curl .../api/healthzreturnsstatus: ok,db: connected - CORS preflight returns
access-control-allow-originfor the Vercel origin - Sample BoQ uploads and classifies 18/20 rows
- Benchmark with
RLBemits the named Piling scope warning - Waterfall reconciles within S$0.01
- No CORS errors in the browser console
-
FRONTEND_URLset on Render and marked as a secret (sync: falseinrender.yaml) - No
.envfile or credential committed:git ls-files | grep -E "(^|/)\.env$"prints nothing - Reminder set for day 25 - free Render PostgreSQL expires on day 30 (or move it to Neon now - see section 14)
The free-tier landscape contracted sharply during 2025-2026. Two of the options most often recommended in older blog posts are no longer available to new users:
| Service | Status |
|---|---|
| Fly.io | Free tier removed for new accounts. Machines bill per second; a small app realistically lands at $8-25/mo once egress is counted. |
| Koyeb | Mistral acquired Koyeb (Feb 2026). The Starter plan is closed to new signups; existing orgs keep it "for the coming months". Cheapest listed plan is Pro at $29/mo. |
| Heroku | Free plans shut down in 2022. |
| Glitch / Deta Space / ElephantSQL | Shut down. |
| Option | Backend | Database | Sleeps? | Card? |
|---|---|---|---|---|
| Render + Vercel + Neon ⭐ | Render free (512 MB) | Neon free | API after 15 min; static site never | No |
| Render + Vercel + Render Postgres (this runbook) | Render free | Render free | API after 15 min | No |
| All on Render | Render free web | Render free | API after 15 min; static site never | No |
| Cloudflare Pages + Render + Neon | Render free | Neon free | API after 15 min; Pages never | No |
| Hugging Face Spaces (Docker) | Free CPU basic | Neon free (external) | After 48 h inactivity | No |
| Google Cloud Run | Always-free tier | Neon free | Cold starts, not sleep | Yes |
| Oracle Cloud Always Free | ARM VM, 4 cores / 24 GB, no expiry | self-hosted Postgres | No | Yes |
| Railway | $5 trial credit, ~500 h | included | No | Trial only |
Render's free PostgreSQL instance is deleted after 30 days. Neon's free plan does not expire: an idle project suspends compute and wakes on the next query, so it is slow on the first request but nothing is lost. The free plan covers 100 projects, 10 branches per project and a 6-hour restore window.
To switch:
- Create a project at https://neon.tech and copy its connection string.
- On Render, edit the
shouldcost-backendservice and replaceDATABASE_URL. If you keep the Blueprint'sfromDatabasereference, remove it first - otherwise Render overwrites your value on the next deploy. Easiest is to delete thedatabases:block fromrender.yamland setDATABASE_URLas a plainsync: falsevariable. - Redeploy, then run
python -m app.etlin the Render Shell.
No code change is needed. app/config.py normalises both postgres:// and postgresql://,
and the app was verified against real PostgreSQL 16 - the full 205-test suite then in the repository passed on Postgres (the suite is now 229 tests; the Postgres leg has not been re-run since the CPI bridge was added)
as well as SQLite.
Supabase is the alternative, but its free plan pauses a project after one week of inactivity (restorable from the dashboard), allows only 2 active projects, and includes no backups.
Add a static site to render.yaml and drop Vercel entirely:
- type: web
name: shouldcost-frontend
runtime: static
rootDir: frontend
buildCommand: npm install && npm run build
staticPublishPath: ./dist
envVars:
- key: VITE_API_BASE_URL
value: https://shouldcost-backend.onrender.com
routes:
- type: rewrite
source: /*
destination: /index.htmlRender static sites do not sleep, so only the API pays the 15-minute cold-start penalty. One dashboard, one bill (zero), one place to configure CORS.
backend/Dockerfile builds a portable image, which unlocks Render, Cloud Run, Railway,
Northflank, Hugging Face Spaces and any plain VM. It runs as a non-root user, honours $PORT,
and needs no write access because uploads are parsed in memory.
docker build -t shouldcost-backend ./backend
docker run -p 8000:8000 -e DATABASE_URL=postgresql://... shouldcost-backendSQLite and PostgreSQL are not the same database, so the production path should be exercised before you rely on it:
docker compose up --build
docker compose exec backend python -m app.etl
# full suite against real PostgreSQL:
docker compose exec -T \
-e SHOULDCOST_TEST_DATABASE_URL=postgresql://shouldcost:shouldcost@db:5432/shouldcost_test \
backend python -m pytest tests -q
docker compose down -vEvery free option above shares the same three problems, and they are worth stating plainly:
- Cold starts. A slept API takes 30-60 s to answer the first request. Fine for a demo, unacceptable for a tender review with a client watching.
- The app has no authentication. Every endpoint is open. Do not put a real commercial Bill of Quantities on a public free URL.
- The benchmark rates are indicative seed values, not published data. CPWD DSR and BCA
Construction InfoNet are licensed publications, so the 20 rate rows carry
is_placeholder: true, a source URL and a TODO. The published index series are real, and the figures the engine derives from them are labelled as derived. Free hosting is not the blocker to production here - licensing and auth are.
If this is going in front of real tender work, budget for a paid instance (Render from ~$7/mo) for the always-on API, and treat the hosting spend as the smallest line in the project.