A production-ready multitenant SaaS application built with Next.js 16, featuring subdomain-based routing, organization management, and enterprise-grade authentication.
- ✅ Subdomain-Based Multitenancy - Each organization gets their own subdomain
- ✅ Clerk Authentication - Enterprise-grade auth with organization support
- ✅ Redis Caching - Fast tenant lookup and data caching
- ✅ Type-Safe Database - Drizzle ORM with PostgreSQL
- ✅ Admin Dashboard - Manage organizations and users
- ✅ Role-Based Access - Super-admin and organization-level permissions
- ✅ Clean Architecture - Maintainable and scalable codebase
| Document | Description |
|---|---|
| QUICKSTART.md | Get up and running in minutes |
| SETUP.md | Detailed setup instructions |
| CLERK_SETUP.md | Clerk configuration and metadata setup |
| PROJECT_STRUCTURE.md | Architecture and code organization |
| IMPLEMENTATION_SUMMARY.md | What's been built and how it works |
# 1. Install dependencies
npm install
# 2. Copy environment variables
cp .env.example .env.local
# Then fill in your Clerk, Neon, and Upstash credentials
# 3. Push database schema
npm run db:push
# 4. Start development server
npm run devThen:
- Sign up and set yourself as super-admin in Clerk Dashboard
- Visit
http://localhost:3000/adminto create organizations - Edit hosts file to test subdomains locally
See QUICKSTART.md for detailed instructions.
- Framework: Next.js 16 (App Router)
- Authentication: Clerk
- Database: Neon PostgreSQL
- ORM: Drizzle
- Caching: Upstash Redis
- UI: Radix UI + Tailwind CSS
- Language: TypeScript
Each organization automatically gets a subdomain:
acme.yourdomain.com → Acme Corp dashboard
Super-admins can:
- Create organizations with custom subdomains
- Add users to organizations
- Manage organization settings
Easily access tenant data in server components:
import { getCurrentTenant } from '@/lib/tenant-context';
export default async function MyPage() {
const tenant = await getCurrentTenant();
// Use tenant.id to filter data
}Required environment variables (see .env.example):
# Clerk
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=
CLERK_SECRET_KEY=
# Neon Database
DATABASE_URL=
# Upstash Redis
UPSTASH_REDIS_REST_URL=
UPSTASH_REDIS_REST_TOKEN=
# App Configuration
NEXT_PUBLIC_APP_DOMAIN=localhost:3000# Run development server
npm run dev
# Check types
npm run build
# Database operations
npm run db:push # Push schema changes
npm run db:generate # Generate migrations
npm run db:studio # Open Drizzle StudioSee SETUP.md for production deployment details.
Need help? Check out the QUICKSTART.md guide!