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
Notification System Patterns

Notification System Patterns

Build in-app and push notification systems in Google Antigravity with real-time delivery.

notificationsrealtimepushsupabase
by antigravity-team
⭐0Stars
.antigravity
# Notification Systems for Google Antigravity

Build comprehensive notification systems with in-app, email, and push notifications.

## Database Schema

```sql
CREATE TABLE public.notifications (
    id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
    user_id UUID REFERENCES auth.users(id) ON DELETE CASCADE,
    type TEXT NOT NULL,
    title TEXT NOT NULL,
    body TEXT,
    data JSONB DEFAULT '{}'::jsonb,
    read BOOLEAN DEFAULT false,
    created_at TIMESTAMPTZ DEFAULT NOW()
);

CREATE INDEX idx_notifications_user ON public.notifications(user_id, created_at DESC);
CREATE INDEX idx_notifications_unread ON public.notifications(user_id) WHERE read = false;

ALTER TABLE public.notifications ENABLE ROW LEVEL SECURITY;
CREATE POLICY "Users can view own notifications" ON public.notifications FOR SELECT USING (auth.uid() = user_id);
CREATE POLICY "Users can update own notifications" ON public.notifications FOR UPDATE USING (auth.uid() = user_id);
```

## Notification Service

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

interface CreateNotificationParams {
    userId: string;
    type: string;
    title: string;
    body?: string;
    data?: Record<string, unknown>;
}

export async function createNotification(params: CreateNotificationParams) {
    const supabase = createClient();
    const { data, error } = await supabase.from("notifications").insert(params).select().single();
    if (error) throw error;
    return data;
}

export async function markAsRead(notificationId: string, userId: string) {
    const supabase = createClient();
    await supabase.from("notifications").update({ read: true }).eq("id", notificationId).eq("user_id", userId);
}

export async function markAllAsRead(userId: string) {
    const supabase = createClient();
    await supabase.from("notifications").update({ read: true }).eq("user_id", userId).eq("read", false);
}

export async function getUnreadCount(userId: string): Promise<number> {
    const supabase = createClient();
    const { count } = await supabase.from("notifications").select("*", { count: "exact", head: true }).eq("user_id", userId).eq("read", false);
    return count || 0;
}
```

## Notification Hook

```typescript
// hooks/useNotifications.ts
"use client";

import { useState, useEffect } from "react";
import { createClient } from "@/lib/supabase/client";

interface Notification {
    id: string;
    type: string;
    title: string;
    body?: string;
    data: Record<string, unknown>;
    read: boolean;
    created_at: string;
}

export function useNotifications(userId: string) {
    const [notifications, setNotifications] = useState<Notification[]>([]);
    const [unreadCount, setUnreadCount] = useState(0);
    const supabase = createClient();

    useEffect(() => {
        // Fetch initial notifications
        supabase.from("notifications").select("*").eq("user_id", userId).order("created_at", { ascending: false }).limit(50).then(({ data }) => {
            setNotifications(data || []);
            setUnreadCount(data?.filter((n) => !n.read).length || 0);
        });

        // Subscribe to new notifications
        const channel = supabase.channel("notifications").on("postgres_changes", { event: "INSERT", schema: "public", table: "notifications", filter: `user_id=eq.${userId}` }, (payload) => {
            setNotifications((prev) => [payload.new as Notification, ...prev]);
            setUnreadCount((prev) => prev + 1);
        }).subscribe();

        return () => { channel.unsubscribe(); };
    }, [userId, supabase]);

    const markAsRead = async (id: string) => {
        await supabase.from("notifications").update({ read: true }).eq("id", id);
        setNotifications((prev) => prev.map((n) => (n.id === id ? { ...n, read: true } : n)));
        setUnreadCount((prev) => Math.max(0, prev - 1));
    };

    const markAllRead = async () => {
        await supabase.from("notifications").update({ read: true }).eq("user_id", userId).eq("read", false);
        setNotifications((prev) => prev.map((n) => ({ ...n, read: true })));
        setUnreadCount(0);
    };

    return { notifications, unreadCount, markAsRead, markAllRead };
}
```

## Notification Bell Component

```typescript
// components/NotificationBell.tsx
"use client";

import { useState, useRef, useEffect } from "react";
import { useNotifications } from "@/hooks/useNotifications";
import { formatDistanceToNow } from "date-fns";

export function NotificationBell({ userId }: { userId: string }) {
    const { notifications, unreadCount, markAsRead, markAllRead } = useNotifications(userId);
    const [open, setOpen] = useState(false);
    const ref = useRef<HTMLDivElement>(null);

    useEffect(() => {
        const handleClick = (e: MouseEvent) => {
            if (ref.current && !ref.current.contains(e.target as Node)) setOpen(false);
        };
        document.addEventListener("mousedown", handleClick);
        return () => document.removeEventListener("mousedown", handleClick);
    }, []);

    return (
        <div ref={ref} className="notification-bell">
            <button onClick={() => setOpen(!open)} className="bell-button">
                🔔 {unreadCount > 0 && <span className="badge">{unreadCount}</span>}
            </button>
            {open && (
                <div className="notification-dropdown">
                    <div className="header">
                        <span>Notifications</span>
                        {unreadCount > 0 && <button onClick={markAllRead}>Mark all read</button>}
                    </div>
                    <div className="notification-list">
                        {notifications.length === 0 ? (
                            <p className="empty">No notifications</p>
                        ) : (
                            notifications.map((n) => (
                                <div key={n.id} className={`notification-item ${n.read ? "" : "unread"}`} onClick={() => markAsRead(n.id)}>
                                    <strong>{n.title}</strong>
                                    {n.body && <p>{n.body}</p>}
                                    <span className="time">{formatDistanceToNow(new Date(n.created_at))} ago</span>
                                </div>
                            ))
                        )}
                    </div>
                </div>
            )}
        </div>
    );
}
```

## Push Notification Setup

```typescript
// lib/push-notifications.ts
export async function requestNotificationPermission(): Promise<boolean> {
    if (!("Notification" in window)) return false;
    if (Notification.permission === "granted") return true;
    if (Notification.permission === "denied") return false;
    const permission = await Notification.requestPermission();
    return permission === "granted";
}

export async function subscribeToPush(userId: string) {
    const registration = await navigator.serviceWorker.ready;
    const subscription = await registration.pushManager.subscribe({
        userVisibleOnly: true,
        applicationServerKey: process.env.NEXT_PUBLIC_VAPID_PUBLIC_KEY,
    });

    await fetch("/api/push/subscribe", {
        method: "POST",
        headers: { "Content-Type": "application/json" },
        body: JSON.stringify({ userId, subscription }),
    });
}
```

## Best Practices

1. **Real-time**: Use Supabase Realtime for instant updates
2. **Batching**: Batch notifications to avoid spam
3. **Preferences**: Let users control notification settings
4. **Cleanup**: Delete old notifications periodically
5. **Analytics**: Track notification engagement

When to Use This Prompt

This notifications prompt is ideal for developers working on:

  • notifications applications requiring modern best practices and optimal performance
  • Projects that need production-ready notifications code with proper error handling
  • Teams looking to standardize their notifications development workflow
  • Developers wanting to learn industry-standard notifications 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 notifications 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 notifications 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 notifications 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 notifications projects, consider mentioning your framework version, coding style, and any specific libraries you're using.

Related Prompts

💬 Comments

Loading comments...