Enterprise-grade SaaS Starter Kit — Built in 14 days
🌐 Live Demo • 📄 API Docs • 📡 GraphQL
Arrêtez de reconstruire les mêmes fondations à chaque projet SaaS. Ce starter kit production-ready vous fait gagner des semaines de développement.
- Vue d'ensemble
- Fonctionnalités
- Stack technique
- Architecture
- Installation rapide
- Configuration
- API REST
- API GraphQL
- Tests
- Déploiement
- Auteur
nestjs-saas-starter est un starter kit open source et production-ready pour
accélérer le développement de vos projets SaaS.
Construit en 14 jours avec une approche TDD (Test Driven Development), il intègre toutes les fonctionnalités essentielles d'une application SaaS moderne.
✅ 95+ tests unitaires et E2E
✅ Couverture de code > 80%
✅ Double API : REST (Swagger) + GraphQL (Apollo)
✅ Déployé et disponible en production
| Fonctionnalité | Status |
|---|---|
| Signup / Login / Logout | ✅ |
| JWT Access Token (15min) + Refresh Token (7j) | ✅ |
| Rotation automatique des Refresh Tokens | ✅ |
| Vérification email par OTP (6 chiffres, 15min) | ✅ |
| Reset password par OTP | ✅ |
| 2FA — Google Authenticator (TOTP) | ✅ |
| OAuth Google | ✅ |
| API Key (avec hash bcrypt) | ✅ |
| Fonctionnalité | Status |
|---|---|
| CRUD utilisateurs | ✅ |
| RBAC — Rôles et permissions | ✅ |
| Profile utilisateur | ✅ |
| Activation compte par email | ✅ |
| Fonctionnalité | Status |
|---|---|
| Multi-tenancy (organisations) | ✅ |
| Plans : Free, Pro, Enterprise | ✅ |
| Invitations membres par email | ✅ |
| Rôles dans l'organisation : OWNER, ADMIN, MEMBER | ✅ |
| Fonctionnalité | Status |
|---|---|
| Erreurs traduisibles | ✅ |
| Support EN / FR | ✅ |
| Clés i18n dans toutes les réponses | ✅ |
| Fonctionnalité | Status |
|---|---|
| REST API avec Swagger | ✅ |
| GraphQL avec Apollo (Code First) | ✅ |
| Rate Limiting par endpoint | ✅ |
| Fonctionnalité | Status |
|---|---|
| Docker Compose | ✅ |
| Rate Limiting (5 req/min auth, 3 req/min email) | ✅ |
| Logging structuré JSON | ✅ |
| Exception Filter global | ✅ |
| Response Interceptor unifié | ✅ |
| Variables d'environnement validées | ✅ |
Backend → NestJS 10 + TypeScript 5
Base de données → PostgreSQL 15 + Prisma 7
API → REST (Swagger) + GraphQL (Apollo)
Auth → JWT + Passport + bcryptjs
2FA → speakeasy (TOTP)
OAuth → passport-google-oauth20
Emails → nodemailer + HTML templates
Tests → Jest (TDD) — 95+ tests
Infrastructure → Docker Compose
Déploiement → Render.com
nestjs-saas-starter/
├── src/
│ ├── auth/ # 🔐 Authentification
│ │ ├── strategies/ # JWT, Google, API Key
│ │ ├── guards/ # JwtAuthGuard, ApiKeyGuard...
│ │ ├── decorators/ # @CurrentUser()
│ │ ├── dto/ # SignupDto, LoginDto...
│ │ ├── types/ # AuthTokens, JwtPayload...
│ │ ├── auth.service.ts # Logique auth + 2FA
│ │ ├── oauth.service.ts # Google OAuth
│ │ ├── api-key.service.ts # API Key management
│ │ └── two-factor.service.ts # TOTP 2FA
│ │
│ ├── users/ # 👥 Gestion utilisateurs + RBAC
│ ├── organizations/ # 🏢 Multi-tenancy + Invitations
│ │
│ ├── graphql/ # 📡 API GraphQL
│ │ ├── resolvers/ # Auth, Users, Organizations
│ │ ├── types/ # ObjectTypes
│ │ └── inputs/ # InputTypes
│ │
│ ├── i18n/ # 🌍 Traductions EN/FR
│ ├── mail/ # 📧 Emails transactionnels
│ │ └── templates/ # HTML templates
│ │
│ ├── common/ # 🔧 Utilitaires partagés
│ │ ├── guards/ # RolesGuard, GqlAuthGuard
│ │ ├── decorators/ # @Roles(), @GqlCurrentUser()
│ │ ├── filters/ # HttpExceptionFilter
│ │ ├── interceptors/ # Logging, Response
│ │ ├── logger/ # Structured JSON logging
│ │ └── config/ # ThrottlerConfig
│ │
│ └── prisma/ # 🗄 Base de données
│ └── seed.ts # Rôles par défaut
│
├── test/ # 🧪 Tests E2E
│ ├── helpers/ # createTestApp, cleanDatabase
│ ├── auth.e2e-spec.ts
│ ├── users.e2e-spec.ts
│ └── organizations.e2e-spec.ts
│
├── prisma/
│ └── schema.prisma # Schéma DB complet
│
├── docker-compose.yml # PostgreSQL + Redis
├── render.yaml # Configuration Render.com
└── .env.example # Variables d'environnement
node >= 18
npm >= 9
docker & docker-composegit clone https://github.com/alibia-phanuel/nestjs-saas-auth-starter.git
cd nestjs-saas-auth-starternpm installcp .env.example .env
# Éditez .env avec vos valeursdocker-compose up -dnpx prisma migrate dev
npx prisma generate
npm run seednpm run start:devApp → http://localhost:3000
Swagger → http://localhost:3000/api/docs
GraphQL → http://localhost:3000/graphql
Health → http://localhost:3000/health
# Application
NODE_ENV=development
PORT=3000
APP_URL=http://localhost:3000
# Base de données
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/saas_auth_db"
# JWT
JWT_ACCESS_SECRET=your_very_long_random_secret_here
JWT_ACCESS_EXPIRES_IN=15m
JWT_REFRESH_SECRET=another_very_long_random_secret_here
JWT_REFRESH_EXPIRES_IN=7d
# Email (Gmail)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_SECURE=false
SMTP_USER=your_email@gmail.com
SMTP_PASS=your_gmail_app_password
SENDER_EMAIL=your_email@gmail.com
# OAuth Google
GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret
GOOGLE_CALLBACK_URL=http://localhost:3000/auth/google/callbacknode -e "console.log(require('crypto').randomBytes(32).toString('base64'))"| Method | Endpoint | Description | Rate Limit |
|---|---|---|---|
| POST | /auth/signup |
Inscription | 3/min |
| POST | /auth/verify-otp |
Vérification OTP | 10/min |
| POST | /auth/login |
Connexion | 5/min |
| POST | /auth/refresh |
Refresh token | 100/min |
| POST | /auth/forgot-password |
Reset password | 3/min |
| POST | /auth/reset-password |
Nouveau mot de passe | 5/min |
| GET | /auth/me |
Profil connecté 🔒 | 100/min |
| POST | /auth/2fa/setup |
Setup 2FA 🔒 | 100/min |
| POST | /auth/2fa/enable |
Activer 2FA 🔒 | 5/min |
| POST | /auth/2fa/disable |
Désactiver 2FA 🔒 | 5/min |
| POST | /auth/2fa/verify |
Vérifier code 2FA | 5/min |
| GET | /auth/google |
OAuth Google | - |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| GET | /users |
Liste utilisateurs | 🔒 Admin |
| GET | /users/me |
Mon profil | 🔒 |
| GET | /users/:id |
Profil par id | 🔒 Admin |
| PATCH | /users/:id |
Modifier profil | 🔒 |
| DELETE | /users/:id |
Supprimer compte | 🔒 |
| POST | /users/:id/roles |
Assigner rôle | 🔒 Admin |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| POST | /organizations |
Créer organisation | 🔒 |
| GET | /organizations |
Mes organisations | 🔒 |
| GET | /organizations/:id |
Détails | 🔒 Membre |
| PATCH | /organizations/:id |
Modifier | 🔒 Owner/Admin |
| DELETE | /organizations/:id |
Supprimer | 🔒 Owner |
| POST | /organizations/:id/invite |
Inviter | 🔒 Owner/Admin |
| GET | /organizations/accept/:token |
Accepter invitation | 🔒 |
| Method | Endpoint | Description | Auth |
|---|---|---|---|
| POST | /auth/api-keys |
Créer API key | 🔒 JWT |
| GET | /auth/api-keys |
Lister mes keys | 🔒 JWT |
| GET | /auth/api-keys/test |
Tester une key | 🔒 API Key |
| DELETE | /auth/api-keys/:id |
Révoquer | 🔒 JWT |
Accessible sur /graphql avec Apollo Sandbox.
# Inscription
mutation {
signup(input: {
email: "user@example.com"
password: "SecurePass123!"
firstName: "John"
}) {
key
message
}
}
# Connexion
mutation {
login(input: {
email: "user@example.com"
password: "SecurePass123!"
}) {
accessToken
refreshToken
requiresTwoFactor
}
}
# Vérifier OTP
mutation {
verifyOtp(input: {
email: "user@example.com"
otp: "847392"
}) {
key
message
}
}# Profil connecté
query {
me {
id
email
firstName
roles { role { name } }
}
}
# Mes organisations
query {
myOrganizations {
id
name
planType
members { role }
}
}# Tests unitaires
npm run test
# Tests avec coverage
npm run test:cov
# Tests E2E
npm run test:e2e
# Watch mode
npm run test:watchTests unitaires : 95+ tests ✅
Tests E2E : Auth + Users + Organizations ✅
Coverage : > 80% sur les services ✅
Approche : TDD (Red → Green → Refactor) ✅
Le projet inclut un render.yaml pour déploiement automatique.
# 1. Fork le repo
# 2. Connecter à Render.com
# 3. New → Blueprint → Sélectionner le repo
# 4. Ajouter les variables d'environnement
# 5. Deploy# Build
docker build -t nestjs-saas-starter .
# Run
docker-compose up -d# Crée les rôles et l'admin par défaut
npm run seed
# Compte admin par défaut
Email : admin@nestjs-saas.com
Password : Admin123!
⚠️ Changez le mot de passe admin en production !
Les contributions sont bienvenues !
# Fork le projet
# Créer une branche feature
git checkout -b feature/ma-feature
# Commit avec convention
git commit -m "feat(scope): description"
# Push et Pull Request
git push origin feature/ma-featurefeat → nouvelle fonctionnalité
fix → correction de bug
test → ajout de tests
docs → documentation
refactor → refactoring
chore → config, deps
MIT © Tsopze Nekdem Phanuel Arsene