Skip to content

willy187/global-app-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

5 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🌍 Global App Template - Next.js Edition

Deploy with Vercel Powered by Supabase Open in GitHub Codespaces License: MIT TypeScript

English-First PWA with PayPal, Supabase & Viral Features
A production-ready template for building scalable web applications with authentication, payments, and social sharing.

✨ Features

πŸ” Authentication & User Management

  • Multi-Provider OAuth: Google, Apple, GitHub integration
  • Guest Mode: 3-day trial with seamless upgrade
  • Data Migration: Automatic guest-to-member data transfer
  • Session Management: Secure JWT with refresh tokens
  • Row Level Security: Supabase RLS for data protection

πŸ’³ Payment Integration

  • PayPal Subscriptions: Multiple plans (Premium, Pro)
  • Subscription Management: Cancel, upgrade, downgrade
  • Payment Security: PCI-compliant processing
  • Webhook Handling: Real-time payment status updates
  • Grace Periods: 3-day grace period for expired subscriptions

🎯 Achievement System

  • Daily Tracking: Mood-based achievement logging
  • Streak Calculation: Current and longest streaks
  • Category System: Health, Fitness, Learning, Career, etc.
  • Sharing Features: Social media integration
  • Premium Categories: Business, Finance (subscription-only)

πŸ“± Progressive Web App (PWA)

  • Offline First: Works without internet connection
  • App Installation: Native app-like experience
  • Push Notifications: Real-time updates
  • Background Sync: Offline actions sync when online
  • App Shortcuts: Quick actions from home screen

πŸš€ Performance & Scalability

  • Real-time Updates: Supabase WebSocket integration
  • Infinite Scroll: Virtualized lists for large datasets
  • Optimistic Updates: Immediate UI feedback
  • Image Optimization: Next.js built-in optimization
  • Bundle Analysis: Built-in bundle size monitoring

πŸ›‘οΈ Security & Compliance

  • Content Security Policy: XSS protection
  • HTTPS Everywhere: Secure connections only
  • Rate Limiting: Abuse prevention
  • Input Validation: Server-side validation
  • Device Fingerprinting: Bot detection

πŸš€ Quick Start

Prerequisites

  • Node.js 18+ and npm
  • Supabase account
  • PayPal Developer account
  • Google OAuth credentials

1. Clone and Setup

git clone https://github.com/your-username/global-app-template.git
cd global-app-template/variants/nextjs
npm install

2. Environment Configuration

cp .env.example .env.local

Fill in your environment variables:

# Supabase
NEXT_PUBLIC_SUPABASE_URL=your_supabase_url
NEXT_PUBLIC_SUPABASE_ANON_KEY=your_supabase_anon_key
SUPABASE_SERVICE_ROLE_KEY=your_service_role_key

# PayPal
NEXT_PUBLIC_PAYPAL_CLIENT_ID=your_paypal_client_id
PAYPAL_CLIENT_SECRET=your_paypal_client_secret

# Google OAuth
NEXT_PUBLIC_GOOGLE_CLIENT_ID=your_google_client_id
GOOGLE_CLIENT_SECRET=your_google_client_secret

# Security
JWT_SECRET=your_jwt_secret_minimum_32_characters
ENCRYPTION_KEY=your_encryption_key_32_bytes

3. Database Setup

# Run the Supabase migrations
npx supabase db reset
npx supabase db push

4. Start Development

npm run dev

Visit http://localhost:3000 to see your app!

πŸ“‹ Supabase Setup Guide

1. Create Supabase Project

  1. Go to Supabase
  2. Create new project
  3. Wait for database to be ready
  4. Copy your project URL and anon key

2. Database Schema

Run the SQL files in this order:

  1. database/schema.sql - Main schema
  2. database/policies.sql - Security policies
  3. database/functions/common_functions.sql - Utility functions

3. Enable Authentication

  1. Go to Authentication > Settings
  2. Enable Google provider
  3. Add your Google OAuth credentials
  4. Set redirect URLs:
    • Development: http://localhost:3000/auth/callback
    • Production: https://yourapp.com/auth/callback

πŸ’³ PayPal Integration Guide

1. PayPal Developer Setup

  1. Go to PayPal Developer
  2. Create new app
  3. Choose "Merchant" for subscriptions
  4. Copy Client ID and Secret

2. Create Subscription Plans

Use PayPal's API or dashboard to create these plans:

  • premium-monthly: $9.99/month
  • premium-yearly: $99.99/year
  • pro-monthly: $19.99/month
  • pro-yearly: $199.99/year

3. Webhook Configuration

Set up webhooks for these events:

  • BILLING.SUBSCRIPTION.ACTIVATED
  • BILLING.SUBSCRIPTION.CANCELLED
  • BILLING.SUBSCRIPTION.SUSPENDED
  • PAYMENT.SALE.COMPLETED

Webhook URL: https://yourapp.com/api/webhooks/paypal

πŸ—οΈ Architecture Overview

