Skip to content

LionsTheme/the-edge-stack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

57 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ The Edge Stack

Edge-first monorepo boilerplate designed for ultra-fast applications. Built with Turborepo, Hono, Drizzle, Neon, TanStack Start, Astro, Starlight, and Cloudflare Workers.

Deploy to Cloudflare Workers

πŸ“š Extended Documentation: Visit our Wiki for detailed step-by-step guides on every technology in the stack.


✨ Features

  • ⚑ Edge-First: Deploy to 300+ locations worldwide with Cloudflare Workers
  • πŸ”’ Type-Safe End-to-End: Hono RPC shares types between API and frontend
  • πŸ—„οΈ Serverless Database: Neon Postgres with branching for previews
  • πŸ” Stateless Auth: Better Auth optimized for edge runtimes
  • πŸ“¦ Monorepo: Turborepo + pnpm with shared configs and components
  • 🎨 Shared Design System: Shadcn/ui + Tailwind CSS across all apps
  • πŸ§ͺ Testing Ready: Vitest with Cloudflare Workers pool
  • πŸ“š Documentation: Astro Starlight with shared design tokens

πŸ—οΈ Architecture

                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                  β”‚   Cloudflare    β”‚
                  β”‚    Gateway      β”‚
                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                           β”‚
        β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
        β”‚                  β”‚                  β”‚
   β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”      β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”     β”Œβ”€β”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”€β”€β”
   β”‚   API   β”‚      β”‚ Dashboard β”‚     β”‚  Landing   β”‚
   β”‚ (Hono)  β”‚      β”‚(TanStack) β”‚     β”‚  (Astro)   β”‚
   β””β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”˜      β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜     β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
        β”‚
   β”Œβ”€β”€β”€β”€β–Όβ”€β”€β”€β”€β”
   β”‚  Neon   β”‚
   β”‚(Postgres)β”‚
   β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Authentication Flow

Better Auth lives inside apps/api (following the official Hono integration pattern), not as a separate package. Any app in the monorepo consumes auth via HTTP:

                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                  β”‚  Dashboard  β”‚ ──signIn.social()──►
                  β”‚ (TanStack)  β”‚ ◄──callbackURL──────
                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                         β”‚
                  fetch /api/auth/get-session (cookie)
                         β”‚
                         β–Ό
                  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                  β”‚   API       β”‚
                  β”‚ (Hono+Auth) β”‚ ──betterAuth()──►  PostgreSQL
                  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
  • Client-side: createAuthClient from better-auth/react β†’ typed hooks (useSession, signIn, signOut)
  • SSR: getSession() server function forwards cookies to the API β†’ validates on the server
  • Protected routes: _protected.tsx layout with beforeLoad redirecting to /sign-in
  • OAuth: Google provider β†’ API handles callback β†’ session cookie set on API domain

Hono RPC Types

End-to-end type safety between API and frontend via @repo/api-types:

apps/api/src/routes.ts ──export AppType──► packages/api-types ──► apps/dashboard
                                                 β”‚
                                          hc<AppType>("/api")
                                                 β”‚
                                          api.message.$get() ← autocompletado
  • apps/api/src/routes.ts exports AppType from routes (without Cloudflare bindings)
  • packages/api-types re-exports it for consumption by any frontend
  • Dashboard uses hc<AppType>(url) from hono/client for typed fetch calls
