Skip to content

SaaS Starter

Le template SaaS Starter genere une application SaaS multi-tenant complete, prete pour la production. C'est le point de depart recommande pour les projets SaaS.

Creation

bash
rvr new MonSaaS --template saas-starter
cd MonSaaS

Modules inclus

ModuleRole
Identity.ProAuthentification JWT, 2FA, OAuth2
Multi-tenancyIsolation par schema ou base de donnees
BillingAbonnements Stripe, plans, factures
WebhooksNotifications evenementielles
CachingCache distribue Redis
JobsTaches planifiees (Hangfire)
ExportExport PDF/Excel des donnees
AuditJournal d'audit des actions

Entites incluses

Le template genere ces entites metier :

csharp
// Tenant et gestion utilisateur
public class Tenant : AggregateRoot<Guid>
{
    public string Name { get; private set; }
    public string Subdomain { get; private set; }
    public TenantPlan Plan { get; private set; }
    public bool IsActive { get; private set; }
    public DateTime CreatedAt { get; private set; }
}

public class TenantUser : Entity<Guid>
{
    public Guid TenantId { get; private set; }
    public Guid UserId { get; private set; }
    public TenantRole Role { get; private set; }
}

// Abonnement et facturation
public class Subscription : AggregateRoot<Guid>
{
    public Guid TenantId { get; private set; }
    public SubscriptionPlan Plan { get; private set; }
    public SubscriptionStatus Status { get; private set; }
    public string StripeSubscriptionId { get; private set; }
    public DateTime CurrentPeriodEnd { get; private set; }
}

public class Invoice : Entity<Guid>
{
    public Guid TenantId { get; private set; }
    public Money Amount { get; private set; }
    public InvoiceStatus Status { get; private set; }
    public string StripeInvoiceId { get; private set; }
}

API Endpoints

MethodeEndpointDescription
POST/api/v1/auth/registerInscription + creation tenant
POST/api/v1/auth/loginConnexion
GET/api/v1/tenantsLister les tenants (admin)
PUT/api/v1/tenants/:id/planChanger de plan
GET/api/v1/subscriptionsAbonnement actuel
POST/api/v1/subscriptions/checkoutLancer le paiement Stripe
GET/api/v1/invoicesHistorique des factures
POST/api/v1/webhooksConfigurer un webhook

Configuration

appsettings.json

json
{
  "MultiTenancy": {
    "IsEnabled": true,
    "Strategy": "PerSchema",
    "DefaultTenant": "default"
  },
  "Stripe": {
    "SecretKey": "sk_test_...",
    "PublishableKey": "pk_test_...",
    "WebhookSecret": "whsec_...",
    "Plans": {
      "Free": { "PriceId": "price_free", "Limits": { "Users": 3, "Storage": "1GB" } },
      "Pro": { "PriceId": "price_pro", "Limits": { "Users": 25, "Storage": "50GB" } },
      "Enterprise": { "PriceId": "price_enterprise", "Limits": { "Users": -1, "Storage": "unlimited" } }
    }
  }
}

Demarrage

bash
# 1. Lancer l'infrastructure
docker compose up -d

# 2. Appliquer les migrations
rvr migrate apply

# 3. Seeder les donnees de demo
rvr seed --profile demo

# 4. Lancer l'API
dotnet run --project src/MonSaaS.Api

# 5. (Optionnel) Lancer le frontend
cd src/frontend && npm run dev

Architecture

MonSaaS/
  src/
    MonSaaS.Domain/
      Tenants/           # Aggregate Tenant, TenantUser
      Subscriptions/     # Aggregate Subscription
      Invoices/          # Entity Invoice
    MonSaaS.Application/
      Tenants/
        Commands/        # CreateTenant, UpdatePlan
        Queries/         # GetTenantById, GetTenants
      Subscriptions/
        Commands/        # CreateSubscription, CancelSubscription
        Queries/         # GetCurrentSubscription
    MonSaaS.Infrastructure/
      Persistence/       # DbContext, Migrations
      Stripe/            # StripeService, WebhookHandler
    MonSaaS.Api/
      Controllers/       # TenantController, SubscriptionController
      Middleware/         # TenantResolutionMiddleware

Etape suivante

Released under the MIT License.