Google Antigravity Directory

The #1 directory for Google Antigravity prompts, rules, workflows & MCP servers. Optimized for Gemini 3 agentic development.

Resources

PromptsMCP ServersAntigravity RulesGEMINI.md GuideBest Practices

Company

Submit PromptAntigravityAI.directory

Popular Prompts

Next.js 14 App RouterReact TypeScriptTypeScript AdvancedFastAPI GuideDocker Best Practices

Legal

Privacy PolicyTerms of ServiceContact Us
Featured on FazierFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App ShowAI ToolzShinyLaunchMillion Dot HomepageSolver ToolsFeatured on FazierFeatured on WayfindioAntigravity AI - Featured on Startup FameFeatured on Wired BusinessFeatured on Twelve ToolsListed on Turbo0Featured on findly.toolsFeatured on Aura++That App ShowAI ToolzShinyLaunchMillion Dot HomepageSolver Tools

© 2026 Antigravity AI Directory. All rights reserved.

The #1 directory for Google Antigravity IDE

This website is not affiliated with, endorsed by, or associated with Google LLC. "Google" and "Gemini" are trademarks of Google LLC.

Antigravity AI Directory
PromptsMCPBest PracticesUse CasesLearn
Home
Prompts
Feature Flags and Rollout Patterns

Feature Flags and Rollout Patterns

Implement feature flags in Google Antigravity for gradual rollouts and A/B testing.

feature-flagsrollouttestingconfiguration
by antigravity-team
⭐0Stars
.antigravity
# Feature Flags for Google Antigravity

Implement feature flags for gradual rollouts and A/B testing.

## Database Schema

```sql
CREATE TABLE public.feature_flags (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    key TEXT UNIQUE NOT NULL,
    name TEXT NOT NULL,
    enabled BOOLEAN DEFAULT false,
    percentage INT DEFAULT 100 CHECK (percentage >= 0 AND percentage <= 100),
    conditions JSONB DEFAULT '{}'::jsonb,
    created_at TIMESTAMPTZ DEFAULT NOW()
);

CREATE TABLE public.feature_flag_overrides (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    flag_id UUID REFERENCES public.feature_flags(id) ON DELETE CASCADE,
    user_id UUID REFERENCES auth.users(id) ON DELETE CASCADE,
    enabled BOOLEAN NOT NULL,
    UNIQUE(flag_id, user_id)
);
```

## Feature Flag Service

```typescript
// lib/feature-flags.ts
import { createClient } from "@/lib/supabase/server";

const cache = new Map<string, { flag: any; expiresAt: number }>();

export async function getFlag(key: string) {
    const cached = cache.get(key);
    if (cached && Date.now() < cached.expiresAt) return cached.flag;

    const supabase = createClient();
    const { data } = await supabase.from("feature_flags").select("*").eq("key", key).single();
    if (data) cache.set(key, { flag: data, expiresAt: Date.now() + 60000 });
    return data;
}

export async function isEnabled(key: string, userId?: string): Promise<boolean> {
    const flag = await getFlag(key);
    if (!flag || !flag.enabled) return false;

    if (userId) {
        const supabase = createClient();
        const { data: override } = await supabase.from("feature_flag_overrides").select("enabled").eq("flag_id", flag.id).eq("user_id", userId).single();
        if (override) return override.enabled;
    }

    if (flag.percentage < 100) {
        const hash = hashString(userId || "anon");
        if ((hash % 100) >= flag.percentage) return false;
    }

    return true;
}

function hashString(str: string): number {
    let hash = 0;
    for (let i = 0; i < str.length; i++) { hash = ((hash << 5) - hash) + str.charCodeAt(i); hash = hash & hash; }
    return Math.abs(hash);
}
```

## React Hook

```typescript
// hooks/useFeatureFlag.ts
"use client";
import { useState, useEffect } from "react";

export function useFeatureFlag(key: string, defaultValue = false): boolean {
    const [enabled, setEnabled] = useState(defaultValue);

    useEffect(() => {
        fetch(`/api/feature-flags/${key}`).then((r) => r.json()).then(({ enabled }) => setEnabled(enabled)).catch(() => {});
    }, [key]);

    return enabled;
}
```

