---
title: "Deploy full-stack-fastapi-mongodb"
description: "One-Click Deploy official fullstack fastapi template with mongodb"
category: "Starters"
url: https://railway.com/deploy/full-stack-fastapi-1
---

# Deploy full-stack-fastapi-mongodb

One-Click Deploy official fullstack fastapi template with mongodb

**[Deploy full-stack-fastapi-mongodb on Railway](https://railway.com/template/full-stack-fastapi-1)**

- **Creator:** Nameless 's Projects
- **Category:** Starters
- **Total deploys:** 1

## Template content

### frontend+backend

- **Source:** https://github.com/lNamelessl/full-stack-fastapi-mongodb
- **Health check:** /health
- **Public domain:** Yes

### MongoDB https://devicons.railway.app/i/mongodb.svg

- **Image:** mongo:8.0
- **Start command:** `docker-entrypoint.sh mongod --ipv6 --bind_ip ::,0.0.0.0 --setParameter diagnosticDataCollectionEnabled=false`

## Documentation

#Deploy and Host Full Stack FastAPI with MongoDB
# Full Stack FastAPI + MongoDB

[![Deploy on Railway](https://railway.com/button.svg)](https://railway.app/new?github_url=https://github.com/lNamelessl/full-stack-fastapi-mongodb)

A production-ready full stack application template: the official [Full Stack FastAPI Template](https://github.com/fastapi/full-stack-fastapi-template) with **MongoDB** as the database instead of PostgreSQL.

## What's inside

- ⚡ [FastAPI](https://fastapi.tiangolo.com) backend (Python 3.14) with automatic interactive API docs at `/docs`
- 🍃 [PyMongo](https://www.mongodb.com/docs/languages/python/pymongo-driver/current/) talking to [MongoDB](https://www.mongodb.com): documents in `users` and `items` collections, a unique index on user email, and idempotent seeding of the first superuser at boot
- 🔑 JWT (OAuth2 password flow) authentication, argon2 password hashing with transparent bcrypt upgrade on login
- 🚀 [React](https://react.dev) + TypeScript frontend ([Vite](https://vitejs.dev), [Tailwind CSS](https://tailwindcss.com), [shadcn/ui](https://ui.shadcn.com)), built into the backend image and served by FastAPI on the same domain — no separate web host, no CORS setup
- ✉️ [React Email](https://react.email) templates for account and password-reset emails
- ✅ Full backend test suite ([Pytest](https://pytest.org), 58 tests) run in CI
- 🐋 One multi-stage `Dockerfile`: [Bun](https://bun.sh) builds the frontend, [uv](https://docs.astral.sh/uv/) manages the Python runtime

The backend exposes the same OpenAPI schema as the original template, so the generated type-safe frontend client works unchanged.

## After deploying

1. Open your generated Railway domain — the login page is served by FastAPI.
2. Sign in with the `FIRST_SUPERUSER` email and `FIRST_SUPERUSER_PASSWORD` you configured.
3. Explore the API at `/docs`.

# Deploy and Host

Deploy this template and you get two services on Railway:

- **Backend** — a Dockerized FastAPI application that serves both the REST API (under `/api/v1`) and the built React frontend from a single port. On every deploy it runs `backend/scripts/prestart.sh`, which creates the email unique index and seeds the first superuser if it does not exist yet, then serves with `fastapi run` on the port Railway provides. Railway health-checks the redirect-free `GET /health` endpoint, so the deployment only goes live once the app is actually serving.
- **MongoDB** — a Railway MongoDB database. The backend connects to it through the `MONGODB_URI` variable, which references the database's own connection string (`${{Mongo.MONGO_URL}}`), so credentials stay in sync automatically.

Set these variables on the backend service when deploying: `PROJECT_NAME`, `SECRET_KEY`, `FIRST_SUPERUSER`, `FIRST_SUPERUSER_PASSWORD` (generate `SECRET_KEY` and the password — the app refuses to boot with the default `changethis` values outside development), and `FRONTEND_HOST` set to `https://${{RAILWAY_PUBLIC_DOMAIN}}` so CORS allows the generated domain automatically.

## About Hosting

Hosting this stack on Railway means one web service plus one managed database. The frontend is built into the backend image, so there is nothing else to host: API and UI share one domain and one deployment. Deploys are atomic from Railway's point of view — the healthcheck on `/health` gates the switch to the new deployment, and database seeding is idempotent, so redeploys are safe against existing data. MongoDB runs as a Railway database service with automated backups available on Pro; the backend stores users (with hashed passwords) and items as documents and never needs schema migrations, which removes the Alembic migration step the original template requires on every deploy.

## Why Deploy

- **Zero-migration database workflow**: MongoDB is schemaless — the template creates indexes and seeds data at boot, so you never run migration commands when you change your models.
- **One service, one domain**: the React frontend is compiled into the FastAPI app, so you deploy a single container; no CDN, reverse proxy, or CORS configuration needed.
- **Everything included out of the box**: JWT auth with secure password hashing, user and item CRUD with role-based permissions, password recovery emails, and a type-safe frontend client generated from the OpenAPI schema.
- **CI-tested**: the same code you deploy is validated by the backend test suite on every push.

## Common Use Cases

- SaaS products and internal admin tools that need accounts, roles (superuser vs normal user), and CRUD dashboards out of the box.
- Rapid prototyping of API + SPA products when you want to iterate on data models without managing SQL migrations.
- Teams standardizing on MongoDB who still want the FastAPI development experience: typed Pydantic models, OpenAPI docs, and generated frontend clients.
- A starting point for FastAPI + MongoDB projects that keeps parity with the official full-stack-fastapi-template structure, so upstream improvements are easy to port.

## Dependencies for template

- **Railway MongoDB plugin** (`Mongo` service): provides the `MONGO_URL` variable referenced as `MONGODB_URI` by the backend. Provisioned automatically with the template.
- **Backend service variables**: `PROJECT_NAME`, `SECRET_KEY`, `FIRST_SUPERUSER`, `FIRST_SUPERUSER_PASSWORD`, `FRONTEND_HOST` (your generated Railway domain).
- **Docker**: the backend builds from the repo-root `Dockerfile` (frontend build stage + Python runtime stage). No other runtime dependencies are required.

## Similar templates

- [open-excalidraw](https://railway.com/deploy/open-excalidraw) — Self-hostable collaborative drawing built on Excalidraw
- [caring-vibrancy](https://railway.com/deploy/caring-vibrancy) — Deploy and Host caring-vibrancy with Railway
- [Appsmith](https://railway.com/deploy/appsmith-1) — Low-code platform for internal tools, dashboards, and admin panels.

Open this page in a browser: https://railway.com/deploy/full-stack-fastapi-1
