# aiherrera/sveltesaasstarter architecture

> Architecture diagram of the GitHub repository aiherrera/sveltesaasstarter, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-09-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/aiherrera/sveltesaasstarter
- Repository: https://github.com/aiherrera/sveltesaasstarter

## Overview

##### Project Type & Purpose
- Full-stack SaaS template with two “faces”:
– Marketing/Public site (static & SSR pages)
– Authenticated user/admin dashboard
- Backed by Supabase (Auth + Postgres) and Stripe (billing/subscriptions), deployed on Cloudflare.

##### Main Components
a. Client (Browser or Mobile)
– Loads static / pre-rendered assets (HTML / CSS / JS)
– Performs interactive CSR navigation & form submissions
b. CDN & Edge Layer
– Cloudflare Pages serves static assets
– Cloudflare Workers run SvelteKit SSR & API endpoints
c. SvelteKit App
– File-based routing under src/routes
· (marketing) public pages (pre-rendered where possible)
· (admin) protected pages & API routes (user/dashboard flows)
– lib/ contains shared utilities (e.g., DB helpers)
– config.ts provides site metadata & keys
d. Supabase Services
– Auth (signup/sign-in/forgot-password, JWT sessions)
– Postgres DB (user profiles, subscriptions metadata)
– Exposed via PUBLIC_SUPABASE_URL & keys
e. Stripe
– Payment/Checkout API (checkout sessions, webhooks)
– Billing portal integration (manage subscription, receipts)
f. CI/CD & DevOps
– GitHub Actions (build, lint, test pipelines)
– Deploy hooks to Cloudflare

##### Architectural Patterns & Principles
- Hybrid SSR/CSR:
– SSR the first load (via Workers) for performance/SEO
– CSR on subsequent navigation (pre-loaded JS)
- Static-first: Pre-render (prerender) marketing pages & blog content
- File-based routing: server versus page modules under src/routes
- Serverless / Edge Functions: each +server.ts / +server.js file becomes an isolated endpoint
- Separation of concerns:
– Public (marketing) and private (admin) route groups
– UI styling via Tailwind + DaisyUI

##### Essential Elements
– Notes on prerendered vs. server-rendered routes

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Client Layer
    Client["Client (Browser/Mobile)"]:::frontend
    click Client "https://github.com/aiherrera/sveltesaasstarter/tree/main/static/"

    %% CDN & Edge Layer
    subgraph "CDN & Edge Layer"
        direction TB
        Pages["Cloudflare Pages (Static CDN)"]:::infra
        Workers["Cloudflare Workers (SSR & API)"]:::infra
        click Pages "https://github.com/aiherrera/sveltesaasstarter/blob/main/svelte.config.js"
        click Pages "https://github.com/aiherrera/sveltesaasstarter/blob/main/vite.config.ts"
    end

    %% SvelteKit Application
    subgraph "SvelteKit App"
        direction TB
        subgraph "Public Marketing Routes"
            direction TB
            Public["src/routes/(marketing)/"]:::frontend
            click Public "https://github.com/aiherrera/sveltesaasstarter/tree/main/src/routes/(marketing)/"
        end
        subgraph "Protected Admin & API Routes"
            direction TB
            Admin["src/routes/(admin)/"]:::frontend
            click Admin "https://github.com/aiherrera/sveltesaasstarter/tree/main/src/routes/(admin)/"
            SubscriptionHelpers["subscription_helpers.server.ts"]:::billing
            click SubscriptionHelpers "https://github.com/aiherrera/sveltesaasstarter/blob/main/src/routes/(admin)/account/subscription_helpers.server.ts"
        end
        Utils["Shared Utilities (src/lib)"]:::data
        click Utils "https://github.com/aiherrera/sveltesaasstarter/blob/main/src/lib/index.js"
        Config["Site Config & Env"]:::infra
        click Config "https://github.com/aiherrera/sveltesaasstarter/blob/main/src/config.ts"
        click Config "https://github.com/aiherrera/sveltesaasstarter/tree/main/local_env_template"
        Hooks["Server Hooks (Auth/session)"]:::data
        click Hooks "https://github.com/aiherrera/sveltesaasstarter/blob/main/src/hooks.server.ts"
    end

    %% Supabase Services
    subgraph "Supabase Services"
        direction TB
        SupaAuth["Supabase Auth"]:::data
        SupaDB["Postgres DB"]:::data
        click SupaDB "https://github.com/aiherrera/sveltesaasstarter/blob/main/src/DatabaseDefinitions.ts"
        click SupaAuth "https://github.com/aiherrera/sveltesaasstarter/tree/main/local_env_template"
    end

    %% Stripe Service
    Stripe["Stripe API & Webhooks"]:::billing

    %% CI/CD & DevOps
    subgraph "CI/CD & DevOps"
        direction TB
        GitHubActions["GitHub Actions"]:::infra
        BuildCI["Build & Deploy Pipeline"]:::infra
        click BuildCI "https://github.com/aiherrera/sveltesaasstarter/blob/main/.github/workflows/build.yml"
        FormatCI["Formatting & Linting Pipeline"]:::infra
        click FormatCI "https://github.com/aiherrera/sveltesaasstarter/blob/main/.github/workflows/format.yml"
        click FormatCI "https://github.com/aiherrera/sveltesaasstarter/blob/main/.github/workflows/linting.yml"
        TestCI["Testing Pipeline"]:::infra
        click TestCI "https://github.com/aiherrera/sveltesaasstarter/blob/main/.github/workflows/tests.yml"
    end

    %% Connections
    Client -->|"HTTPS: fetch assets"| Pages
    Client -->|"HTTPS: SSR page/API"| Workers
    Pages -->|"serves static assets"| Client

    Workers -->|"RPC/REST: Auth"| SupaAuth
    Workers -->|"RPC/REST: Data"| SupaDB
    Workers -->|"REST: Create checkout"| Stripe
    Stripe -->|"Webhook events"| Workers

    SupaAuth -->|"Callbacks"| Workers

    GitHubActions -->|"Deploy hooks"| Pages
    GitHubActions -->|"Deploy hooks"| Workers

    %% Class Definitions
    classDef frontend fill:#D0E8FF,stroke:#004080;
    classDef data fill:#D0FFD8,stroke:#006600;
    classDef billing fill:#FFE0B2,stroke:#CC6600;
    classDef infra fill:#F0F0F0,stroke:#666666;
```