## Component Wrapper

```typescript
// components/FeatureFlag.tsx
"use client";
import { useFeatureFlag } from "@/hooks/useFeatureFlag";

export function FeatureFlag({ flag, children, fallback = null }: { flag: string; children: React.ReactNode; fallback?: React.ReactNode }) {
    const enabled = useFeatureFlag(flag);
    return enabled ? <>{children}</> : <>{fallback}</>;
}
```

## API Route

```typescript
// app/api/feature-flags/[key]/route.ts
import { NextRequest, NextResponse } from "next/server";
import { isEnabled } from "@/lib/feature-flags";
import { createClient } from "@/lib/supabase/server";

export async function GET(request: NextRequest, { params }: { params: { key: string } }) {
    const supabase = createClient();
    const { data: { user } } = await supabase.auth.getUser();
    const enabled = await isEnabled(params.key, user?.id);
    return NextResponse.json({ enabled });
}
```

## Admin UI

```typescript
// components/admin/FeatureFlagAdmin.tsx
"use client";
import { useState, useEffect } from "react";
import { createClient } from "@/lib/supabase/client";

export function FeatureFlagAdmin() {
    const [flags, setFlags] = useState<any[]>([]);
    const supabase = createClient();

    useEffect(() => {
        supabase.from("feature_flags").select("*").then(({ data }) => setFlags(data || []));
    }, [supabase]);

    const toggle = async (id: string, enabled: boolean) => {
        await supabase.from("feature_flags").update({ enabled }).eq("id", id);
        setFlags(flags.map((f) => (f.id === id ? { ...f, enabled } : f)));
    };

    return (
        <div>
            <h2>Feature Flags</h2>
            {flags.map((f) => (
                <div key={f.id}>
                    <span>{f.name}</span>
                    <input type="checkbox" checked={f.enabled} onChange={(e) => toggle(f.id, e.target.checked)} />
                    <span>{f.percentage}%</span>
                </div>
            ))}
        </div>
    );
}
```

## Best Practices

1. **Cache Flags**: Reduce database queries
2. **Default Safe**: Default to disabled
3. **Consistent Hashing**: Use for percentage rollouts
4. **Kill Switch**: Have instant disable capability
5. **Cleanup**: Remove old flags after rollout

When to Use This Prompt

This feature-flags prompt is ideal for developers working on:

  • feature-flags applications requiring modern best practices and optimal performance
  • Projects that need production-ready feature-flags code with proper error handling
  • Teams looking to standardize their feature-flags development workflow
  • Developers wanting to learn industry-standard feature-flags patterns and techniques

By using this prompt, you can save hours of manual coding and ensure best practices are followed from the start. It's particularly valuable for teams looking to maintain consistency across their feature-flags implementations.

How to Use

  1. Copy the prompt - Click the copy button above to copy the entire prompt to your clipboard
  2. Paste into your AI assistant - Use with Claude, ChatGPT, Cursor, or any AI coding tool
  3. Customize as needed - Adjust the prompt based on your specific requirements
  4. Review the output - Always review generated code for security and correctness
💡 Pro Tip: For best results, provide context about your project structure and any specific constraints or preferences you have.

Best Practices

  • ✓ Always review generated code for security vulnerabilities before deploying
  • ✓ Test the feature-flags code in a development environment first
  • ✓ Customize the prompt output to match your project's coding standards
  • ✓ Keep your AI assistant's context window in mind for complex requirements
  • ✓ Version control your prompts alongside your code for reproducibility

Frequently Asked Questions

Can I use this feature-flags prompt commercially?

Yes! All prompts on Antigravity AI Directory are free to use for both personal and commercial projects. No attribution required, though it's always appreciated.

Which AI assistants work best with this prompt?

This prompt works excellently with Claude, ChatGPT, Cursor, GitHub Copilot, and other modern AI coding assistants. For best results, use models with large context windows.

How do I customize this prompt for my specific needs?

You can modify the prompt by adding specific requirements, constraints, or preferences. For feature-flags projects, consider mentioning your framework version, coding style, and any specific libraries you're using.

Related Prompts

💬 Comments

Loading comments...