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
Elysia Bun Framework Patterns

Elysia Bun Framework Patterns

Build high-performance APIs with Elysia and Bun runtime in Google Antigravity

ElysiaBunTypeScriptAPIPerformance
by Antigravity Team
⭐0Stars
.antigravity
# Elysia Bun Framework for Google Antigravity

Elysia is a performant framework built for Bun runtime. This guide covers patterns for Google Antigravity IDE and Gemini 3.

## Application Setup

```typescript
// src/index.ts
import { Elysia, t } from 'elysia';
import { cors } from '@elysiajs/cors';
import { swagger } from '@elysiajs/swagger';
import { jwt } from '@elysiajs/jwt';
import { cookie } from '@elysiajs/cookie';

const app = new Elysia()
  .use(cors())
  .use(swagger({ documentation: { info: { title: 'API', version: '1.0.0' } } }))
  .use(jwt({ name: 'jwt', secret: process.env.JWT_SECRET! }))
  .use(cookie())
  .state('version', '1.0.0')
  .decorate('db', database)
  .get('/', () => 'Hello Elysia')
  .listen(3000);

console.log(`Server running at ${app.server?.hostname}:${app.server?.port}`);
```

## Type-Safe Routes

```typescript
// src/routes/users.ts
import { Elysia, t } from 'elysia';
import { db } from '../db';

export const userRoutes = new Elysia({ prefix: '/users' })
  .get('/', async () => {
    const users = await db.user.findMany({ select: { id: true, email: true, name: true } });
    return users;
  })
  .get('/:id', async ({ params: { id }, error }) => {
    const user = await db.user.findUnique({ where: { id } });
    if (!user) return error(404, 'User not found');
    return user;
  }, { params: t.Object({ id: t.String() }) })
  .post('/', async ({ body, set }) => {
    const user = await db.user.create({ data: body });
    set.status = 201;
    return user;
  }, {
    body: t.Object({
      email: t.String({ format: 'email' }),
      name: t.String({ minLength: 2 }),
      password: t.String({ minLength: 8 }),
    }),
  })
  .put('/:id', async ({ params: { id }, body, error }) => {
    const user = await db.user.update({ where: { id }, data: body });
    if (!user) return error(404, 'User not found');
    return user;
  }, {
    params: t.Object({ id: t.String() }),
    body: t.Object({
      email: t.Optional(t.String({ format: 'email' })),
      name: t.Optional(t.String({ minLength: 2 })),
    }),
  })
  .delete('/:id', async ({ params: { id }, set }) => {
    await db.user.delete({ where: { id } });
    set.status = 204;
  }, { params: t.Object({ id: t.String() }) });
```

## Authentication Plugin

```typescript
// src/plugins/auth.ts
import { Elysia, t } from 'elysia';
import { jwt } from '@elysiajs/jwt';

export const authPlugin = new Elysia({ name: 'auth' })
  .use(jwt({ name: 'jwt', secret: process.env.JWT_SECRET! }))
  .derive(async ({ jwt, cookie: { auth }, error }) => {
    const token = auth.value;
    if (!token) return { user: null };

    const payload = await jwt.verify(token);
    if (!payload) return { user: null };

    return { user: payload as { id: string; email: string } };
  })
  .macro(({ onBeforeHandle }) => ({
    isAuth(enabled: boolean) {
      if (!enabled) return;
      onBeforeHandle(({ user, error }) => {
        if (!user) return error(401, 'Unauthorized');
      });
    },
  }));

// Usage
app.use(authPlugin).get('/protected', ({ user }) => user, { isAuth: true });
```

## WebSocket Support

```typescript
// src/websocket.ts
import { Elysia, t } from 'elysia';

const connections = new Map<string, any>();

export const wsRoutes = new Elysia()
  .ws('/ws', {
    body: t.Object({ type: t.String(), payload: t.Any() }),
    open(ws) {
      const id = crypto.randomUUID();
      ws.data = { id };
      connections.set(id, ws);
      ws.send(JSON.stringify({ type: 'connected', id }));
    },
    message(ws, { type, payload }) {
      switch (type) {
        case 'broadcast':
          connections.forEach((conn) => {
            if (conn !== ws) conn.send(JSON.stringify({ type: 'message', payload }));
          });
          break;
        case 'ping':
          ws.send(JSON.stringify({ type: 'pong' }));
          break;
      }
    },
    close(ws) {
      connections.delete(ws.data.id);
    },
  });
```

## Error Handling

```typescript
// src/error.ts
import { Elysia } from 'elysia';

export const errorPlugin = new Elysia({ name: 'error' })
  .onError(({ code, error, set }) => {
    console.error(error);

    switch (code) {
      case 'VALIDATION':
        set.status = 400;
        return { error: 'Validation failed', details: error.all };
      case 'NOT_FOUND':
        set.status = 404;
        return { error: 'Not found' };
      default:
        set.status = 500;
        return { error: 'Internal server error' };
    }
  });
```

## Best Practices

1. **Type Inference**: Leverage Elysia's end-to-end type safety
2. **Plugins**: Create reusable plugins for cross-cutting concerns
3. **Validation**: Use t.Object for compile-time and runtime validation
4. **Derive**: Add computed properties to context
5. **Macros**: Create custom route modifiers
6. **WebSockets**: Built-in WS support with type safety

Google Antigravity's Gemini 3 understands Elysia patterns and generates type-safe APIs.

When to Use This Prompt

This Elysia prompt is ideal for developers working on:

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

Related Prompts

💬 Comments

Loading comments...