Verified against Replit Agent · 2026-08-03
Build and deploy a FastAPI backend with a real database
A Replit Agent brief for a FastAPI backend that gets deployed for real, with secrets set for the deployed environment specifically and a health check that actually verifies the database connection.
The prompt
Ready to copy — highlighted parts are example details you can swap.
Build and deploy a FastAPI backend for a small internal API that a separate frontend team's app will call to look up and update shipment tracking records, ending with it actually live at a real, reachable URL — not just runnable inside the Replit workspace.
API SURFACE
Endpoints: GET /shipments/{id}, GET /shipments (paginated, filterable by status), POST /shipments, PATCH /shipments/{id}/status. Every request and response body gets a Pydantic model — no raw dict passed straight through from a request to a database call and back; the model is what gives me actual validation errors instead of a 500 when a client sends a malformed field.
DATA LAYER
Use Replit's managed Postgres database for persistence, with the connection string read from a Replit Secret, never hardcoded in the code even for a "just testing" first pass — a hardcoded connection string committed once tends to stay committed. Write the actual schema (as SQLAlchemy models or raw SQL migrations, your call, but pick one and be consistent) rather than creating tables ad hoc from application code paths that happen to run first — I want a single, explicit place that defines the schema.
RELIABILITY AND HEALTH
Add a /healthz endpoint that checks the actual database connection (not just returning a static 200) and returns a non-200 status if the database is unreachable — this is what a deployment platform's health check should actually be pinging, not the root route. Handle the obvious failure modes explicitly: a request for a resource that doesn't exist returns 404 with a clear message, a validation failure returns 422 with the specific field that failed, and an unexpected exception is caught by a global exception handler that logs the real error server-side but returns a generic message to the client — never a raw stack trace in a production response.
AUTH
A single static API key checked via an X-API-Key header — no full OAuth needed for this internal service yet.
DEPLOYMENT
Deploy this using Replit's Autoscale (this API has bursty, unpredictable traffic rather than a constant load) deployment, not just leaving it running in the workspace's dev server, which stops the moment I close the browser tab. Set up the environment variables/secrets needed for the deployed version specifically, since Replit's deployment environment does not automatically inherit whatever you typed into the workspace's dev-only shell session. After deploying, give me the real, live URL and the exact curl command to hit /healthz and confirm it's actually up, not just that the deploy step reported success.
DOCUMENTATION
Since this is an API with no UI, generate the OpenAPI docs FastAPI provides automatically at /docs, and confirm they're reachable at the deployed URL too, not only in the dev workspace — a common gap is deployment config that works for the app's main routes but accidentally blocks or misconfigures the docs route.
CONSTRAINTS
Add a basic per-API-key rate limit of 100 requests/minute — the frontend team will be given a single shared key for now. Type every function signature — no bare dict or Any where a Pydantic model or a concrete type should be used instead.Customize
Optional — swap in your own details for the highlighted parts above.
Why this works
Replit Agent's ability to actually deploy, not just run inside an interactive dev session, is the specific capability this prompt is written around, and it's the thing the other three tools in this category don't do the same way — Lovable, Bolt.new, and v0's previews are all, in their own way, a session that ends the moment the tab closes. Naming the deployment type explicitly, Autoscale versus a Reserved VM, is necessary because Replit's own deployment product requires that choice and defaults to whichever type it built most recently in a given session rather than the one that actually fits a bursty API traffic pattern like the one described here. Requiring secrets to be set for the deployment specifically, not just the workspace, targets a real and easy-to-miss gap in how Replit's environment model works. Values available to a workspace's interactive shell session are not automatically the same set of environment variables available to a deployed instance of that app, so a backend that works perfectly when tested inside the workspace can fail immediately on deploy with a missing-connection-string error — a failure that's confusing precisely because "it worked five minutes ago" was true, just in a different environment than the one that actually matters once it's live. A health check that verifies the real database connection, rather than returning a static 200 regardless of backend state, addresses what a health-check endpoint is actually for in a deployed system. A platform's automated health monitor pinging /healthz is trying to answer whether this instance can actually serve real requests right now, and a health check that always returns 200 gives false confidence that masks exactly the failure — a lost database connection — that the endpoint exists to catch, right up until a real user's request fails for a reason the monitoring never flagged as a problem.
Verified against
Replit Agent Replit Agent (chat-based build mode, with Replit Deployments) · 2026-08-03
Changelog
- 2026-08-03 — Initial publish, verified against Replit Agent with deployment-scoped secrets and a database-checking health endpoint.
Need this built into your business?
If a prompt isn't enough — custom software, built and maintained for you — that's Scult's day job.
EXPLORE CUSTOM SOFTWARE
