Skip to content

Production-ready multi-tenant SaaS boilerplate with NestJS GraphQL, real-time chat, Stripe billing, and team collaboration features.

Notifications You must be signed in to change notification settings

saadamir1/chatflow-saas

Repository files navigation

ChatFlow - Complete SaaS Foundation

A production-ready SaaS foundation built with NestJS GraphQL, real-time WebSocket technology, and Stripe billing integration.

ChatFlow is a complete multi-tenant SaaS platform that provides team collaboration features with enterprise-grade billing, authentication, and real-time communication. Perfect foundation for any SaaS product.

πŸš€ Complete SaaS Features

πŸ—οΈ Core Foundation

  • 🏒 Multi-Tenant Architecture - Complete workspace isolation with tenant-scoped data
  • πŸ” Enterprise Authentication - JWT + refresh tokens, email verification, password reset
  • πŸ’³ Stripe Billing Integration - Subscriptions, payments, usage tracking, webhooks
  • πŸ“Š Usage Limits Enforcement - FREE/PRO/ENTERPRISE plan limits with real-time tracking
  • 🎯 Plan Management - Automatic upgrades, downgrades, and billing cycle management

πŸ’¬ Team Collaboration

  • πŸ’¬ Real-Time Chat System - Socket.IO + GraphQL subscriptions for instant messaging
  • πŸ‘₯ Team Invitations - Email-based invitations with workspace onboarding
  • πŸ”” Smart Notifications - Real-time alerts and activity tracking
  • πŸ“ File Management - Cloudinary integration for secure file uploads and sharing
  • πŸ“ˆ Analytics Dashboard - User growth, activity metrics, and engagement tracking

πŸ”§ Developer Experience

  • πŸ“± GraphQL API - Type-safe API with auto-generated schema
  • πŸ—ƒοΈ Database Migrations - TypeORM with proper schema versioning
  • πŸŽ›οΈ Development Mode - Mock Stripe responses for testing without payment setup
  • πŸ” Comprehensive Logging - Audit trails and error tracking
  • πŸ›‘οΈ Security Best Practices - Rate limiting, input validation, SQL injection protection

πŸ› οΈ Complete Tech Stack

Backend Foundation

  • Framework: NestJS with TypeScript
  • API: GraphQL with Apollo Server
  • Database: PostgreSQL with TypeORM
  • Authentication: JWT + Refresh Tokens
  • Real-time: Socket.IO + GraphQL Subscriptions

SaaS Infrastructure

  • Billing: Stripe API integration
  • Payments: Payment intents, subscriptions, webhooks
  • Usage Tracking: Plan limits and feature enforcement
  • File Storage: Cloudinary for media management
  • Email: Nodemailer for transactional emails

Production Ready

  • Multi-tenancy: Complete workspace isolation
  • Migrations: Database schema versioning
  • Security: Rate limiting, validation, audit logs
  • Monitoring: Comprehensive error handling and logging

πŸš€ Quick Start

1. Clone & Install

git clone https://github.com/saadamir1/chatflow-saas.git
cd chatflow-saas
npm install

2. Database Setup

CREATE USER dev WITH PASSWORD 'secret';
CREATE DATABASE demo OWNER dev;
GRANT ALL PRIVILEGES ON DATABASE demo TO dev;

3. Environment Variables

# Database
DB_HOST=127.0.0.1
DB_PORT=5432
DB_USERNAME=dev
DB_PASSWORD=secret
DB_NAME=demo

# JWT
JWT_SECRET=your-jwt-secret-key
JWT_EXPIRES_IN=900s
JWT_REFRESH_SECRET=your-refresh-secret
JWT_REFRESH_EXPIRES_IN=7d

# Email Configuration
EMAIL_USER=[email protected]
EMAIL_PASS=your-gmail-app-password
FRONTEND_URL=http://localhost:3001

# Cloudinary (for file uploads)
CLOUDINARY_CLOUD_NAME=your_cloud_name
CLOUDINARY_API_KEY=your_api_key
CLOUDINARY_API_SECRET=your_api_secret

4. Run Migrations & Start

# Run database migrations
npm run migration:run

# Start development server
npm run start:dev

Access ChatFlow:

  • GraphQL Playground: http://localhost:3000/graphql
  • API Endpoint: http://localhost:3000/graphql
  • Stripe Webhooks: http://localhost:3000/webhooks/stripe

5. Optional: Stripe Setup (for billing)

# Add to .env for production billing
STRIPE_SECRET_KEY=sk_test_your_stripe_secret_key
STRIPE_PUBLISHABLE_KEY=pk_test_your_stripe_publishable_key
STRIPE_WEBHOOK_SECRET=whsec_your_webhook_secret
STRIPE_PRO_PRICE_ID=price_your_pro_plan_id
STRIPE_ENTERPRISE_PRICE_ID=price_your_enterprise_plan_id

Note: Billing works in development mode without Stripe keys (uses mock responses).

πŸ“± Complete API Examples

Authentication & Workspace

# Register new user
mutation {
  register(registerInput: {
    email: "[email protected]"
    password: "securePassword123"
    firstName: "John"
    lastName: "Doe"
  }) {
    access_token
    refresh_token
    user { id email }
  }
}