App Technology URL Path Purpose
API Hono + Workers /api/* Type-safe REST API
Dashboard TanStack Start /app/* Interactive admin interface
Landing Astro /* Marketing page (static)
Blog Astro /blog/* Content marketing
Docs Starlight /docs/* Technical documentation
Gateway Cloudflare Worker / Unified routing

Note: wrangler.toml files are not committed (they contain sensitive data). Copy from .example.wrangler.toml files after cloning.

cp apps/api/wrangler.toml.example apps/api/wrangler.toml
cp apps/gateway/wrangler.toml.example apps/gateway/wrangler.toml

πŸ“– Quick Start

Prerequisites

Before starting, make sure you have:

  • Node.js 20+ installed (node --version)
  • pnpm 9+ installed (pnpm --version)
  • A Cloudflare account (free)
  • A Neon database (free tier available)

New to these tools? Check our Wiki - Getting Started for detailed setup instructions.

1. Create from Template

Click "Use this template" on GitHub or clone directly:

git clone https://github.com/LionsTheme/the-edge-stack.git
cd the-edge-stack

2. Install Dependencies

pnpm install

What is pnpm? It's a fast, disk space efficient package manager. Learn more in our Wiki - Turborepo & pnpm.

3. Configure Environment Variables

Each app manages its own environment variables. The API is the only one that requires configuration:

cp apps/api/.env.example apps/api/.env
nano apps/api/.env

Required variables:

Variable Where to get it Guide
DATABASE_URL Neon Dashboard or local PostgreSQL Wiki
BETTER_AUTH_SECRET Generate with openssl rand -base64 32 Wiki
BETTER_AUTH_URL Your API URL (e.g. http://localhost:8787) Wiki
DASH_URL Your frontend URL (e.g. http://localhost:3000) Wiki
GOOGLE_CLIENT_ID Google Cloud Console Wiki
GOOGLE_CLIENT_SECRET Google Cloud Console Wiki

πŸ“– Detailed env setup: See Wiki - Variables de Entorno for step-by-step instructions with screenshots.

4. Setup Database

# Run migrations
pnpm db:migrate

# (Optional) Generate initial types
pnpm db:generate

What are migrations? They're versioned SQL files that update your database schema safely. Learn more in Wiki - Drizzle ORM.

5. Start Development

pnpm dev

This starts all apps in parallel:

App URL Description
API http://localhost:8787 Hono API with RPC
Dashboard http://localhost:3000 TanStack Start app
Landing http://localhost:4321 Astro landing page
Blog http://localhost:4322 Astro blog
Docs http://localhost:4323 Starlight documentation

πŸ“ Available Scripts

Run from the root directory:

Command Description
pnpm dev Start all apps in development mode
pnpm build Build all apps for production
pnpm db:generate Generate Drizzle migrations
pnpm db:migrate Apply database migrations
pnpm db:studio Open Drizzle Studio (GUI)
pnpm auth:generate Regenerate Better Auth Drizzle schema
pnpm clean Clean all build outputs

Run in a specific app/package:

# Start the API locally
pnpm --filter @repo/api dev

# Start the Dashboard locally
pnpm --filter @repo/dashboard dev

# Build only the UI package
pnpm --filter @repo/ui build

# Regenerate auth schema (after adding plugins/fields)
cd apps/api && pnpm dlx @better-auth/cli@latest generate \
  --config ./better-auth.config.ts \
  --output ../packages/database/src/auth-schema.ts

🌐 Deployment

Architecture Overview

User β†’ Cloudflare Gateway β†’ [API | Dashboard | Landing | Blog | Docs]
                                    β”‚
                              Neon PostgreSQL

Step-by-Step Deployment

1. API Worker

cd apps/api
wrangler deploy

2. Gateway Worker

cd apps/gateway
wrangler deploy

3. Static Apps

# Landing
cd apps/landing && pnpm build && wrangler pages deploy dist

# Blog
cd apps/blog && pnpm build && wrangler pages deploy dist

# Docs
cd apps/docs && pnpm build && wrangler pages deploy dist

4. Dashboard

cd apps/dashboard
pnpm build
wrangler pages deploy .output

πŸ“– Detailed deployment guide: See Wiki - Despliegue for production checklists, CI/CD setup, and DNS configuration.


πŸ“š Documentation

Wiki (Recommended for Beginners)

Our Wiki contains detailed guides for every technology:

In-Repo Docs

  • .env.example - Detailed environment variable explanations
  • apps/docs/ - Full documentation site built with Starlight

πŸ—οΈ Project Structure

the-edge-stack/
β”œβ”€β”€ apps/
β”‚   β”œβ”€β”€ api/                   # Hono API (Cloudflare Worker)
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ index.ts           # Entry point + auth middleware
β”‚   β”‚   β”‚   β”œβ”€β”€ routes.ts          # API routes + AppType for RPC
β”‚   β”‚   β”‚   └── lib/
β”‚   β”‚   β”‚       └── auth.ts        # Better Auth instance (per-request)
β”‚   β”‚   β”œβ”€β”€ better-auth.config.ts  # CLI config for schema generation
β”‚   β”‚   β”œβ”€β”€ .dev.vars              # Local secrets (gitignored)
β”‚   β”‚   └── wrangler.jsonc
β”‚   β”œβ”€β”€ dashboard/             # TanStack Start SSR app
β”‚   β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”‚   β”œβ”€β”€ routes/            # File-based routes
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ __root.tsx         # Root layout
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ index.tsx          # Public home
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ sign-in.tsx        # Sign-in page (Google OAuth)
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ _protected.tsx     # Protected layout (auth check)
β”‚   β”‚   β”‚   β”‚   └── _protected/
β”‚   β”‚   β”‚   β”‚       └── dashboard.tsx  # Protected dashboard
β”‚   β”‚   β”‚   β”œβ”€β”€ lib/
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ api.ts             # Hono RPC client (type-safe)
β”‚   β”‚   β”‚   β”‚   β”œβ”€β”€ auth-client.ts     # Better Auth React client
β”‚   β”‚   β”‚   β”‚   └── auth.functions.ts  # SSR session check (server fn)
β”‚   β”‚   β”‚   β”œβ”€β”€ router.tsx
β”‚   β”‚   β”‚   └── routeTree.gen.ts
β”‚   β”‚   └── vite.config.ts
β”‚   β”œβ”€β”€ landing/               # Astro landing page
β”‚   β”œβ”€β”€ blog/                  # Astro blog (MDX)
β”‚   β”œβ”€β”€ docs/                  # Starlight documentation
β”‚   └── gateway/               # Cloudflare Gateway Worker
β”œβ”€β”€ packages/
β”‚   β”œβ”€β”€ database/              # Drizzle schema, migrations, getDb()
β”‚   β”œβ”€β”€ api-types/             # Shared types for Hono RPC (AppType)
β”‚   β”œβ”€β”€ ui/                    # Shared UI components (Shadcn)
β”‚   β”œβ”€β”€ tailwind-config/       # Shared Tailwind config
β”‚   └── typescript-config/     # Shared TS configs
β”œβ”€β”€ tooling/
β”œβ”€β”€ services/
β”œβ”€β”€ .github/workflows/         # CI/CD pipelines
β”œβ”€β”€ turbo.json                 # Turborepo pipeline
β”œβ”€β”€ pnpm-workspace.yaml        # pnpm workspace config
└── .env.example               # Environment template

πŸ”— Gateway Routing

The Cloudflare Gateway Worker unifies all apps under a single domain:

Path Destination Technology
/api/* API Worker Hono + Cloudflare Workers
/app/* Dashboard TanStack Start
/blog/* Blog Astro
/docs/* Documentation Starlight
/* Landing page Astro

This eliminates CORS issues and simplifies authentication.


πŸ› οΈ Customizing the Monorepo

Not every project needs all 6 apps. Here's how to trim the boilerplate:

Remove unused apps

rm -rf apps/blog apps/docs

Update the Gateway

Three files need minor changes:

1. apps/gateway/wrangler.jsonc β€” remove unused service bindings and routes:

"services": [
  { "binding": "API", "service": "api" },
  { "binding": "DASH", "service": "dash" },
  { "binding": "LANDING", "service": "landing" }
]

2. apps/gateway/src/types.ts β€” remove unused bindings from Env:

export interface Env {
  API: Fetcher;
  DASH: Fetcher;
  LANDING: Fetcher;
  ROUTES: string;
  ASSET_PREFIXES?: string;
}

3. apps/gateway/src/router.ts β€” remove from BINDING_KEYS:

const BINDING_KEYS = new Set<BindingKey>(["API", "DASH", "LANDING"]);

TypeScript (BindingKey) keeps everything consistent β€” if a binding is missing from Env, router.ts won't compile.

Verify

pnpm install && pnpm --filter @repo/gateway typecheck

Add a new app

mkdir -p apps/shop/src

Create apps/shop/wrangler.jsonc and apps/shop/package.json as a standard Cloudflare Worker, then register it in three Gateway files:

1. apps/gateway/wrangler.jsonc β€” add binding + route:

"services": [
  { "binding": "SHOP", "service": "shop" }
]

2. apps/gateway/src/types.ts β€” add to Env:

SHOP: Fetcher;

3. apps/gateway/src/router.ts β€” add to BINDING_KEYS:

"SHOP"

TypeScript ensures all three stay in sync. Missing one β†’ compile error.


🀝 Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ™ Acknowledgments

About

Boilerplate monorepo for edge-first applications. Turborepo + Hono + Drizzle + Neon + TanStack Start + Astro + Starlight + Cloudflare Workers.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors