# webdevsimplified/better-auth-crash-course architecture

> Architecture diagram of the GitHub repository webdevsimplified/better-auth-crash-course, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-07). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/webdevsimplified/better-auth-crash-course
- Repository: https://github.com/webdevsimplified/better-auth-crash-course

## Overview

This is a Next.js account and organization management application built around Better Auth. Users sign in or register, then manage profile/security, organizations, or (with permission) user administration; the pages invoke auth APIs through the client or server configuration. Authentication also persists through Drizzle and supports email notifications, social login, and Stripe subscriptions. The graph preserves these documented-by-source capabilities, but unsampled organization and profile components are represented at their exact component paths; their internal call details are not inferred.

Main entry points: [`src/lib/auth/auth.ts`](https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/lib/auth/auth.ts) (Auth configuration), [`src/lib/auth/auth-client.ts`](https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/lib/auth/auth-client.ts) (Auth client), [`src/app/auth/login/page.tsx`](https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/app/auth/login/page.tsx) (Sign-in flow), [`src/app/profile/page.tsx`](https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/app/profile/page.tsx) (Profile management)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_entry["App workflows"]
  node_home["Home<br/>[page.tsx]"]
  node_login["Sign-in flow<br/>[page.tsx]"]
  node_twofa["2FA verification<br/>[page.tsx]"]
  node_profile["Profile management<br/>[page.tsx]"]
  node_admin["User administration<br/>[page.tsx]"]
end

subgraph group_identity["Identity and access"]
  node_authclient["Auth client<br/>[auth-client.ts]"]
  node_authserver["Auth configuration<br/>[auth.ts]"]
  node_authroute["Auth API route<br/>[route.ts]"]
  node_permissions["Roles and permissions<br/>[permissions.ts]"]
  node_profilefeatures["Profile feature views"]
  node_userrow["User row actions<br/>[user-row.tsx]"]
end

subgraph group_domain["Organizations and billing"]
  node_orgs["Organization workspace<br/>[page.tsx]"]
  node_invites["Invite acceptance<br/>[page.tsx]"]
  node_orgfeatures["Org feature views"]
end

subgraph group_infra["Persistence and messaging"]
  node_database[("Drizzle database<br/>[db.ts]")]
  node_schema["Auth schema<br/>[auth-schema.ts]"]
  node_emails["Email notifications"]
  node_emailtransport["Email sender<br/>[send-email.ts]"]
end

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

node_user -->|"opens"| node_home
node_user -->|"authenticates"| node_login
node_home -->|"checks session"| node_authclient
node_login -->|"checks session"| node_authclient
node_login -->|"authenticates"| node_authclient
node_authclient -->|"redirects for 2FA"| node_twofa
node_user -->|"manages account"| node_profile
node_profile -->|"loads session and accounts"| node_authserver
node_profile -->|"renders"| node_profilefeatures
node_user -->|"manages organizations"| node_orgs
node_orgs -->|"loads session"| node_authserver
node_orgs -->|"renders"| node_orgfeatures
node_user -->|"accepts invitation"| node_invites
node_invites -->|"loads session"| node_authserver
node_user -->|"manages users"| node_admin
node_admin -->|"checks access and lists users"| node_authserver
node_admin -->|"renders rows"| node_userrow
node_authroute -->|"dispatches requests"| node_authserver
node_authserver -->|"persists auth data"| node_database
node_database -->|"uses schema"| node_schema
node_authserver -->|"configures roles"| node_permissions
node_authclient -->|"configures client roles"| node_permissions
node_authserver -->|"sends auth notifications"| node_emails
node_emails -->|"sends messages"| node_emailtransport
node_authserver -->|"configures subscriptions"| node_stripe

