Deploy FastAPI - PostgreSQL
A comprehensive FastAPI and PostgreSQL template.
Just deployed
/var/lib/postgresql/data
Fullstack-FastAPI
Just deployed
Overview
The most complete FastAPI + PostgreSQL template on Railway — fully async, production-ready, and built with modern Python best practices. Skip weeks of boilerplate and start building your API in minutes.
Whether you're prototyping a side project or scaffolding a production service, this template gives you everything you need out of the box: async database access, authenticated API docs, structured project layout, and one-click deployment.
Why This Template?
-
Fully async from top to bottom: Every endpoint, CRUD operation, and database call is non-blocking — no thread pool bottlenecks, no mixed sync/async confusion. Just clean, fast async Python.
-
SQLAlchemy 2.0 + PostgreSQL: Modern ORM with
select()queries,async_sessionmaker, and native UUID support. Auto-creates tables on startup, disposes connections on shutdown — zero manual setup. -
Authenticated API docs:
/docsand/redocare protected behind session-based login using a pure ASGI middleware (noBaseHTTPMiddlewareoverhead). Your API documentation stays private until you're ready to share. -
Production-grade performance: FastAPI 0.139 with Rust-powered JSON serialization (pydantic-core),
uvloop+httptoolsfor maximum throughput, and GZIP compression. -
Tuned for your Railway bill: ~62MB idle memory (not the typical 150MB Python footprint) — multi-stage image, glibc arena capping, precompiled bytecode, no wrapper processes. Railway bills by memory per minute; this template respects that.
-
Modern Python tooling: Managed with
uvandpyproject.toml— fast, reproducible installs with no dependency conflicts. Python 3.12, Pydantic v2, and cleansrc/project layout. -
Ready to extend: Clean separation between API endpoints, service layer, models, and schemas. Add new resources by following the existing
messagespattern — no guesswork needed.
What's Included
- FastAPI with async CRUD endpoints (Create, Read, Update, Delete)
- PostgreSQL with SQLAlchemy 2.0 async engine
- Time-ordered UUIDv7 primary keys (PostgreSQL 18-ready)
- Alembic async migrations
- Pydantic v2 request/response validation
- Session-based authentication for API docs
/healthendpoint wired for Railway healthchecks- Environment-driven configuration (
.env.exampleprovided) - Docker multi-stage build
- Async test suite with pytest
- Locust load testing configuration
Quick Start
- Click Deploy — you'll be prompted for
USER_NAMEandPASSWORD(your API docs login) before the FastAPI app + PostgreSQL database provision - Left them empty? No problem — credentials are auto-generated and printed once in the deploy logs
- Visit your deployment URL — your API is live
Learn More
Template Content
Fullstack-FastAPI
yuting1214/Fullstack-FastAPIPASSWORD
Password for accessing OpenAPI document.
USER_NAME
User name for accessing OpenAPI document.