Skip to content

mahmoudazaid/saas-framework

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

2 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

SaaS Framework - Multi-Tenant SaaS Application Platform

A comprehensive, production-ready framework for building scalable multi-tenant SaaS applications with Flutter frontend and NestJS backend.

πŸ—οΈ Architecture Overview

This is a monorepo containing:

  • Backend: NestJS + Fastify + TypeORM + PostgreSQL
  • Frontend: Flutter + Dart (mobile + web)
  • Database: PostgreSQL with multi-tenancy support
  • Containerization: Docker for development and production

πŸš€ Quick Start

Prerequisites

  • Node.js 18+ and npm 8+
  • Flutter 3.0+
  • Docker and Docker Compose
  • PostgreSQL 14+

Setup

# Clone and setup
git clone <repository-url>
cd saas-framework

# Install dependencies
npm run setup

# Start database only
npm run start:db

# Start full development stack (database + backend)
npm run start:dev

# Start development servers
npm run dev

🎯 Customize for Your Project

# Run the complete setup and customization script
./setup.sh

# Or follow the detailed guide
# See: docs/development/project-customization-checklist.md

🐳 Docker Usage

Database Only (Production/Staging)

# Start PostgreSQL + pgAdmin
npm run start:db

# Stop services
npm run stop:db

# Reset database (removes all data)
npm run reset:db

Full Development Stack

# Start database + backend (with hot reload)
npm run start:dev

# Stop all services
npm run stop:dev

# View logs
docker-compose -f docker/docker-compose.yml logs -f backend

Manual Docker Commands

# Database only
docker-compose -f docker/docker-compose.yml up -d

# Full development stack
docker-compose -f docker/docker-compose.yml --profile development up -d

Available Services

  • PostgreSQL: localhost:5432 (database: saas_framework)
  • pgAdmin: localhost:5050 (admin@saasframework.com / admin)
  • Backend API: localhost:3000 (development profile only)

πŸ“š Documentation

πŸ—οΈ Architecture

πŸ”§ Development

πŸ—„οΈ Database

πŸ“– API Documentation

πŸ”§ Backend-Specific Documentation

πŸ“± Frontend-Specific Documentation

πŸ› οΈ Available Scripts

Development

npm run dev              # Start both backend and frontend
npm run dev:backend      # Start backend only
npm run dev:frontend     # Start frontend only

Building

npm run build            # Build both backend and frontend
npm run build:backend    # Build backend only
npm run build:frontend   # Build frontend only

Testing

npm run test:backend     # Run backend tests
npm run test:frontend    # Run frontend tests

Database

npm run start:db         # Start PostgreSQL database
npm run stop:db          # Stop database
npm run reset:db         # Reset database (removes all data)

Documentation

npm run docs:build       # Build all shared documentation
npm run docs:serve       # Serve shared documentation locally
npm run docs:architecture # View architecture documentation
npm run docs:development # View development documentation
npm run docs:api         # View API documentation

Utilities

npm run lint:backend     # Lint backend code
npm run clean            # Clean all build artifacts
npm run setup            # Initial project setup

Code Quality Checkers

# Framework compliance checkers
npm run check:framework:backend     # Check backend framework compliance
npm run check:framework:frontend    # Check Flutter framework compliance
npm run check:framework:watch       # Watch backend for changes
npm run check:framework:frontend:watch # Watch frontend for changes
npm run check:all                   # Run all framework checkers

# Hardcoded content checkers
npm run check:hardcoded:frontend    # Check for hardcoded text/styling
npm run check:hardcoded:frontend:watch # Watch for hardcoded violations

πŸ” Code Quality Checkers

This project includes automated checkers to maintain code quality and enforce design patterns.

Framework Compliance Checkers

Backend Framework Checker

# Check backend code for framework compliance
npm run check:framework:backend

# Watch mode - automatically check on file changes
npm run check:framework:watch

# Check specific path
npm run check:framework:backend -- apps/backend/src/modules/user

What it checks:

  • Clean Architecture violations
  • Generic terminology usage
  • Multi-tenancy patterns
  • Error handling compliance
  • Type safety issues

Frontend Framework Checker

# Check Flutter code for framework compliance
npm run check:framework:frontend

# Watch mode - automatically check on file changes
npm run check:framework:frontend:watch

# Check specific path
npm run check:framework:frontend -- apps/frontend/lib/features/home

What it checks:

  • Clean Architecture patterns
  • State management compliance
  • Error handling with FrameworkException
  • Multi-tenancy implementation
  • Accessibility compliance

Hardcoded Content Checker

Flutter Hardcoded Violations Checker

