Relay is a full-stack e-commerce platform built with modern web technologies, featuring a hybrid database architecture with Sanity CMS for content management and MySQL for transactional data.
- Next.js 15 - React framework with App Router
- React 19 - Latest UI library with hooks and context
- TypeScript 5 - Type-safe JavaScript
- Tailwind CSS 3.4 - Utility-first CSS framework
- Lucide React - Modern icon library
- Styled Components - CSS-in-JS styling
- Sanity CMS - Headless CMS for product catalog, reviews, and content
- MySQL - Relational database hosted on Oracle Cloud
- Prisma ORM - Type-safe database toolkit and ORM
- Hybrid Architecture - Syncing between Sanity and MySQL for optimal performance
- Auth.js (NextAuth) v5 - Authentication with Google OAuth
- Rate Limiting - Upstash Redis for API protection
- Input Sanitization - Security measures for user inputs
- Middleware - Route protection and authentication
- Stripe - Payment processing with tax calculations
- EasyPost - Shipping and logistics API
- Google Maps API - Geocoding for tax calculations
- Advanced Promo System - Flexible discount rules and usage tracking
- Vercel - Deployment and hosting
- Oracle Cloud - Virtual machine for MySQL database
- Upstash Redis - Rate limiting and caching
- Sentry - Error tracking and monitoring
- Resend - Transactional email service
Relay uses a sophisticated dual-database approach:
- Sanity CMS: Stores product information, categories, brands, reviews, and media assets
- MySQL (Oracle Cloud): Handles transactional data like orders, carts, user sessions, and payment records
- Sync Layer: Custom synchronization between systems for data consistency
- Dynamic product pages with image galleries
- Advanced variant support (colors, sizes) with inventory tracking
- Real-time inventory synchronization between Sanity and MySQL
- Product reviews and ratings system
- Recently viewed products
- Advanced product filtering and search
- Persistent cart management with guest and authenticated users
- Advanced promo code system with usage limits and constraints
- Real-time tax calculation based on location
- Multiple shipping options via EasyPost integration
- Mobile-responsive design with modern UI/UX
- Wishlist/favorites functionality
- Complete order lifecycle tracking
- Stripe integration for secure payments
- Automated email notifications via Resend
- Refund processing and tracking
- Order history and detailed tracking
- Shipping label generation
- Google OAuth authentication
- Comprehensive user profile management
- Multiple shipping addresses
- Personalized recommendations
- Review system with flagging
- Rate-limited API access
- Node.js 18+
- MySQL database
- Sanity account
- Stripe account
- Google Cloud Console (for OAuth and Maps API)
Create a .env.local file with the following variables:
# Environment
NODE_ENV="development"
EASYPOST_TEST_MODE="true"
# Sanity CMS
NEXT_PUBLIC_SANITY_PROJECT_ID="your_project_id"
NEXT_PUBLIC_SANITY_DATASET="production"
SANITY_WRITE_TOKEN="your_write_token"
SANITY_WEBHOOK_SECRET="your_webhook_secret"
# Authentication
AUTH_SECRET="your_auth_secret"
AUTH_GOOGLE_ID="your_google_oauth_id"
AUTH_GOOGLE_SECRET="your_google_oauth_secret"
NEXTAUTH_URL="http://localhost:3000"
NEXTAUTH_URL_INTERNAL="http://localhost:3000"
# Database
DATABASE_URL="mysql://user:password@host:port/database"
# Redis (Rate Limiting)
UPSTASH_REDIS_REST_URL="your_redis_url"
UPSTASH_REDIS_REST_TOKEN="your_redis_token"
# Stripe
NEXT_PUBLIC_STRIPE_PUBLISHABLE_KEY="your_stripe_public_key"
STRIPE_SECRET_KEY="your_stripe_secret_key"
STRIPE_WEBHOOK_SECRET="your_webhook_secret"
# Shipping
EASYPOST_API_KEY="your_easypost_key"
EASYPOST_TRACKER_WEBHOOK_SECRET="your_tracker_secret"
# External APIs
GOOGLE_MAPS_API_KEY="your_google_maps_key"
RESEND_API_KEY="your_resend_key"
# URLs
NEXT_PUBLIC_APP_URL="http://localhost:3000"
APP_URL="http://localhost:3000"
# Monitoring
SENTRY_AUTH_TOKEN="your_sentry_token"- Clone the repository
git clone <repository-url>
cd ecommercesite- Install dependencies
npm install- Set up the database
npx prisma generate
npx prisma db push- Configure Sanity
npm run typegen- Run the development server
npm run devecommercesite/
βββ app/ # Next.js 15 App Router
β βββ (src)/ # Main application routes
β β βββ (auth)/ # Authentication pages
β β βββ (pages)/ # Main content pages
β β β βββ cart/ # Shopping cart
β β β βββ collections/ # Product collections
β β β βββ gender/ # Gender-based routing
β β β β βββ [gender]/ # Dynamic gender pages
β β β βββ kids/ # Kids section
β β β βββ product/ # Product pages
β β β βββ writeReview/ # Review submission
β β βββ layout.tsx # Main layout
β β βββ loading.tsx # Loading UI
β β βββ page.tsx # Homepage
β β βββ sale/ # Sale pages
β βββ about/ # About page
β βββ api/ # API routes
β βββ checkout/ # Checkout flow
β β βββ layout.tsx
β β βββ loading.tsx
β β βββ page.tsx
β β βββ return/ # Post-checkout handling
β βββ context/ # React contexts
β βββ fonts/ # Custom fonts
β βββ orders/ # Order management
β βββ privacy/ # Privacy policy
β βββ sentry-example-page/ # Sentry integration
β βββ studio/ # Sanity Studio
β βββ terms/ # Terms of service
β βββ favicon.ico
β βββ global-error.tsx # Global error boundary
β βββ globals.css # Global styles
β βββ layout.tsx # Root layout
βββ components/ # Reusable React components
βββ lib/ # Utility functions and configurations
βββ prisma/ # Database schema and migrations
βββ public/ # Static assets
βββ sanity/ # Sanity CMS configuration
βββ types/ # TypeScript type definitions
βββ upstash/ # Redis configuration
βββ auth.ts # Authentication configuration
βββ components.json # Shadcn/ui configuration
βββ globalTypes.ts # Global TypeScript types
βββ instrumentation.ts # Performance monitoring
βββ middleware.ts # Next.js middleware
βββ next.config.ts # Next.js configuration
βββ package.json # Dependencies and scripts
βββ postcss.config.mjs # PostCSS configuration
βββ sanity.config.ts # Sanity configuration
βββ sanity.types.ts # Generated Sanity types
βββ schema.json # Sanity schema
βββ sentry.*.config.ts # Sentry configurations
βββ tailwind.config.ts # Tailwind CSS configuration
βββ tsconfig.json # TypeScript configuration
- Sanity Query β Fetch product data, images, and reviews
- MySQL Sync β Get real-time inventory from Variant table
- User Context β Check authentication and preferences
- Cart Integration β Get user's cart and wishlist data
- Render β Combine data for optimal user experience
- Cart Validation β Verify inventory and pricing from both databases
- Promo Code Application β Validate and apply discounts
- Address Validation β Verify shipping address
- Tax Calculation β Use Google Maps + Stripe Tax API
- Payment Processing β Stripe Checkout Session
- Order Creation β Store in MySQL with Prisma
- Inventory Update β Update stock quantities
- Fulfillment β EasyPost shipping integration
- Notifications β Resend email confirmations
- Submission β User submits review via server action
- Validation β Rate limiting and content moderation
- Storage β Store in Sanity with user reference
- Auto-flagging β AI-powered content filtering
- Display β Real-time updates with optimistic UI
- User - User accounts with Google OAuth integration
- Cart/CartItem - Shopping cart with promo code support
- Order/OrderItem - Complete order tracking with snapshots
- Product/Variant - Synced product data with inventory
- Address - User shipping addresses
- PromoCode/PromoCodeUsage - Advanced promotion system
- CheckoutSession - Stripe checkout tracking
- SanitySync - Webhook synchronization logs
- Product - Main product information with variants
- Reviews - User reviews and ratings
- Categories/Collections - Product organization
- Colors/Materials/Brands - Product attributes
- Rate Limiting: Upstash Redis prevents API abuse
- Input Sanitization: All user inputs are validated and sanitized
- Authentication: Secure OAuth with session management
- CSRF Protection: Built-in Next.js security measures
- Environment Isolation: Separate test/production configurations
- Webhook Security: Signature verification for external webhooks
- Connect your repository to Vercel
- Configure environment variables in Vercel dashboard
- Set up build commands:
- Build Command:
npm run build - Install Command:
npm install - Development Command:
npm run dev
- Build Command:
- Create MySQL instance on Oracle Cloud
- Configure networking and security groups
- Update connection strings in environment variables
- Run Prisma migrations:
npx prisma db push
- Image Optimization: Next.js Image component with Sanity CDN
- Caching: Strategic use of React Suspense and data fetching
- Code Splitting: Automatic chunking with Next.js 15
- Database Indexing: Optimized queries with Prisma
- CDN: Sanity's global CDN for media assets
- Hybrid Data Strategy: Optimal data fetching from both databases
# Development server
npm run dev
# Build for production
npm run build
# Generate Prisma client
npx prisma generate
# Database studio
npx prisma studio
# Sanity type generation
npm run typegen
# Linting
npm run lint- Sentry: Error tracking and performance monitoring
- Stripe Dashboard: Payment and revenue analytics
- Sanity Studio: Content management and usage metrics
- Vercel Analytics: Web vitals and deployment metrics
- Upstash Console: Redis usage and rate limiting stats
npm run dev- Start development servernpm run build- Build for productionnpm run start- Start production servernpm run lint- Run ESLintnpm run typegen- Generate Sanity typesnpm run postinstall- Generate Prisma client
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
For support and questions:
- Check the documentation
- Review environment variable setup
- Verify database connections
- Check API key configurations
- Ensure Sanity and MySQL are properly synced
Built with β€οΈ using modern web technologies for optimal performance and user experience.