A comprehensive demonstration of a self-built feature flag system showcasing both the library implementation and a real-world application example.
FeatureFlagDemo.mp4
This project demonstrates a complete feature flag solution with:
- @feature-flag/gatekeeper: A custom React library for managing feature flags with hooks, components, and caching
- Interactive Demo App: A clean web application showing feature flags in action with animated UI transitions
- API Integration: Backend endpoint for flag management with user-based logic
# Install dependencies
pnpm install
# Start the demo
pnpm dev
# Visit http://localhost:3000 to see the demo-
apps/web: Next.js demo application showcasing the feature flag system- Interactive table with animated column show/hide
- User switching to demonstrate different flag states
- Clean OpenAI-inspired design
- API integration with real-time updates
-
packages/gatekeeper: Feature flag React libraryuseFeatureFlagshook for flag subscriptionGateandTogglecomponents for conditional rendering- React Query integration for caching and performance
- TypeScript support with full type safety
- Real-time Updates: Flags update immediately when changed
- Performance Optimized: Smart caching with React Query
- Type Safe: Full TypeScript support throughout
- User-based Logic: Different users can have different flag states
- Smooth Animations: CSS transitions for polished UX
- User Toggle: Switch between different users to see varying flag states
- Dynamic UI: Table columns animate in/out based on feature flags
- Real-time API: Flags are fetched from
/api/flagswith user-specific logic - Smart Caching: React Query optimizes API calls and provides smooth UX
The gatekeeper library provides:
// Hook-based usage
const { flags, isLoading } = useFeatureFlags({
flags: ['newFeature', 'darkMode']
});
// Component-based usage
<Gate flag="newFeature">
<NewFeatureComponent />
</Gate>
<Toggle flag="darkMode" fallback={<LightTheme />}>
<DarkTheme />
</Toggle>GET /api/flags?userId=user-123
{
"showExtendedColumns": true,
"newFeature": false
}
# Install dependencies
pnpm install
# Start development
pnpm dev
# Build everything
pnpm build
# Run linting
pnpm lint- Next.js 15: App router with API routes
- React 19: Latest React features
- TypeScript: Full type safety
- React Query: Smart caching and state management
- Tailwind CSS: Utility-first styling
- Radix UI: Accessible component primitives