# Check for hardcoded text and styling
npm run check:hardcoded:frontend

# Watch mode - automatically check on file changes
npm run check:hardcoded:frontend:watch

# Check specific path
npm run check:hardcoded:frontend -- apps/frontend/lib/features/home

What it checks:

  • Hardcoded user-facing text (should be in ARB files)
  • Hardcoded colors (should use theme colors)
  • Hardcoded sizes (should use AppStyles constants)
  • Missing localization imports
  • Direct styling instead of theme-based styling

Checker Output

All checkers provide detailed output with:

  • File locations and line numbers
  • Violation types (ERROR, WARNING, INFO)
  • Specific suggestions for fixes
  • Code snippets showing the issue
  • Summary statistics (total violations, warnings, etc.)

Integration with Development

The checkers are designed to be run:

  • During development - Use watch mode for real-time feedback
  • Before commits - Run all checkers to ensure compliance
  • In CI/CD - Automated checking in GitHub Actions
  • Code reviews - Verify compliance before merging

🎯 Key Features

βœ… SaaS Framework

  • Reusable: Works for any SaaS business domain
  • Multi-tenant: Built-in tenant isolation and management
  • Scalable: Clean Architecture patterns for enterprise growth
  • Type-safe: Strict TypeScript throughout
  • Production-ready: Comprehensive error handling and monitoring

βœ… Backend Features

  • Clean Architecture: Domain, Application, Infrastructure, Presentation
  • Multi-tenancy: Generic tenant management
  • Event-driven: Domain events and event bus
  • Comprehensive Logging: Structured logging with context
  • API Validation: DTO validation with class-validator
  • Error Handling: Global exception filters
  • Testing: Unit and integration test framework

βœ… Frontend Features

  • Cross-platform: Mobile and web support
  • State Management: Provider/Riverpod patterns
  • Responsive Design: Material Design 3
  • Generic Components: Reusable UI components
  • Loading System: Smooth transitions with localization support
  • API Integration: Type-safe API client

🏒 Multi-tenancy

This framework is designed for SaaS applications:

  • Tenant Isolation: Complete data separation by tenant
  • Scalable Multi-tenancy: Support for unlimited SaaS customers
  • Secure: Proper tenant context validation and access control
  • Subscription-ready: Built for SaaS billing and subscription models

πŸ”§ Technology Stack

Backend

  • Framework: NestJS with Fastify
  • Language: TypeScript (strict mode)
  • Database: PostgreSQL with TypeORM
  • Validation: class-validator + class-transformer
  • Testing: Jest + Testcontainers
  • Logging: Custom LoggerService

Frontend

  • Framework: Flutter
  • Language: Dart
  • State Management: Provider/Riverpod
  • UI: Material Design 3
  • Testing: Flutter Test

DevOps

  • Containerization: Docker + Docker Compose
  • Database: PostgreSQL
  • CI/CD: GitHub Actions (planned)

πŸ“ Project Structure

saas-framework/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ backend/                 # NestJS API
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ core/           # Domain layer
β”‚   β”‚   β”‚   β”œβ”€β”€ application/    # Application layer
β”‚   β”‚   β”‚   β”œβ”€β”€ infrastructure/ # Infrastructure layer
β”‚   β”‚   β”‚   β”œβ”€β”€ presentation/   # Presentation layer
β”‚   β”‚   β”‚   └── common/         # Shared utilities
β”‚   β”‚   β”œβ”€β”€ test/               # Backend tests
β”‚   β”‚   └── .cursorrules        # Backend development rules
β”‚   └── frontend/               # Flutter app
β”‚       β”œβ”€β”€ lib/
β”‚       β”œβ”€β”€ test/
β”‚       └── .cursorrules        # Frontend development rules
β”œβ”€β”€ docs/                       # Documentation
β”œβ”€β”€ docker/                     # Docker configuration
β”‚   β”œβ”€β”€ docker-compose.yml     # Docker services
β”‚   └── Dockerfile.backend     # Backend container
β”œβ”€β”€ package.json                # Root package.json
└── .cursorrules               # Project-wide rules

🀝 Contributing

  1. Read the Contributing Guidelines
  2. Follow the Backend Development Rules
  3. Follow the Frontend Development Rules
  4. Write tests for new features
  5. Update documentation as needed

πŸ“„ License

MIT License - see LICENSE file for details.

πŸ†˜ Support

  • Documentation: Check the docs/ directory
  • Issues: Create a GitHub issue
  • Discussions: Use GitHub Discussions for questions

Built with ❀️ for scalable, multi-tenant SaaS applications

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors