Production upgrade: Clerk auth, Stripe billing, analytics, PWA support
Backend & Auth: - Add @clerk/nextjs for production authentication - Create src/proxy.ts with clerkMiddleware() for route protection - Implement multi-tenant auth with role-based access control - Add Clerk components (Show, UserButton, SignInButton, SignUpButton) Billing & Payments: - Full Stripe integration (subscriptions, add-ons, customer portal) - Plan tiers: Starter 9/mo, Farm 49/mo, Enterprise 99/mo - Webhook handling for subscription events - createSubscription(), createAddonSubscription(), createCustomerPortalSession() API & Security: - Rate limiting with @upstash/ratelimit (100 req/min API, 20 req/min checkout) - Zod validation schemas for all endpoints (orders, products, campaigns, etc.) - Security headers (CSP, HSTS, X-Frame-Options) - API routes: /api/v1/ with validated, rate-limited endpoints Monitoring: - Sentry error tracking with performance monitoring - PostHog analytics for feature usage, funnels, cohorts - User activity logging and breadcrumb tracking Admin Features: - Analytics dashboard with revenue charts, customer growth, conversion funnel - Onboarding flow with 6-step interactive tour - Referral system with share tracking and reward redemption - Changelog feed with in-app notifications PWA & SEO: - Web app manifest with icons and shortcuts - Service worker for offline support and caching - Full SEO metadata, OpenGraph, Twitter cards - Structured data (JSON-LD) for organization and products Database: - Add referral_codes, changelogs, onboarding_progress tables - Add user_activity_logs, api_keys, notification_preferences - Comprehensive RLS policies for all new tables - Seed data for demo brands and products
This commit is contained in:
@@ -0,0 +1,99 @@
|
||||
# Route Commerce - Production Setup Guide
|
||||
|
||||
## Quick Start
|
||||
|
||||
```bash
|
||||
# Install dependencies
|
||||
npm install
|
||||
|
||||
# Copy environment variables
|
||||
cp .env.example .env.local
|
||||
|
||||
# Start development server
|
||||
npm run dev
|
||||
```
|
||||
|
||||
## Configuration
|
||||
|
||||
### 1. Clerk Authentication
|
||||
|
||||
1. Sign up at [Clerk](https://clerk.com)
|
||||
2. Create a new application
|
||||
3. Copy keys to `.env.local`:
|
||||
```
|
||||
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=pk_test_xxx
|
||||
CLERK_SECRET_KEY=sk_test_xxx
|
||||
```
|
||||
4. Configure middleware in `src/proxy.ts`
|
||||
|
||||
### 2. Stripe Payments
|
||||
|
||||
1. Create Stripe account
|
||||
2. Create products and prices in Stripe Dashboard
|
||||
3. Update `.env.local` with:
|
||||
```
|
||||
STRIPE_SECRET_KEY=sk_test_xxx
|
||||
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY=pk_test_xxx
|
||||
STRIPE_WEBHOOK_SECRET=whsec_xxx
|
||||
```
|
||||
|
||||
### 3. Supabase Database
|
||||
|
||||
1. Create project at [Supabase](https://supabase.com)
|
||||
2. Run migrations: `npm run migrate`
|
||||
3. Update `.env.local` with:
|
||||
```
|
||||
NEXT_PUBLIC_SUPABASE_URL=https://xxx.supabase.co
|
||||
NEXT_PUBLIC_SUPABASE_ANON_KEY=xxx
|
||||
SUPABASE_SERVICE_ROLE_KEY=xxx
|
||||
```
|
||||
|
||||
### 4. Optional Services
|
||||
|
||||
#### Sentry (Error Monitoring)
|
||||
```
|
||||
SENTRY_DSN=https://xxx@sentry.io/xxx
|
||||
```
|
||||
|
||||
#### PostHog (Analytics)
|
||||
```
|
||||
NEXT_PUBLIC_POSTHOG_API_KEY=phc_xxx
|
||||
```
|
||||
|
||||
## Deployment
|
||||
|
||||
### Vercel
|
||||
|
||||
1. Connect repository to Vercel
|
||||
2. Add all environment variables
|
||||
3. Deploy
|
||||
|
||||
### Other Platforms
|
||||
|
||||
Ensure environment variables are set before deployment.
|
||||
|
||||
## Key Files
|
||||
|
||||
- `src/proxy.ts` - Clerk middleware
|
||||
- `src/lib/stripe-billing.ts` - Stripe integration
|
||||
- `src/lib/analytics.ts` - PostHog analytics
|
||||
- `src/lib/sentry.ts` - Sentry error tracking
|
||||
- `src/components/admin/AnalyticsDashboard.tsx` - Admin dashboard
|
||||
- `src/components/onboarding/OnboardingFlow.tsx` - User onboarding
|
||||
- `src/components/referral/ReferralSystem.tsx` - Referral tracking
|
||||
- `src/components/changelog/ChangelogFeed.tsx` - Product updates
|
||||
- `supabase/migrations/` - Database schema
|
||||
|
||||
## Scripts
|
||||
|
||||
```bash
|
||||
npm run dev # Start development server
|
||||
npm run build # Production build
|
||||
npm run lint # Run ESLint
|
||||
npm run migrate # Run database migrations
|
||||
```
|
||||
|
||||
## Documentation
|
||||
|
||||
- Full documentation: [CLAUDE.md](./CLAUDE.md)
|
||||
- Launch checklist: [LAUNCH_CHECKLIST.md](./LAUNCH_CHECKLIST.md)
|
||||
Reference in New Issue
Block a user