# rovidev95/rovidev-saas-starter architecture

> Architecture diagram of the GitHub repository rovidev95/rovidev-saas-starter, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/rovidev95/rovidev-saas-starter
- Repository: https://github.com/rovidev95/rovidev-saas-starter

## Overview

saas-starter is a multi-tenant SaaS foundation: users register or log in, create or enter an organization, then use tenant-scoped project, member, and billing areas. Its domain stages include session-based authentication, organization membership and role checks, plan-limit enforcement, and Stripe subscription checkout, portal management, and webhook updates. Prisma/PostgreSQL provides persistence. The graph follows documented capabilities, but unsampled member and organization internals are represented only where the tree and README establish them; dashed edges mark documented behavior without a sampled caller.

Main entry points: [`src/lib/db.ts`](https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/lib/db.ts) (Prisma client), [`src/app/api/stripe/webhook/route.ts`](https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/app/api/stripe/webhook/route.ts) (Stripe webhook), [`src/app/actions/billing.ts`](https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/app/actions/billing.ts) (Checkout and portal), [`src/lib/tenant.ts`](https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/lib/tenant.ts) (Tenant boundary)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_auth["Authentication"]
  node_login["Login and registration<br/>[page.tsx]"]
  node_auth_actions["Auth actions<br/>[auth.ts]"]
  node_auth_service["Current user lookup<br/>[auth.ts]"]
  node_session["Signed sessions<br/>[session.ts]"]
end

subgraph group_tenant["Tenant workspace"]
  node_workspace_home["Workspace selection<br/>[page.tsx]"]
  node_org_form["Create organization<br/>[CreateOrgForm.tsx]"]
  node_org_actions["Organization actions<br/>[org.ts]"]
  node_org_overview["Organization overview<br/>[page.tsx]"]
  node_tenant_nav["Tenant navigation<br/>[TenantNav.tsx]"]
  node_project_form["Project form"]
  node_members["Member management<br/>[page.tsx]"]
  node_marketing["Marketing and pricing<br/>[page.tsx]"]
end

subgraph group_policy["Domain policies"]
  node_tenant_context["Tenant boundary<br/>[tenant.ts]"]
  node_rbac["Role permissions<br/>[rbac.ts]"]
  node_plans["Plans and limits<br/>[plans.ts]"]
end

subgraph group_billing["Billing"]
  node_billing_page["Billing workspace<br/>[page.tsx]"]
  node_billing_actions["Checkout and portal<br/>[billing.ts]"]
  node_webhook["Stripe webhook<br/>[route.ts]"]
  node_billing_logic["Subscription mapping<br/>[billing.ts]"]
end

subgraph group_infra["Persistence and services"]
  node_db_client["Prisma client<br/>[db.ts]"]
  node_database[("PostgreSQL data model<br/>[schema.prisma]")]
  node_environment["Runtime configuration<br/>[env.ts]"]
  node_stripe_client["Stripe client<br/>[stripe.ts]"]
end

node_user(("User"))
node_stripe["Stripe"]

