A modern, scalable multi-tenant application built with Next.js 15+, Prisma, and PostgreSQL. Featuring robust authentication, basic tenant isolation, and a sleek UI.
- 🏢 Multi-Tenancy: Full tenant isolation with slug-based routing (
/tenant-name/dashboard). - 🔐 Advanced Authentication:
- Secure Email/Password Login.
- Google OAuth 2.0: Integrated with strict tenant resolution.
- Magic Links: Passwordless login via email.
- Role-Based Access Control (RBAC): Tenant ownership and membership rules.
- JWT Sessions: Secure, HTTP-only cookie-based session management with Refresh Tokens.
- 📧 Email System: Transactional emails powered by Resend and React Email.
- ⚡ Real-time & Caching: Redis integration for high-performance data caching and OTP storage.
- 🎨 Modern UI: Built with Tailwind CSS v4 and Radix UI primitives for accessibility and design.
- 🛡️ Type Safety: End-to-end type safety with TypeScript and Zod.
- Framework: Next.js App Router (React 19)
- Database: PostgreSQL & Prisma ORM
- State Management: TanStack Query v5
- Authentication: Custom JWT & OAuth
- Styling: Tailwind CSS 4 & Lucide Icons
- Forms: React Hook Form & Zod
- Infrastructure: Docker Compose (Postgres, Redis)
- Node.js 20+
- Docker (for local database & redis)
-
Clone the repository:
git clone https://github.com/your-username/multi-tenant-saas.git cd multi-tenant-saas -
Install dependencies:
npm install
-
Start Services (DB & Redis):
docker-compose up -d
-
Configure Environment Variables: Create a
.envfile in the root directory:DATABASE_URL="postgresql://postgres:postgres@localhost:5432/saas_dev" REDIS_URL="redis://localhost:6379" # Auth Secrets JWT_ACCESS_SECRET="your-access-secret" JWT_REFRESH_SECRET="your-refresh-secret" # Google OAuth GOOGLE_CLIENT_ID="your-google-client-id" GOOGLE_CLIENT_SECRET="your-google-client-secret" # App Config NEXT_PUBLIC_APP_URL="http://localhost:3000" # Email (Resend) RESEND_API_KEY="re_..."
-
Run Migrations:
npx prisma migrate dev
-
Start Development Server:
npm run dev
Visit http://localhost:3000 to begin.
app/[tenant]: Tenant-scoped routes and layouts.app/api/auth: Global authentication endpoints (OAuth callbacks).lib/: Shared utilities (Prisma client, Auth helpers, Redis).components/: Reusable UI components (Auth forms, Buttons).prisma/: Database schema and migrations.
Contributions are welcome! Please feel free to submit a Pull Request.