Skip to content

Architecture Overview

Visual guide to modern SaaS architecture.

Full Stack Architecture

┌─────────────────────────────────────────────────────────────────┐
│                         CLIENT LAYER                             │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐           │
│  │   Browser    │  │  Mobile App  │  │     CLI      │           │
│  │   (React)    │  │   (React     │  │   (Node.js)  │           │
│  │              │  │    Native)   │  │              │           │
│  └──────────────┘  └──────────────┘  └──────────────┘           │
└─────────────────────────────────────────────────────────────────┘


┌─────────────────────────────────────────────────────────────────┐
│                          EDGE LAYER                              │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐           │
│  │     CDN      │  │    Edge      │  │   Static     │           │
│  │  (Vercel)    │  │  Functions   │  │   Assets     │           │
│  └──────────────┘  └──────────────┘  └──────────────┘           │
└─────────────────────────────────────────────────────────────────┘


┌─────────────────────────────────────────────────────────────────┐
│                       APPLICATION LAYER                          │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐           │
│  │   Next.js    │  │     API      │  │   Server     │           │
│  │  App Router  │  │   Routes     │  │   Actions    │           │
│  └──────────────┘  └──────────────┘  └──────────────┘           │
└─────────────────────────────────────────────────────────────────┘


┌─────────────────────────────────────────────────────────────────┐
│                        SERVICE LAYER                             │
│  ┌─────────┐  ┌─────────┐  ┌─────────┐  ┌─────────┐            │
│  │  Auth   │  │ Billing │  │  Email  │  │  Jobs   │            │
│  │ (Clerk) │  │(Stripe) │  │(Resend) │  │(Inngest)│            │
│  └─────────┘  └─────────┘  └─────────┘  └─────────┘            │
└─────────────────────────────────────────────────────────────────┘


┌─────────────────────────────────────────────────────────────────┐
│                         DATA LAYER                               │
│  ┌──────────────┐  ┌──────────────┐  ┌──────────────┐           │
│  │  PostgreSQL  │  │    Redis     │  │   Storage    │           │
│  │  (Supabase)  │  │  (Upstash)   │  │    (S3)      │           │
│  └──────────────┘  └──────────────┘  └──────────────┘           │
└─────────────────────────────────────────────────────────────────┘

Request Flow

User Request


┌─────────────┐
│   Vercel    │  ← CDN, SSL, DDoS protection
│    Edge     │
└─────────────┘


┌─────────────┐
│ Middleware  │  ← Auth check, rate limiting, redirects
└─────────────┘


┌─────────────┐
│   Next.js   │  ← Server Components, API Routes
│   Server    │
└─────────────┘


┌─────────────┐
│  Database   │  ← PostgreSQL with connection pooling
└─────────────┘


Response

Data Flow

                    ┌─────────────────┐
                    │    Frontend     │
                    │   (React/Next)  │
                    └────────┬────────┘

              ┌──────────────┼──────────────┐
              │              │              │
              ▼              ▼              ▼
       ┌──────────┐   ┌──────────┐   ┌──────────┐
       │  Server  │   │   tRPC   │   │   REST   │
       │ Actions  │   │  Router  │   │   API    │
       └────┬─────┘   └────┬─────┘   └────┬─────┘
            │              │              │
            └──────────────┼──────────────┘


                    ┌──────────────┐
                    │    Prisma    │
                    │     ORM      │
                    └──────┬───────┘


                    ┌──────────────┐
                    │  PostgreSQL  │
                    │   Database   │
                    └──────────────┘

Authentication Flow

User clicks "Sign In"


┌─────────────────┐
│  Clerk Hosted   │
│   Sign-In UI    │
└────────┬────────┘


┌─────────────────┐
│  OAuth Provider │  (Google, GitHub, etc.)
└────────┬────────┘


┌─────────────────┐
│  Clerk Backend  │  Creates session, JWT
└────────┬────────┘


┌─────────────────┐
│    Webhook      │  Syncs user to your database
└────────┬────────┘


┌─────────────────┐
│  Your App       │  Session cookie set
└─────────────────┘

Payment Flow

User clicks "Subscribe"


┌─────────────────┐
│ Create Checkout │  Your API creates Stripe session
│    Session      │
└────────┬────────┘


┌─────────────────┐
│ Stripe Checkout │  Hosted payment page
└────────┬────────┘


┌─────────────────┐
│ Payment Success │  Stripe processes payment
└────────┬────────┘


┌─────────────────┐
│    Webhook      │  Stripe sends event to your API
└────────┬────────┘


┌─────────────────┐
│ Update Database │  Store subscription status
└────────┬────────┘


┌─────────────────┐
│ Redirect User   │  Back to your app
└─────────────────┘
LayerTechnologyWhy
FrontendNext.js 14Best React framework, great DX
StylingTailwind CSSFast, consistent, customizable
Componentsshadcn/uiOwn the code, accessible
DatabasePostgreSQLReliable, feature-rich
ORMPrismaType-safe, great migrations
AuthClerkBest DX, managed solution
PaymentsStripeIndustry standard
EmailResendDeveloper-friendly
JobsInngestReliable, easy workflows
HostingVercelSeamless Next.js deployment
CacheUpstash RedisServerless Redis

Project Structure

my-saas/
├── app/                      # Next.js App Router
│   ├── (auth)/               # Auth routes (login, signup)
│   │   ├── login/
│   │   └── signup/
│   ├── (dashboard)/          # Protected app routes
│   │   ├── dashboard/
│   │   ├── settings/
│   │   └── layout.tsx        # Dashboard layout with sidebar
│   ├── (marketing)/          # Public marketing pages
│   │   ├── page.tsx          # Home page
│   │   ├── pricing/
│   │   └── blog/
│   ├── api/                  # API routes
│   │   ├── webhooks/
│   │   │   ├── clerk/
│   │   │   └── stripe/
│   │   └── trpc/
│   ├── layout.tsx            # Root layout
│   └── globals.css
├── components/
│   ├── ui/                   # shadcn/ui components
│   └── ...                   # App components
├── lib/
│   ├── db.ts                 # Prisma client
│   ├── auth.ts               # Auth helpers
│   ├── stripe.ts             # Stripe client
│   └── utils.ts              # Utilities
├── server/
│   ├── trpc.ts               # tRPC setup
│   └── routers/              # tRPC routers
├── prisma/
│   ├── schema.prisma         # Database schema
│   └── migrations/
├── public/                   # Static assets
├── .env.local                # Environment variables
├── next.config.js
├── tailwind.config.js
└── package.json

Get Started →