src/
β”œβ”€β”€ domain/              # Business logic
β”‚   β”œβ”€β”€ entities/        # Domain entities
β”‚   └── repositories/    # Repository interfaces
β”œβ”€β”€ application/         # Use cases
β”‚   └── usecases/       # Business use cases
β”œβ”€β”€ infrastructure/      # External concerns
β”‚   β”œβ”€β”€ auth/           # Authentication services
β”‚   β”œβ”€β”€ payment/        # Payment processing
β”‚   └── storage/        # Database integration
└── presentation/        # UI layer
    β”œβ”€β”€ components/     # React components
    β”œβ”€β”€ hooks/          # Custom React hooks
    └── pages/          # Next.js pages

Clean Architecture Benefits

  • Testability: Business logic isolated from frameworks
  • Maintainability: Clear separation of concerns
  • Scalability: Easy to add new features
  • Flexibility: Swap implementations without breaking core logic

πŸ”§ Development

Available Scripts

npm run dev          # Start development server
npm run build        # Build for production  
npm run start        # Start production server
npm run lint         # Run ESLint
npm run lint:fix     # Fix ESLint issues
npm run type-check   # TypeScript type checking
npm run test         # Run tests
npm run test:watch   # Run tests in watch mode
npm run test:coverage # Run tests with coverage

Testing

# Run all tests
npm test

# Run integration tests
npm run test:integration

# Run with coverage
npm run test:coverage

Bundle Analysis

ANALYZE=true npm run build

πŸ“± PWA Features

Installation

Users can install the app on:

  • Mobile: "Add to Home Screen"
  • Desktop: "Install App" in browser
  • iOS: Safari "Add to Home Screen"

Offline Functionality

  • βœ… View cached achievements
  • βœ… Create new achievements (syncs when online)
  • βœ… Navigate between pages
  • βœ… View profile information
  • ❌ Authentication (requires internet)
  • ❌ Payment processing (requires internet)

App Shortcuts

  • Quick Achievement: Add achievement instantly
  • Statistics: View your progress
  • Share Progress: Share achievements
  • Profile: Manage account settings

πŸš€ Deployment

Vercel (Recommended)

  1. Push code to GitHub
  2. Import project in Vercel
  3. Add environment variables
  4. Deploy automatically

Deploy with Vercel

Docker

# Build image
docker build -t global-app-template .

# Run container
docker run -p 3000:3000 global-app-template

Environment Variables for Production

NODE_ENV=production
NEXT_PUBLIC_APP_URL=https://yourapp.com
SUPABASE_SERVICE_ROLE_KEY=your_service_role_key
WEBHOOK_SECRET=your_webhook_secret

🀝 Use Cases & Examples

User Registration Flow

// Guest user registration
const guestUser = await registerGuestUseCase.execute({
  deviceId: 'device-123',
  fingerprint: deviceFingerprint
});

// Google authentication with data migration
const authenticatedUser = await googleAuthUseCase.execute({
  googleToken: 'google-token',
  deviceInfo: deviceInfo,
  guestDataToMigrate: {
    guestToken: guestUser.tempToken,
    achievements: guestAchievements
  }
});

Achievement Creation

// Create new achievement
const achievement = await createAchievementUseCase.execute({
  userId: 'user-123',
  title: 'Completed morning workout',
  description: '30 minutes of cardio and strength training',
  category: 'fitness',
  moodLevel: 4
});

PayPal Subscription

// PayPal subscription component
<PayPalSubscriptionButton
  planId="premium-monthly"
  onSuccess={(subscriptionId, details) => {
    console.log('Subscription created:', subscriptionId);
  }}
  onError={(error) => {
    console.error('Payment failed:', error);
  }}
  onCancel={() => {
    console.log('Payment cancelled');
  }}
/>

πŸ› οΈ Customization

Adding New Authentication Provider

  1. Update useSupabaseAuth hook
  2. Add provider to Supabase settings
  3. Create provider-specific use case
  4. Add UI components

Creating Custom Achievement Categories

// Update Achievement entity
const CUSTOM_CATEGORIES = ['work', 'hobby', 'family'];

// Update validation in CreateAchievementUseCase
private validateCategory(category: string) {
  const validCategories = [...DEFAULT_CATEGORIES, ...CUSTOM_CATEGORIES];
  // ... validation logic
}

Adding New Subscription Plans

// Update subscription plans
const SUBSCRIPTION_PLANS = {
  'enterprise-monthly': { price: 49.99, interval: 'month' },
  'enterprise-yearly': { price: 499.99, interval: 'year' }
};

πŸ“Š Project Statistics

  • 34 files created
  • 5,915+ lines of TypeScript code
  • 100% TypeScript coverage
  • Clean Architecture implementation
  • Production-ready configuration

❓ Troubleshooting

Common Issues

Build Errors

# Clear Next.js cache
rm -rf .next

# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install

Supabase Connection Issues

  • Verify environment variables
  • Check Supabase service status
  • Ensure correct RLS policies

PayPal Integration Issues

  • Verify webhook endpoints
  • Check PayPal app settings
  • Monitor webhook delivery logs

PWA Issues

  • Clear browser cache
  • Check service worker registration
  • Verify HTTPS in production

πŸ“ License

MIT License - see LICENSE for details.

🀝 Contributing

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

πŸ“ž Support


Built with ❀️ using Next.js, Supabase, and PayPal

Next.js Supabase PayPal TypeScript Tailwind CSS

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors