Ghoststack Docs

Ghoststack Architecture

How the pieces fit together.

Stack Overview

┌─────────────────────────────────────────────────────┐
│                    Frontend                          │
│  Next.js App Router + DaisyUI                       │
│  app/page.tsx, app/dashboard/, app/pricing/         │
└─────────────────────────────────────────────────────┘
                         │
                         ▼
┌─────────────────────────────────────────────────────┐
│                   API Routes                         │
│  app/api/stripe/, app/api/auth/, app/api/webhooks/     │
└─────────────────────────────────────────────────────┘
                         │
          ┌──────────────┼──────────────┐
          ▼              ▼              ▼
    ┌──────────┐  ┌──────────┐  ┌──────────┐
    │ Supabase │  │  Stripe  │  │  Resend  │
    │ Auth +DB │  │ Payments │  │  Email   │
    └──────────┘  └──────────┘  └──────────┘

Request Flows

Page Load (Server Component)

User visits /dashboard
  → proxy.ts checks auth
  → app/dashboard/page.tsx loads
  → Page verifies user and lib/supabase/db.ts queries DB
  → Page renders with data
User enters email on /login
  → Supabase sends magic link
  → User clicks link
  → /callback exchanges code for session
  → Redirect to /dashboard

Payment

User clicks "Subscribe"
  → /api/stripe/checkout creates session
  → Stripe hosts checkout
  → Webhook hits /api/webhooks/stripe
  → lib/supabase/db.ts updates subscription

Key Files

LayerFilesPurpose
Pagesapp/page.tsx, app/dashboard/UI and routing
APIapp/api/stripe/, app/api/webhooks/Backend logic
Authproxy.ts, lib/supabase/server.tsSession + protection
Databaselib/supabase/db.ts, supabase/setup.sqlQueries + schema
Paymentslib/stripe.ts, lib/plans.tsStripe + pricing
Emaillib/resend.tsxTemplates + sending
App settings.env.localLocal service configuration; may contain secrets
Agent instructionsAGENTS.mdShared project guidance; never secrets

Supabase Clients

Three clients for different contexts:

ClientFileWhen to Use
Browserlib/supabase/client.tsClient components ("use client")
Serverlib/supabase/server.tsServer components, API routes
Adminlib/supabase/server.tsTrusted server operations, such as verified webhooks (bypasses RLS)

Folder Structure

app/                    # Pages + API routes
├── page.tsx            # Landing page
├── dashboard/          # Protected pages
└── api/                # Backend endpoints

lib/                    # Business logic
├── stripe.ts           # Payment helpers
├── resend.tsx          # Email templates
└── supabase/           # Auth clients + database queries

components/             # Shared UI
emails/                 # Transactional email templates
docs/                   # Generated guide reference, not app routes

The Ghoststack guides are hosted separately, with a generated Markdown reference copy in docs/. A documentation website is an optional feature you can add to your own app.

Prompt: Understand a Flow

I want to understand how [FEATURE] works.

Trace the flow from user action to database.
Show me which files are involved and how they connect, using the actual code.
Explain unfamiliar terms and give me one example to follow. Do not edit files.