---
title: "Deploy Complete Supabase + NextJS"
description: "\"PG On Rails\" | Self-hosted Supabase. Amazing developer experience."
category: "Starters"
url: https://railway.com/deploy/complete-supabase-nextjs-frontend
---

# Deploy Complete Supabase + NextJS

"PG On Rails" | Self-hosted Supabase. Amazing developer experience.

**[Deploy Complete Supabase + NextJS on Railway](https://railway.com/template/complete-supabase-nextjs-frontend)**

- **Creator:** Ben Isenstein
- **Category:** Starters
- **Total deploys:** 182

## Template content

### PostgREST https://docs.postgrest.org/en/v13/_static/favicon.ico

- **Source:** https://github.com/BenIsenstein/pgonrails

### Edge Functions https://supabase.com/favicon/favicon-196x196.png

- **Source:** https://github.com/BenIsenstein/pgonrails

### Supabase Storage https://supabase.com/favicon/favicon-196x196.png

- **Source:** https://github.com/BenIsenstein/pgonrails

### Postgres https://devicons.railway.app/postgres

- **Source:** https://github.com/BenIsenstein/pgonrails

### PgBouncer https://devicons.railway.app/postgres

- **Source:** https://github.com/BenIsenstein/pgonrails

### Kong https://github.com/Kong.png

- **Source:** https://github.com/BenIsenstein/pgonrails
- **Public domain:** Yes

### imgproxy https://docs.imgproxy.net/img/icon.svg

- **Source:** https://github.com/BenIsenstein/pgonrails

### Site https://tanstack.com/favicon.ico

- **Source:** https://github.com/BenIsenstein/pgonrails
- **Public domain:** Yes

### Supabase Realtime https://supabase.com/favicon/favicon-196x196.png

- **Source:** https://github.com/BenIsenstein/pgonrails

### Postgres Meta https://supabase.com/favicon/favicon-196x196.png

- **Source:** https://github.com/BenIsenstein/pgonrails

### Supabase Auth https://supabase.com/favicon/favicon-196x196.png

- **Source:** https://github.com/BenIsenstein/pgonrails

### MinIO https://cdn.prod.website-files.com/681c8426519d8db8f867c1e8/681c8426519d8db8f867c1f2_favicon-32x32.png

- **Source:** https://github.com/BenIsenstein/pgonrails
- **Public domain:** Yes

### Supabase Studio https://supabase.com/favicon/favicon-196x196.png

- **Source:** https://github.com/BenIsenstein/pgonrails

## Documentation

# Deploy and Host Complete Supabase + TanStack Start on Railway

PG On Rails is a passion project that combines two of my favourite things: Supabase and Railway! It is **local-first** and is a joy to build Supabase applications with. It is a monorepo with one directory per service, and is designed for the modern deployment pattern of **watch paths.**

My longterm vision is to make PG On Rails *the best strategy for bootstrapping, building and self-hosting Supabase.*

## About Hosting PG On Rails

Please visit the official [GitHub repo](https://github.com/BenIsenstein/pgonrails) to view GIFs of the deployment process.

You can now deploy and setup PG On Rails completely **hands-free**! With a single shell command, accomplish every step from the manual setup in minutes without lifting a finger. Simply run the following command on a Linux, MacOS or WSL terminal:

bash &lt;(curl -fsSL https://raw.githubusercontent.com/BenIsenstein/pgonrails-cli/main/start.sh)

For the manual tutorial, continue reading!

To deploy this template, only 3 environment variables need to be configured. Please visit the Supabase self-hosting tool to generate a JWT secret and keys, and input them when prompted into the `Postgres` service.

You can use your deployment as a remote backend only, or you can practice truly local-first development by running your project on your machine. To do this, you'll need to eject the project and clone your newly forked GitHub repo.

Whether remote or local, you'll be able to use the Supabase Studio dashboard right away, by copying the `DASHBOARD_PASSWORD` variable from the Kong service. Visit the public url for Kong, and log in with user `pgonrails` and the password.

## Common Use Cases

- Postgres database with instant APIs
- Auth, Edge Functions, Websockets
- S3-compatible storage, Vector embeddings
- Startups, Scale-ups, SaaS

## Dependencies for Complete Supabase + TanStack Start Frontend Hosting

- <a rel="noopener noreferrer" href="https://docs.docker.com/desktop/">Docker Desktop</a>
- <a rel="noopener noreferrer" href="https://supabase.com/docs/guides/local-development/cli/getting-started">Supabase CLI</a>

### Deployment Dependencies

In order to deploy this template smoothly, you must create a JWT secret and keys using the Supabase online self-hosting tool. The link to it is provided directly in the environment configuration UI.

### Implementation Details 

#### Sane and simple defaults

Get working on real application features in seconds. We go the extra mile to make default configuration minimal while still covering everything needed to run out-of-the-box. Avoid drowning in config, and opt in to more hackability as needed.

#### Add your app logic, deploy seamlessly

Every service gets its own directory, so watchpaths just work. Add new functions, configuration files, migrations, and anything else to a service's repo, commit your work, and Railway (or your CI/CD of choice) will trigger a new build.

#### Your frontend, included in the stack

Reduce context-switching and host as much of your stack as possible on the same platform. For Tanstack Start, Django, htmx or any server-rendered frontend, get fast and secure access to Supabase data APIs via the shared internal network.

#### Full control over your application

For the hackers. Configure every aspect of your Supabase application and version it in code:
- Email templates
- Third-party auth providers
- Environment variables
- Networking settings
- Railway config-as-code

#### Railway observability instead of Logflare

The entire Supabase feature set for building applications has been extensively tested and proven via the included TanStack Start app, "Trello Clone". At this time, it doesn't include a Logflare analytics service, and opts to use Railway's platform observability instead.

### Frontend included with seamless dev mode

We included a frontend app in the stack and named it `site`. The frontend site is a TanStack app built with `Tanstack Start`, `tailwindCSS` and `shadcn/ui`. It includes basic auth functionality so you can begin building user experiences out of the box.

#### Separate Dockerfiles for development and deployment

The project is setup so that running the Docker Compose stack locally **runs the site in dev mode**. The local dev experience points to a `dev.Dockerfile` in the `site` repo. This dockerfile runs the vite dev server. For production, however, Railway looks for a `Dockerfile` by default (no `dev` prefix), and will deploy using the `Dockerfile` which builds and serves the optimized site.

The other strategy which enables smooth local development inside Docker, is mounting the entire `site` directory as a volume inside the dev container (`volumes: - ./site:/app`). This exposes the codebase from your local filesystem inside the container, where the dev server can pick up any changes and deliver that hot-reload experience we all love.

### Choose your DB migrations story

By default, the `Site` service runs its DB migrations on startup:

`ENTRYPOINT supabase db push ... &amp;&amp; node server.js`

This way, the example web app is usable from the moment you deploy. It is easy to move this process into a GitHub action however - there is one already included in the repo for you! Simply add a `DB_URL` secret to your forked repo and it will run when you add migration files to `/site/supabase/migrations`.

### No mail server yet, no problem

By default, mailing is disabled. Once a user signs up with their email and password, their email is "auto-confirmed" by the auth server and they are signed in.

### Setup mailing fast

The auth server requires an SMTP server to send transactional emails. In my experience, the quickest way to get up and running in both **local** and **non-production cloud** environments, is through a gmail account with an app password.

Log in to the Google account you want all transactional emails to come from. Visit the following link to [create a Google app password.](https://myaccount.google.com/u/4/apppasswords)

Make sure the email signup and SMTP environment variables are set:

`GOTRUE_MAILER_AUTOCONFIRM=false`
`GOTRUE_SMTP_ADMIN_EMAIL=johndoe@gmail.com`
`GOTRUE_SMTP_USER=myapp@gmail.com`
`GOTRUE_SMTP_PASS="abcd efgh ijkl mnop"`
`GOTRUE_SMTP_HOST=smtp.gmail.com`
`GOTRUE_SMTP_PORT=587`
`GOTRUE_SMTP_SENDER_NAME: "PG On Rails"`

**NOTE** - SMTP traffic on Railway is only allowed for the Pro Plan and above.

## Why Deploy PG On Rails on Railway?


Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying PG On Rails on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.


## Similar templates

- [Paperless-ngx](https://railway.com/deploy/paperless-ngx-3) — Document management with OCR on Railway with PostgreSQL and Redis
- [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

Open this page in a browser: https://railway.com/deploy/complete-supabase-nextjs-frontend
