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.
- π’ 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
- π¬ 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
- π± 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
- Framework: NestJS with TypeScript
- API: GraphQL with Apollo Server
- Database: PostgreSQL with TypeORM
- Authentication: JWT + Refresh Tokens
- Real-time: Socket.IO + GraphQL Subscriptions
- 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
- Multi-tenancy: Complete workspace isolation
- Migrations: Database schema versioning
- Security: Rate limiting, validation, audit logs
- Monitoring: Comprehensive error handling and logging
git clone https://github.com/saadamir1/chatflow-saas.git
cd chatflow-saas
npm installCREATE USER dev WITH PASSWORD 'secret';
CREATE DATABASE demo OWNER dev;
GRANT ALL PRIVILEGES ON DATABASE demo TO dev;# 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# Run database migrations
npm run migration:run
# Start development server
npm run start:devAccess ChatFlow:
- GraphQL Playground:
http://localhost:3000/graphql - API Endpoint:
http://localhost:3000/graphql - Stripe Webhooks:
http://localhost:3000/webhooks/stripe
# 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_idNote: Billing works in development mode without Stripe keys (uses mock responses).
# 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 }
}
}# 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
}
}# 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
}
}- 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
- β 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
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
- β‘ 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
- π° 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
- v1.0.0-saas-foundation - Complete SaaS foundation (use this for new projects)
- master - ChatFlow-specific features and frontend integration
# 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!- β 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
- Fork the repository
- Create feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'feat: add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open Pull Request
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!