Skip to content

About

A production-ready SaaS starter kit built with Next.js and Postrust (PostgREST in Rust). All business logic lives in PostgreSQL with Row Level Security (RLS) for authorization.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Postrust SaaS Starter

A production-ready SaaS starter kit built with Next.js and Postrust (PostgREST in Rust). All business logic lives in PostgreSQL with Row Level Security (RLS) for authorization.

Features

  • Authentication: Magic link (email) + OAuth (Google, GitHub) via NextAuth.js
  • Team Management: Create teams, invite members, manage roles
  • Billing: Stripe + LemonSqueezy integration ready
  • Projects: Demo feature showing team-scoped resources
  • API Keys: Generate and manage API keys
  • Audit Logs: Track all team actions
  • Row Level Security: Secure data access at the database level

Tech Stack

Layer Technology
Frontend Next.js 14, React 18, TypeScript
Styling Tailwind CSS, shadcn/ui
Auth NextAuth.js v5
API Postrust (PostgREST in Rust)
Database PostgreSQL 16+
Payments Stripe
Monorepo Turborepo

Getting Started

Prerequisites

  • Node.js 18+
  • Docker & Docker Compose
  • pnpm (recommended)

Installation

  1. Clone the repository:
git clone https://github.com/your-username/postrust-saas-starter.git
cd postrust-saas-starter
  1. Install dependencies:
pnpm install
  1. Copy the environment file:
cp .env.example .env
  1. Start the development stack:
docker-compose up -d
  1. Run database migrations:
# Connect to postgres and run migrations
docker exec -i postgres psql -U postgres -d saas_starter < packages/database/migrations/001_initial_schema.sql
docker exec -i postgres psql -U postgres -d saas_starter < packages/database/migrations/002_rls_policies.sql
docker exec -i postgres psql -U postgres -d saas_starter < packages/database/migrations/003_functions.sql
docker exec -i postgres psql -U postgres -d saas_starter < packages/database/migrations/004_seed_plans.sql
  1. Start the development server:
pnpm dev

Open http://localhost:3000 to see the app.

Project Structure

postrust-saas-starter/
├── apps/
│   └── web/                    # Next.js application
│       ├── app/
│       │   ├── (auth)/         # Auth pages (login, register)
│       │   ├── (dashboard)/    # Protected dashboard
│       │   ├── (marketing)/    # Public pages
│       │   └── api/            # API routes
│       ├── components/
│       │   └── ui/             # shadcn/ui components
│       └── lib/
│           ├── api.ts          # Postrust API client
│           ├── auth.ts         # NextAuth config
│           └── utils.ts        # Utilities
├── packages/
│   └── database/
│       └── migrations/         # SQL migrations
├── docker/
│   └── docker-compose.yml      # Local dev stack
└── package.json

Environment Variables

See .env.example for all required environment variables:

  • POSTRUST_URL - Postrust API URL
  • POSTRUST_JWT_SECRET - JWT secret for API authentication
  • NEXTAUTH_SECRET - NextAuth.js secret
  • OAuth credentials (Google, GitHub)
  • Stripe/LemonSqueezy API keys

Database Schema

The database uses PostgreSQL with the following core tables:

  • users - User accounts (synced from NextAuth)
  • teams - Team/organization entities
  • team_members - Team membership with roles
  • invitations - Pending team invitations
  • subscriptions - Billing subscriptions
  • plans - Subscription plans
  • projects - Demo team-scoped resource
  • api_keys - API key management
  • audit_logs - Action tracking

All tables are protected with Row Level Security (RLS) policies.

Authentication Flow

  1. User signs in via OAuth or magic link
  2. NextAuth creates/updates user in database via Postrust
  3. JWT token is generated with user_id claim
  4. All Postrust requests include JWT for authorization
  5. RLS policies filter data based on auth.uid()

Deployment

Vercel + Railway (Recommended)

  1. Deploy Next.js to Vercel
  2. Deploy Postrust + PostgreSQL to Railway
  3. Configure environment variables

Docker (Self-hosted)

docker-compose -f docker-compose.prod.yml up -d

License

MIT

About

A production-ready SaaS starter kit built with Next.js and Postrust (PostgREST in Rust). All business logic lives in PostgreSQL with Row Level Security (RLS) for authorization.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages