---
title: "Deploy Nextjs-Multitenant-Template"
description: "Multi-tenant SaaS starter for Next.js with Better Auth, Prisma and RBAC."
category: "Starters"
url: https://railway.com/deploy/nextjs-multitenant-template
---

# Deploy Nextjs-Multitenant-Template

Multi-tenant SaaS starter for Next.js with Better Auth, Prisma and RBAC.

**[Deploy Nextjs-Multitenant-Template on Railway](https://railway.com/template/nextjs-multitenant-template)**

Machine-readable deploy manifest (JSON, validated by TemplateCI): https://railway.com/deploy/nextjs-multitenant-template/manifest.json

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

## Template content

### Postgres https://devicons.railway.app/i/postgresql.svg

- **Image:** ghcr.io/railwayapp-templates/postgres-ssl:18

### Frontend-Multitenancy https://devicons.railway.app/nextj

- **Source:** https://github.com/laguillo/nextjs-multitenant
- **Health check:** /api/health
- **Public domain:** Yes

## Documentation

# Deploy and Host Nextjs-Multitenant-Template on Railway

Nextjs-Multitenant-Template is a production-ready multi-tenant SaaS starter built with Next.js. It ships with Better Auth for sign-in, Prisma with PostgreSQL for data, and shadcn/ui for the interface. Each organization gets its own space at `/tenant/[slug]` or its own subdomain, with role-based access (owner and member) and email invitations already in place.

## About Hosting Nextjs-Multitenant-Template

This template deploys the Next.js app and a PostgreSQL database as two services in one Railway project. The app connects to the database over Railway's private network, and `DATABASE_URL` is wired to the bundled Postgres service automatically. After the first deploy, run `bunx prisma migrate deploy` once to create the schema. Then add the environment variables that Railway asks for: `RESEND_API_KEY` for transactional email, and optionally `GOOGLE_CLIENT_ID` and `GOOGLE_CLIENT_SECRET` for Google sign-in. `BETTER_AUTH_SECRET` is generated for you. The app uses your Railway public domain by default, so you can deploy without a custom domain. Add a custom domain later if you want tenant subdomains such as `acme.yourdomain.com`.

## Common Use Cases

- B2B SaaS products where each customer company needs its own workspace, members, and roles
- Internal tools for teams or agencies that manage several client organizations from one app
- Starting point for a multi-tenant app that needs authentication, invitations, and an admin area from day one

## Dependencies for Nextjs-Multitenant-Template Hosting

- PostgreSQL (provisioned automatically by the template)
- A Resend account with a verified sending domain, for transactional emails
- Optional: a Google OAuth client, for "Sign in with Google"

### Implementation Details 

The app has two routing modes. Platform routes (landing, sign-up, dashboard, and admin) live at the root domain. Tenant routes live under `/tenant/[slug]` and, when a custom domain is configured, under subdomains. Authentication is handled by Better Auth at `src/lib/auth.ts`, and organization membership and roles are enforced in the tenant layout. The database schema covers users, sessions, accounts, organizations, members, and invitations.

## Why Deploy Nextjs-Multitenant-Template 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 Nextjs-Multitenant-Template 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

- [Openfront Gym](https://railway.com/deploy/openfront-gym) — Opensource Mindbody alternative based on Next.js and Keystone.js
- [open-excalidraw](https://railway.com/deploy/open-excalidraw) — Self-hostable collaborative drawing built on Excalidraw
- [Next.js + Prisma + PostgreSQL Starter](https://railway.com/deploy/nextjs-prisma-postgres) — Deploy a Next.js app with Prisma ORM and PostgreSQL in one click.

Open this page in a browser: https://railway.com/deploy/nextjs-multitenant-template
