A modern e-commerce demo application built to showcase LaunchDarkly's feature flag capabilities at conferences and events.
ToggleStore is a Next.js application that simulates a real-world online store selling LaunchDarkly-themed merchandise. It's designed for live demonstrations of feature management, experimentation, and progressive rollouts using LaunchDarkly.
- ποΈ E-commerce Storefront - Browse products, add to cart, and checkout
- π― Feature Flags - Ready for LaunchDarkly integration
- π Authentication - Google OAuth with LaunchDarkly domain restriction
- π€ AI Chatbot - Customer support assistant (placeholder)
- π¨ Modern UI - Dark theme with beautiful gradients
- π± Responsive Design - Works on all devices
- Framework: Next.js 15 with App Router
- Language: TypeScript
- Styling: Tailwind CSS v4
- UI Components: shadcn/ui
- Authentication: NextAuth.js v5
- Feature Flags: LaunchDarkly
- Node.js 18+ and npm
- Google OAuth credentials (optional, for admin access)
- LaunchDarkly account (optional, for feature flags)
- Clone the repository
git clone <your-repo-url>
cd ToggleStore- Install dependencies
npm install- Set up environment variables
Copy .env.example to .env.local and fill in your credentials:
cp .env.example .env.localEdit .env.local with your values:
# NextAuth
NEXTAUTH_URL=http://localhost:3000
NEXTAUTH_SECRET=<generate-with-openssl-rand-base64-32>
# Google OAuth (optional)
GOOGLE_CLIENT_ID=<your-google-client-id>
GOOGLE_CLIENT_SECRET=<your-google-client-secret>
# LaunchDarkly (optional)
LAUNCHDARKLY_SDK_KEY=<your-server-sdk-key>
NEXT_PUBLIC_LAUNCHDARKLY_CLIENT_ID=<your-client-side-id>- Run the development server
npm run dev- Open your browser
Navigate to http://localhost:3000
- Go to Google Cloud Console
- Create a new project or select existing one
- Enable Google+ API
- Create OAuth 2.0 credentials
- Add authorized redirect URI:
http://localhost:3000/api/auth/callback/google - Copy Client ID and Client Secret to
.env.local
Note: Only @launchdarkly.com emails can authenticate. This is enforced in the auth configuration.
- Sign up at LaunchDarkly
- Create a new project
- Get your SDK keys:
- Server-side SDK key: Account Settings β Projects β Your Project β Environments
- Client-side ID: Same location as above
- Add keys to
.env.local
ToggleStore/
βββ app/ # Next.js app directory
β βββ api/ # API routes
β β βββ auth/ # NextAuth endpoints
β βββ auth/ # Auth pages (signin, error)
β βββ layout.tsx # Root layout with providers
β βββ page.tsx # Main storefront page
βββ components/ # React components
β βββ ui/ # shadcn/ui components
β βββ header.tsx # Header with nav and cart
β βββ product-card.tsx # Product card component
β βββ cart.tsx # Shopping cart drawer
β βββ chatbot.tsx # AI chatbot component
βββ lib/ # Utilities and configs
β βββ auth.ts # NextAuth configuration
β βββ launchdarkly/ # LaunchDarkly utilities
β βββ server.ts # Server-side SDK
β βββ client.tsx # Client-side SDK
βββ data/ # Static data
β βββ products.json # Product catalog
βββ types/ # TypeScript types
β βββ product.ts # Product and cart types
βββ public/ # Static assets
β βββ assets/ # Images and icons
β βββ products/ # Product images
β βββ icons/ # UI icons
β βββ chatbot/ # Chatbot assets
β βββ backgrounds/ # Background effects
βββ .cursorrules # AI assistant guidelines
Product data is stored in /data/products.json. To add product images:
- Add images to
/public/assets/products/ - Update the
imagesfield inproducts.json:
{
"id": "prod-001",
"name": "Super fun Dev T-shirt",
"images": {
"main": "/assets/products/tshirt-001.png",
"thumbnail": "/assets/products/tshirt-001-thumb.png"
}
// ...
}Here are some feature flags you can implement:
import { getFlagValue } from "@/lib/launchdarkly/server"
export default async function MyPage() {
const showNewFeature = await getFlagValue(
"new-feature",
{ kind: "user", key: "anonymous" },
false
)
return showNewFeature ? <NewFeature /> : <OldFeature />
}"use client"
import { useFlag } from "@/lib/launchdarkly/client"
export default function MyComponent() {
const showNewFeature = useFlag("new-feature", false)
return showNewFeature ? <NewFeature /> : <OldFeature />
}Here are some feature flag demonstrations you can implement:
- Product Recommendations - Show personalized products
- Pricing Experiments - A/B test different prices
- New Product Launch - Gradually roll out new products
- Cart Features - Toggle express checkout, gift options
- Chatbot - Enable/disable AI assistant
- Search - Toggle advanced search features
- Inventory - Show/hide out-of-stock items
- Themes - Switch between seasonal themes
- Targeting - Different experiences per user segment
- Public Access: Anyone can browse the storefront
- Admin Access: Only
@launchdarkly.comemails can sign in - Protected routes redirect to signin if not authenticated
# Development server
npm run dev
# Production build
npm run build
# Start production server
npm start
# Linting
npm run lintnpx shadcn@latest add <component-name>- Push your code to GitHub
- Import project in Vercel
- Add environment variables
- Deploy
Build the production bundle:
npm run buildThen deploy the .next folder according to your platform's instructions.
- Check that your SDK keys are correct
- Ensure client-side ID starts with
NEXT_PUBLIC_ - Check browser console for errors
- Verify Google OAuth credentials
- Check redirect URIs match exactly
- Ensure
NEXTAUTH_SECRETis set
- Run
npm installto ensure all dependencies are installed - Check Node.js version (requires 18+)
- Clear
.nextfolder and rebuild
This is a demo application. Feel free to fork and customize for your own demonstrations.
MIT
For issues or questions, please open an issue on GitHub or contact the LaunchDarkly team.
Built with β€οΈ for LaunchDarkly demonstrations