node_user -->|"submits credentials"| node_login
node_login -->|"calls auth actions"| node_auth_actions
node_auth_actions -->|"reads and creates users"| node_db_client
node_auth_actions -->|"starts or ends session"| node_session
node_auth_actions -->|"redirects after login"| node_workspace_home
node_session -->|"loads signing secret"| node_environment
node_workspace_home -->|"requires current user"| node_auth_service
node_auth_service -->|"reads session user"| node_session
node_auth_service -->|"loads user memberships"| node_db_client
node_workspace_home -->|"renders creation form"| node_org_form
node_org_form -->|"submits organization"| node_org_actions
node_org_actions -->|"persists organization data"| node_db_client
node_org_actions -->|"resolves tenant"| node_tenant_context
node_org_actions -->|"checks permissions"| node_rbac
node_org_actions -->|"checks plan limits"| node_plans
node_org_overview -->|"resolves tenant"| node_tenant_context
node_org_overview -->|"loads projects and seats"| node_db_client
node_org_overview -->|"checks project permissions"| node_rbac
node_org_overview -->|"computes usage limits"| node_plans
node_org_overview -->|"renders navigation"| node_tenant_nav
node_org_overview -->|"renders project form"| node_project_form
node_members -->|"resolves tenant"| node_tenant_context
node_members -->|"loads member data"| node_db_client
node_members -->|"renders navigation"| node_tenant_nav
node_tenant_context -->|"gets session user"| node_session
node_tenant_context -->|"checks organization membership"| node_db_client
node_billing_page -->|"resolves tenant"| node_tenant_context
node_billing_page -->|"checks billing access"| node_rbac
node_billing_page -->|"shows plan details"| node_plans
node_billing_page -->|"maps subscription status"| node_billing_logic
node_billing_page -->|"offers billing actions"| node_billing_actions
node_billing_actions -->|"resolves tenant"| node_tenant_context
node_billing_actions -->|"checks billing permission"| node_rbac
node_billing_actions -->|"creates checkout or portal"| node_stripe_client
node_billing_actions -->|"reads prices and URLs"| node_environment
node_stripe_client -->|"loads Stripe key"| node_environment
node_stripe_client -->|"calls Stripe API"| node_stripe
node_stripe -.->|"posts subscription events"| node_webhook
node_webhook -->|"verifies and retrieves events"| node_stripe_client
node_webhook -->|"reads webhook secret"| node_environment
node_webhook -->|"records event id"| node_db_client
node_webhook -->|"maps event status"| node_billing_logic
node_webhook -->|"maps Stripe price"| node_plans
node_webhook -->|"persists subscription"| node_billing_actions
node_billing_actions -->|"upserts subscription"| node_db_client
node_db_client -.->|"persists application records"| node_database
node_marketing -->|"shows plan options"| node_plans

