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
PocketBase Backend Patterns

PocketBase Backend Patterns

Master PocketBase patterns for Google Antigravity IDE rapid backend development

PocketBaseBackendReal-timeTypeScript
by Antigravity AI
⭐0Stars
.antigravity
# PocketBase Backend Patterns for Google Antigravity IDE

Build backends rapidly with PocketBase using Google Antigravity IDE. This guide covers collection schemas, real-time subscriptions, hooks, custom APIs, and deployment patterns for prototypes to production.

## Collection Schema Design

```javascript
// pb_migrations/1234567890_create_collections.js
migrate((db) => {
  // Users collection (extends built-in auth)
  const users = new Collection({
    name: "users",
    type: "auth",
    schema: [
      { name: "name", type: "text", required: true, options: { min: 2, max: 100 } },
      { name: "avatar", type: "file", options: { maxSelect: 1, maxSize: 5242880, thumbs: ["100x100", "200x200"] } },
      { name: "bio", type: "text", options: { max: 500 } },
      { name: "role", type: "select", options: { values: ["user", "moderator", "admin"] } },
      { name: "preferences", type: "json" },
    ],
    listRule: "@request.auth.id != ''",
    viewRule: "@request.auth.id != ''",
    createRule: "",
    updateRule: "@request.auth.id = id",
    deleteRule: "@request.auth.id = id && @request.auth.role = 'admin'",
  });
  db.save(users);

  // Posts collection
  const posts = new Collection({
    name: "posts",
    type: "base",
    schema: [
      { name: "title", type: "text", required: true, options: { min: 5, max: 200 } },
      { name: "slug", type: "text", required: true, options: { pattern: "^[a-z0-9-]+$" } },
      { name: "content", type: "editor", required: true },
      { name: "excerpt", type: "text", options: { max: 300 } },
      { name: "coverImage", type: "file", options: { maxSelect: 1, mimeTypes: ["image/jpeg", "image/png", "image/webp"] } },
      { name: "author", type: "relation", required: true, options: { collectionId: users.id, cascadeDelete: false } },
      { name: "tags", type: "relation", options: { collectionId: "_tags", maxSelect: 10 } },
      { name: "published", type: "bool", options: { default: false } },
      { name: "publishedAt", type: "date" },
      { name: "viewCount", type: "number", options: { min: 0 } },
    ],
    indexes: ["CREATE UNIQUE INDEX idx_posts_slug ON posts (slug)", "CREATE INDEX idx_posts_published ON posts (published, publishedAt)"],
    listRule: "published = true || @request.auth.id = author.id",
    viewRule: "published = true || @request.auth.id = author.id",
    createRule: "@request.auth.id != ''",
    updateRule: "@request.auth.id = author.id",
    deleteRule: "@request.auth.id = author.id || @request.auth.role = 'admin'",
  });
  db.save(posts);

  // Comments collection
  const comments = new Collection({
    name: "comments",
    type: "base",
    schema: [
      { name: "post", type: "relation", required: true, options: { collectionId: posts.id, cascadeDelete: true } },
      { name: "author", type: "relation", required: true, options: { collectionId: users.id } },
      { name: "content", type: "text", required: true, options: { min: 1, max: 2000 } },
      { name: "parent", type: "relation", options: { collectionId: "_self" } },
    ],
    listRule: "@request.auth.id != ''",
    viewRule: "@request.auth.id != ''",
    createRule: "@request.auth.id != ''",
    updateRule: "@request.auth.id = author.id",
    deleteRule: "@request.auth.id = author.id || @request.auth.role ?= 'moderator'",
  });
  db.save(comments);
});
```

## TypeScript Client Integration

```typescript
// src/lib/pocketbase.ts
import PocketBase, { RecordService } from "pocketbase";

export interface User {
  id: string;
  email: string;
  name: string;
  avatar?: string;
  bio?: string;
  role: "user" | "moderator" | "admin";
  preferences: Record<string, unknown>;
}

export interface Post {
  id: string;
  title: string;
  slug: string;
  content: string;
  excerpt?: string;
  coverImage?: string;
  author: string;
  tags: string[];
  published: boolean;
  publishedAt?: string;
  viewCount: number;
  expand?: {
    author?: User;
    tags?: Tag[];
  };
}

export interface TypedPocketBase extends PocketBase {
  collection(idOrName: "users"): RecordService<User>;
  collection(idOrName: "posts"): RecordService<Post>;
  collection(idOrName: "comments"): RecordService<Comment>;
}

export const pb = new PocketBase(process.env.NEXT_PUBLIC_POCKETBASE_URL) as TypedPocketBase;

// Real-time subscriptions
export function subscribeToCollection<T>(
  collection: string,
  callback: (data: { action: string; record: T }) => void
) {
  return pb.collection(collection).subscribe("*", callback);
}

// File URL helper
export function getFileUrl(record: { id: string; collectionId: string }, filename: string, thumb?: string) {
  return pb.files.getUrl(record, filename, { thumb });
}
```

## React Hooks

```typescript
// src/hooks/usePocketBase.ts
import { useEffect, useState } from "react";
import { pb, type Post, type User } from "@/lib/pocketbase";

export function usePosts(options?: { filter?: string; sort?: string }) {
  const [posts, setPosts] = useState<Post[]>([]);
  const [loading, setLoading] = useState(true);
  const [error, setError] = useState<Error | null>(null);

  useEffect(() => {
    let unsubscribe: (() => void) | undefined;

    async function fetchAndSubscribe() {
      try {
        const records = await pb.collection("posts").getFullList<Post>({
          filter: options?.filter ?? "published = true",
          sort: options?.sort ?? "-publishedAt",
          expand: "author,tags",
        });
        setPosts(records);

        unsubscribe = await pb.collection("posts").subscribe<Post>("*", (e) => {
          setPosts((prev) => {
            if (e.action === "create") return [e.record, ...prev];
            if (e.action === "update") return prev.map((p) => (p.id === e.record.id ? e.record : p));
            if (e.action === "delete") return prev.filter((p) => p.id !== e.record.id);
            return prev;
          });
        });
      } catch (e) {
        setError(e as Error);
      } finally {
        setLoading(false);
      }
    }

    fetchAndSubscribe();

    return () => {
      unsubscribe?.();
    };
  }, [options?.filter, options?.sort]);

  return { posts, loading, error };
}
```

## Best Practices for Google Antigravity IDE

When using PocketBase with Google Antigravity, define strict API rules for security. Use relation fields for data normalization. Implement file handling with thumbnails. Set up real-time subscriptions for live updates. Create typed client wrappers. Let Gemini 3 generate collection schemas from your data models.

Google Antigravity excels at generating PocketBase migrations and typed SDK wrappers.

When to Use This Prompt

This PocketBase prompt is ideal for developers working on:

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

Related Prompts

💬 Comments

Loading comments...