click node_home "https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/app/page.tsx"
click node_login "https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/app/auth/login/page.tsx"
click node_twofa "https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/app/auth/2fa/page.tsx"
click node_profile "https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/app/profile/page.tsx"
click node_admin "https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/app/admin/page.tsx"
click node_orgs "https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/app/organizations/page.tsx"
click node_invites "https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/app/organizations/invites/%5Bid%5D/page.tsx"
click node_orgfeatures "https://github.com/webdevsimplified/better-auth-crash-course/tree/main/src/app/organizations/_components"
click node_authclient "https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/lib/auth/auth-client.ts"
click node_authserver "https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/lib/auth/auth.ts"
click node_authroute "https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/app/api/auth/%5B...all%5D/route.ts"
click node_permissions "https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/components/auth/permissions.ts"
click node_profilefeatures "https://github.com/webdevsimplified/better-auth-crash-course/tree/main/src/app/profile/_components"
click node_userrow "https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/app/admin/_components/user-row.tsx"
click node_database "https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/drizzle/db.ts"
click node_schema "https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/drizzle/schemas/auth-schema.ts"
click node_emails "https://github.com/webdevsimplified/better-auth-crash-course/tree/main/src/lib/emails"
click node_emailtransport "https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/lib/emails/send-email.ts"

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_home,node_login,node_twofa,node_profile,node_admin,node_user toneBlue
class node_authclient,node_authserver,node_authroute,node_permissions,node_profilefeatures,node_userrow toneAmber
class node_orgs,node_invites,node_orgfeatures toneMint
class node_database,node_schema,node_emails,node_emailtransport toneRose
class node_stripe toneIndigo
```

## Components

### App workflows

- [Home](https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/app/page.tsx): `src/app/page.tsx`
- [Sign-in flow](https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/app/auth/login/page.tsx): `src/app/auth/login/page.tsx`
- [2FA verification](https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/app/auth/2fa/page.tsx): `src/app/auth/2fa/page.tsx`
- [Profile management](https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/app/profile/page.tsx): `src/app/profile/page.tsx`
- [User administration](https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/app/admin/page.tsx): `src/app/admin/page.tsx`

### Identity and access

- [Auth client](https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/lib/auth/auth-client.ts): `src/lib/auth/auth-client.ts`
- [Auth configuration](https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/lib/auth/auth.ts): `src/lib/auth/auth.ts`
- [Auth API route](https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/app/api/auth/%5B...all%5D/route.ts): `src/app/api/auth/[...all]/route.ts`
- [Roles and permissions](https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/components/auth/permissions.ts): `src/components/auth/permissions.ts`
- [Profile feature views](https://github.com/webdevsimplified/better-auth-crash-course/tree/main/src/app/profile/_components): `src/app/profile/_components`
- [User row actions](https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/app/admin/_components/user-row.tsx): `src/app/admin/_components/user-row.tsx`

### Organizations and billing

- [Organization workspace](https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/app/organizations/page.tsx): `src/app/organizations/page.tsx`
- [Invite acceptance](https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/app/organizations/invites/%5Bid%5D/page.tsx): `src/app/organizations/invites/[id]/page.tsx`
- [Org feature views](https://github.com/webdevsimplified/better-auth-crash-course/tree/main/src/app/organizations/_components): `src/app/organizations/_components`

### Persistence and messaging

- [Drizzle database](https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/drizzle/db.ts): `src/drizzle/db.ts`
- [Auth schema](https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/drizzle/schemas/auth-schema.ts): `src/drizzle/schemas/auth-schema.ts`
- [Email notifications](https://github.com/webdevsimplified/better-auth-crash-course/tree/main/src/lib/emails): `src/lib/emails`
- [Email sender](https://github.com/webdevsimplified/better-auth-crash-course/blob/main/src/lib/emails/send-email.ts): `src/lib/emails/send-email.ts`

### Other components

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

## Connections

- User → Home: opens (evidence: `src/app/page.tsx`)
- User → Sign-in flow: authenticates (evidence: `src/app/auth/login/page.tsx`)
- Home → Auth client: checks session (evidence: `src/app/page.tsx`)
- Sign-in flow → Auth client: checks session (evidence: `src/app/auth/login/page.tsx`)
- Sign-in flow → Auth client: authenticates (evidence: `src/lib/auth/auth-client.ts`)
- Auth client → 2FA verification: redirects for 2FA (evidence: `src/lib/auth/auth-client.ts`)
- User → Profile management: manages account (evidence: `src/app/profile/page.tsx`)
- Profile management → Auth configuration: loads session and accounts (evidence: `src/app/profile/page.tsx`)
- Profile management → Profile feature views: renders (evidence: `src/app/profile/page.tsx`)
- User → Organization workspace: manages organizations (evidence: `src/app/organizations/page.tsx`)
- Organization workspace → Auth configuration: loads session (evidence: `src/app/organizations/page.tsx`)
- Organization workspace → Org feature views: renders (evidence: `src/app/organizations/page.tsx`)
- User → Invite acceptance: accepts invitation (evidence: `src/app/organizations/invites/[id]/page.tsx`)
- Invite acceptance → Auth configuration: loads session (evidence: `src/app/organizations/invites/[id]/page.tsx`)
- User → User administration: manages users (evidence: `src/app/admin/page.tsx`)
- User administration → Auth configuration: checks access and lists users (evidence: `src/app/admin/page.tsx`)
- User administration → User row actions: renders rows (evidence: `src/app/admin/page.tsx`)
- Auth API route → Auth configuration: dispatches requests (evidence: `src/app/api/auth/[...all]/route.ts`)
- Auth configuration → Drizzle database: persists auth data (evidence: `src/lib/auth/auth.ts`)
- Drizzle database → Auth schema: uses schema (evidence: `src/drizzle/db.ts`)
- Auth configuration → Roles and permissions: configures roles (evidence: `src/lib/auth/auth.ts`)
- Auth client → Roles and permissions: configures client roles (evidence: `src/lib/auth/auth-client.ts`)
- Auth configuration → Email notifications: sends auth notifications (evidence: `src/lib/auth/auth.ts`)
- Email notifications → Email sender: sends messages (evidence: `src/lib/emails/email-verification.ts`)
- Auth configuration → Stripe: configures subscriptions (evidence: `src/lib/auth/auth.ts`)