click node_login "https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/app/(auth)/login/page.tsx"
click node_auth_actions "https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/app/actions/auth.ts"
click node_auth_service "https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/lib/auth.ts"
click node_session "https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/lib/session.ts"
click node_workspace_home "https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/app/dashboard/page.tsx"
click node_org_form "https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/components/CreateOrgForm.tsx"
click node_org_actions "https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/app/actions/org.ts"
click node_org_overview "https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/app/dashboard/%5Bslug%5D/page.tsx"
click node_tenant_nav "https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/components/TenantNav.tsx"
click node_project_form "https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/components/CreateProjectForm.tsx"
click node_members "https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/app/dashboard/%5Bslug%5D/members/page.tsx"
click node_tenant_context "https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/lib/tenant.ts"
click node_rbac "https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/lib/rbac.ts"
click node_plans "https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/lib/plans.ts"
click node_billing_page "https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/app/dashboard/%5Bslug%5D/billing/page.tsx"
click node_billing_actions "https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/app/actions/billing.ts"
click node_webhook "https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/app/api/stripe/webhook/route.ts"
click node_billing_logic "https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/lib/billing.ts"
click node_db_client "https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/lib/db.ts"
click node_database "https://github.com/rovidev95/rovidev-saas-starter/blob/main/prisma/schema.prisma"
click node_environment "https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/lib/env.ts"
click node_stripe_client "https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/lib/stripe.ts"
click node_marketing "https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/app/page.tsx"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_login,node_auth_actions,node_auth_service,node_session,node_user toneBlue
class node_workspace_home,node_org_form,node_org_actions,node_org_overview,node_tenant_nav,node_project_form,node_members,node_marketing toneAmber
class node_tenant_context,node_rbac,node_plans toneMint
class node_billing_page,node_billing_actions,node_webhook,node_billing_logic toneRose
class node_db_client,node_database,node_environment,node_stripe_client,node_stripe toneIndigo
```

## Components

### Authentication

- [Login and registration](https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/app/(auth)/login/page.tsx): `src/app/(auth)/login/page.tsx`
- [Auth actions](https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/app/actions/auth.ts): `src/app/actions/auth.ts`
- [Current user lookup](https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/lib/auth.ts): `src/lib/auth.ts`
- [Signed sessions](https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/lib/session.ts): `src/lib/session.ts`

### Tenant workspace

- [Workspace selection](https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/app/dashboard/page.tsx): `src/app/dashboard/page.tsx`
- [Create organization](https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/components/CreateOrgForm.tsx): `src/components/CreateOrgForm.tsx`
- [Organization actions](https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/app/actions/org.ts): `src/app/actions/org.ts`
- [Organization overview](https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/app/dashboard/%5Bslug%5D/page.tsx): `src/app/dashboard/[slug]/page.tsx`
- [Tenant navigation](https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/components/TenantNav.tsx): `src/components/TenantNav.tsx`
- [Project form](https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/components/CreateProjectForm.tsx): `src/components/CreateProjectForm.tsx`
- [Member management](https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/app/dashboard/%5Bslug%5D/members/page.tsx): `src/app/dashboard/[slug]/members/page.tsx`
- [Marketing and pricing](https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/app/page.tsx): `src/app/page.tsx`

### Domain policies

- [Tenant boundary](https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/lib/tenant.ts): `src/lib/tenant.ts`
- [Role permissions](https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/lib/rbac.ts): `src/lib/rbac.ts`
- [Plans and limits](https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/lib/plans.ts): `src/lib/plans.ts`

### Billing

- [Billing workspace](https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/app/dashboard/%5Bslug%5D/billing/page.tsx): `src/app/dashboard/[slug]/billing/page.tsx`
- [Checkout and portal](https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/app/actions/billing.ts): `src/app/actions/billing.ts`
- [Stripe webhook](https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/app/api/stripe/webhook/route.ts): `src/app/api/stripe/webhook/route.ts`
- [Subscription mapping](https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/lib/billing.ts): `src/lib/billing.ts`

### Persistence and services

- [Prisma client](https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/lib/db.ts): `src/lib/db.ts`
- [PostgreSQL data model](https://github.com/rovidev95/rovidev-saas-starter/blob/main/prisma/schema.prisma): `prisma/schema.prisma`
- [Runtime configuration](https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/lib/env.ts): `src/lib/env.ts`
- [Stripe client](https://github.com/rovidev95/rovidev-saas-starter/blob/main/src/lib/stripe.ts): `src/lib/stripe.ts`

### Other components

- **User**
- **Stripe**

## Connections

- User → Login and registration: submits credentials (evidence: `src/app/(auth)/login/page.tsx`)
- Login and registration → Auth actions: calls auth actions (evidence: `src/app/(auth)/login/page.tsx`)
- Auth actions → Prisma client: reads and creates users (evidence: `src/app/actions/auth.ts`)
- Auth actions → Signed sessions: starts or ends session (evidence: `src/app/actions/auth.ts`)
- Auth actions → Workspace selection: redirects after login (evidence: `src/app/actions/auth.ts`)
- Signed sessions → Runtime configuration: loads signing secret (evidence: `src/lib/session.ts`)
- Workspace selection → Current user lookup: requires current user (evidence: `src/app/dashboard/page.tsx`)
- Current user lookup → Signed sessions: reads session user (evidence: `src/lib/auth.ts`)
- Current user lookup → Prisma client: loads user memberships (evidence: `src/lib/auth.ts`)
- Workspace selection → Create organization: renders creation form (evidence: `src/app/dashboard/page.tsx`)
- Create organization → Organization actions: submits organization (evidence: `src/components/CreateOrgForm.tsx`)
- Organization actions → Prisma client: persists organization data (evidence: `src/app/actions/org.ts`)
- Organization actions → Tenant boundary: resolves tenant (evidence: `src/app/actions/org.ts`)
- Organization actions → Role permissions: checks permissions (evidence: `src/app/actions/org.ts`)
- Organization actions → Plans and limits: checks plan limits (evidence: `src/app/actions/org.ts`)
- Organization overview → Tenant boundary: resolves tenant (evidence: `src/app/dashboard/[slug]/page.tsx`)
- Organization overview → Prisma client: loads projects and seats (evidence: `src/app/dashboard/[slug]/page.tsx`)
- Organization overview → Role permissions: checks project permissions (evidence: `src/app/dashboard/[slug]/page.tsx`)
- Organization overview → Plans and limits: computes usage limits (evidence: `src/app/dashboard/[slug]/page.tsx`)
- Organization overview → Tenant navigation: renders navigation (evidence: `src/app/dashboard/[slug]/page.tsx`)
- Organization overview → Project form: renders project form (evidence: `src/app/dashboard/[slug]/page.tsx`)
- Member management → Tenant boundary: resolves tenant (evidence: `src/app/dashboard/[slug]/members/page.tsx`)
- Member management → Prisma client: loads member data (evidence: `src/app/dashboard/[slug]/members/page.tsx`)
- Member management → Tenant navigation: renders navigation (evidence: `src/app/dashboard/[slug]/members/page.tsx`)
- Tenant boundary → Signed sessions: gets session user (evidence: `src/lib/tenant.ts`)
- Tenant boundary → Prisma client: checks organization membership (evidence: `src/lib/tenant.ts`)
- Billing workspace → Tenant boundary: resolves tenant (evidence: `src/app/dashboard/[slug]/billing/page.tsx`)
- Billing workspace → Role permissions: checks billing access (evidence: `src/app/dashboard/[slug]/billing/page.tsx`)
- Billing workspace → Plans and limits: shows plan details (evidence: `src/app/dashboard/[slug]/billing/page.tsx`)
- Billing workspace → Subscription mapping: maps subscription status (evidence: `src/app/dashboard/[slug]/billing/page.tsx`)
- Billing workspace → Checkout and portal: offers billing actions (evidence: `src/app/dashboard/[slug]/billing/page.tsx`)
- Checkout and portal → Tenant boundary: resolves tenant (evidence: `src/app/actions/billing.ts`)
- Checkout and portal → Role permissions: checks billing permission (evidence: `src/app/actions/billing.ts`)
- Checkout and portal → Stripe client: creates checkout or portal (evidence: `src/app/actions/billing.ts`)
- Checkout and portal → Runtime configuration: reads prices and URLs (evidence: `src/app/actions/billing.ts`)
- Stripe client → Runtime configuration: loads Stripe key (evidence: `src/lib/stripe.ts`)
- Stripe client → Stripe: calls Stripe API (evidence: `src/lib/stripe.ts`)
- Stripe → Stripe webhook: posts subscription events (evidence: `README.md`)
- Stripe webhook → Stripe client: verifies and retrieves events (evidence: `src/app/api/stripe/webhook/route.ts`)
- Stripe webhook → Runtime configuration: reads webhook secret (evidence: `src/app/api/stripe/webhook/route.ts`)
- Stripe webhook → Prisma client: records event id (evidence: `src/app/api/stripe/webhook/route.ts`)
- Stripe webhook → Subscription mapping: maps event status (evidence: `src/app/api/stripe/webhook/route.ts`)
- Stripe webhook → Plans and limits: maps Stripe price (evidence: `src/app/api/stripe/webhook/route.ts`)
- Stripe webhook → Checkout and portal: persists subscription (evidence: `src/app/api/stripe/webhook/route.ts`)
- Checkout and portal → Prisma client: upserts subscription (evidence: `src/app/actions/billing.ts`)
- Prisma client → PostgreSQL data model: persists application records (evidence: `README.md`)
- Marketing and pricing → Plans and limits: shows plan options (evidence: `src/app/page.tsx`)