# Create workspace
mutation {
  createWorkspace(createWorkspaceInput: {
    name: "Acme Corp"
    description: "Main workspace for Acme Corporation"
  }) {
    id name slug
    subscription { planType status }
  }
}

Billing & Subscriptions

# Create subscription
mutation {
  createSubscription(createSubscriptionInput: {
    planType: PRO
    paymentMethodId: "pm_card_visa"
  }) {
    subscriptionId
    status
    clientSecret
  }
}

# Get billing info
query {
  myBillingSubscription {
    planType
    status
    amount
    currentPeriodEnd
  }
}

# Create payment
mutation {
  createPaymentIntent(createPaymentIntentInput: {
    amount: 10.00
    description: "One-time payment"
  }) {
    clientSecret
    paymentIntentId
  }
}

Team Collaboration

# Invite team member
mutation {
  inviteUser(inviteUserInput: {
    email: "[email protected]"
    message: "Join our team!"
  }) {
    message
    success
  }
}

# Real-time chat
mutation {
  sendMessage(sendMessageInput: {
    content: "Hello team!"
    roomId: 1
  }) {
    id content createdAt
    sender { firstName lastName }
  }
}

# Subscribe to messages
subscription {
  messageAdded {
    id content senderId roomId createdAt
  }
}

πŸ’° Built-in SaaS Pricing Model

Plan Limits (Configurable)

  • FREE: 5 users, 1,000 messages/month, 1GB storage, 3 rooms
  • PRO: 50 users, 50,000 messages/month, 10GB storage, 50 rooms
  • ENTERPRISE: Unlimited users, unlimited messages, 100GB storage, unlimited rooms

Billing Features

  • βœ… Stripe Integration - Automatic payment processing
  • βœ… Usage Tracking - Real-time feature usage monitoring
  • βœ… Plan Enforcement - Automatic limit blocking when exceeded
  • βœ… Webhook Handling - Real-time payment status updates
  • βœ… Subscription Management - Upgrades, downgrades, cancellations
  • βœ… Invoice Generation - Automatic billing cycle management

πŸ—οΈ Complete SaaS Architecture

ChatFlow SaaS Foundation
β”œβ”€β”€ 🏒 Multi-Tenant Core
β”‚   β”œβ”€β”€ Workspace isolation
β”‚   β”œβ”€β”€ User management
β”‚   └── Role-based access
β”œβ”€β”€ πŸ’³ Billing System
β”‚   β”œβ”€β”€ Stripe integration
β”‚   β”œβ”€β”€ Usage tracking
β”‚   β”œβ”€β”€ Plan enforcement
β”‚   └── Webhook handling
β”œβ”€β”€ πŸ’¬ Real-Time Features
β”‚   β”œβ”€β”€ Socket.IO messaging
β”‚   β”œβ”€β”€ GraphQL subscriptions
β”‚   β”œβ”€β”€ Live notifications
β”‚   └── Presence tracking
β”œβ”€β”€ πŸ” Security Layer
β”‚   β”œβ”€β”€ JWT authentication
β”‚   β”œβ”€β”€ Rate limiting
β”‚   β”œβ”€β”€ Input validation
β”‚   └── Audit logging
└── πŸ“Š Analytics & Monitoring
    β”œβ”€β”€ User growth tracking
    β”œβ”€β”€ Feature usage metrics
    β”œβ”€β”€ Billing analytics
    └── Performance monitoring

🎯 SaaS Foundation Benefits

For Developers

  • ⚑ Rapid Development - Skip months of boilerplate setup
  • πŸ”§ Production Ready - Enterprise-grade architecture from day one
  • πŸ“š Well Documented - Comprehensive API documentation and examples
  • πŸ§ͺ Testing Friendly - Mock services for development without external dependencies

For Businesses

  • πŸ’° Revenue Ready - Complete billing system with Stripe integration
  • πŸ“ˆ Scalable - Multi-tenant architecture supports unlimited workspaces
  • πŸ›‘οΈ Secure - Enterprise security practices built-in
  • πŸš€ Fast Time-to-Market - Focus on your unique features, not infrastructure

🏷️ Version Tags

  • v1.0.0-saas-foundation - Complete SaaS foundation (use this for new projects)
  • master - ChatFlow-specific features and frontend integration

πŸš€ Using as SaaS Foundation

For New SaaS Projects

# Clone the foundation
git clone https://github.com/saadamir1/chatflow-saas.git my-saas-app
cd my-saas-app

# Checkout the foundation tag
git checkout v1.0.0-saas-foundation

# Create your new branch
git checkout -b my-product-features

# Install and setup
npm install
cp .env.example .env
# Configure your database and services

# Start building your unique features!

What You Get Out of the Box

  • βœ… Complete user authentication system
  • βœ… Multi-tenant workspace architecture
  • βœ… Stripe billing integration
  • βœ… Real-time communication infrastructure
  • βœ… File upload and management
  • βœ… Team invitation system
  • βœ… Analytics and usage tracking
  • βœ… Production-ready database schema
  • βœ… GraphQL API with comprehensive resolvers
  • βœ… Security best practices implemented

🀝 Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'feat: add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


🎯 Built as a complete SaaS foundation - ready for your next big idea!

⭐ Star this repo if it helps you build your SaaS faster!

About

Production-ready multi-tenant SaaS boilerplate with NestJS GraphQL, real-time chat, Stripe billing, and team collaboration features.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages