Overview

TurboStack includes a comprehensive .ai/rules/ directory containing development guidelines that help AI coding assistants (like GitHub Copilot, Cursor, Windsurf, Claude) understand your project’s patterns and conventions.
Why AI Rules? These guidelines ensure that AI assistants generate code that matches your project’s architecture, coding style, and best practices automatically.

📁 Available Rules Files

Core Guidelines

Specialized Guidelines

material-symbols:perm-media

media.md

Media upload service with provider pattern (UploadThing, Cloudinary)
material-symbols:shield-lock

security.md

Security best practices, authentication, and authorization
material-symbols:code

api-response-format.md

Standardized API response structure
material-symbols:mail

email-templates.md

React Email template development guide
material-symbols:api

swagger.md

OpenAPI/Swagger documentation standards
material-symbols:auto-fix

clean-code.md

Clean code principles and best practices

🤖 How AI Assistants Use These Rules

When you ask an AI assistant to help with your code, it automatically reads the relevant .ai/rules/ files to:
  1. Understand your architecture - Routes, services, database patterns
  2. Follow your conventions - Naming, file structure, import paths
  3. Match your coding style - TypeScript patterns, error handling
  4. Use the right tools - Correct libraries and frameworks
  5. Generate consistent code - Same patterns across the codebase

Example: Adding a New API Endpoint

Without AI Rules:
// AI might generate inconsistent code
app.get("/api/products", (req, res) => {
  const products = await db.products.findAll();
  res.json(products); // ❌ No standard response format
});
With AI Rules (backend.md):
// AI generates code following your patterns
export const productRoutes = new Elysia({ prefix: "/products" }).get(
  "/",
  async () => {
    const products = await productService.getAll();
    return { success: true, data: products }; // ✅ Standard format
  },
  {
    detail: {
      tags: ["Products"],
      summary: "List all products",
      // ✅ Auto-includes Swagger docs
    },
  },
);

📖 Using AI Rules in Your IDE

GitHub Copilot / VS Code

1

Enable Workspace Instructions

Copilot automatically reads .ai/rules/ when you reference specific files or patterns.
2

Reference Rules in Comments

// Following backend.md patterns for route creation
export const userRoutes = new Elysia({ prefix: "/users" })
3

Ask Specific Questions

  • “Create a new route following backend.md guidelines”
  • “Add Swagger docs as described in backend.md”
  • “Follow the media.md provider pattern”

Cursor IDE

1

Configure Rules Directory

Cursor automatically detects .ai/rules/ and .cursor/rules/ directories.
2

Reference in Chat

Use @rules or mention specific files: - “@backend.md create a new products endpoint” - “@frontend.md add a server component”
3

Apply to Current File

Cursor applies relevant rules based on your current file location automatically.

Windsurf

1

Auto-Detection

Windsurf reads .windsurfrules which references .ai/rules/.
2

Contextual Suggestions

Suggestions automatically follow your project’s patterns from the rules.

🎯 Quick Reference by Task

Primary File: .ai/rules/backend.mdWhat You’ll Learn:
  • Elysia.js route patterns
  • Service layer architecture
  • Swagger/OpenAPI documentation
  • Authentication with Better-auth
  • Rate limiting
  • Error handling
Example Request:
“Create a new products API endpoint with CRUD operations following backend.md”
Primary File: .ai/rules/frontend.mdWhat You’ll Learn:
  • Next.js 16 App Router patterns
  • Server vs Client Components
  • Zustand state management
  • shadcn/ui component usage
  • Form handling with React Hook Form
Example Request:
“Create a dashboard page following frontend.md patterns with server components”
Primary File: .ai/rules/database.mdWhat You’ll Learn:
  • Prisma schema patterns
  • Creating migrations
  • Query optimization
  • Relation handling
Example Request:
“Add a products table to the schema following database.md conventions”
Primary File: .ai/rules/docs.mdWhat You’ll Learn:
  • Mintlify MDX format
  • Component usage (Cards, Tabs, Steps)
  • Frontmatter structure
  • Code examples
Example Request:
“Create documentation for the products API following docs.md guidelines”
Primary File: .ai/rules/media.mdWhat You’ll Learn:
  • Provider pattern implementation
  • UploadThing integration
  • Cloudinary integration
  • Media transformations
Example Request:
“Implement image upload using the provider pattern from media.md”
Primary File: .ai/rules/security.mdWhat You’ll Learn:
  • Authentication patterns
  • Authorization middleware
  • Input validation
  • Data sanitization
Example Request:
“Add role-based access control following security.md”

💡 Best Practices for Working with AI Rules

✅ DO

material-symbols:target

Be Specific

Reference exact rule files in your requests: - “Following backend.md, create…” - “Using patterns from frontend.md…”
material-symbols:fact-check

Check Generated Code

Always review AI-generated code to ensure it matches the rules and your needs.
material-symbols:sync

Update Rules

When you change patterns, update the corresponding .ai/rules/ file so future generations stay consistent.
material-symbols:chat

Provide Context

Include the current file path or feature you’re working on for better context.

❌ DON’T

  • Don’t blindly accept AI suggestions without understanding them - Don’t skip reading the rules files yourself - they’re valuable documentation - Don’t forget to update rules when you change project patterns - Don’t ignore validation - AI can make mistakes

🔄 Keeping Rules Updated

The AI rules are living documents that should evolve with your project:
1

After Major Changes

When you refactor architecture or change patterns, update the relevant .ai/rules/ file.
2

Document New Patterns

If you create a new pattern (like a new service structure), add it to the rules.
3

Review Periodically

Every few months, review rules files to ensure they match your current codebase.
4

Team Alignment

Make sure all team members know about and follow the rules files.

📚 Complete Rules Index

FilePurposeWhen to Use
backend.mdBackend API developmentCreating routes, services, authentication
frontend.mdFrontend UI developmentBuilding pages, components, forms
docs.mdDocumentation writingAdding MDX documentation
database.mdDatabase patternsSchema changes, migrations, queries
media.mdMedia/upload serviceFile uploads, image handling
security.mdSecurity practicesAuth, validation, permissions
api-response-format.mdAPI response structureStandardizing API responses
email-templates.mdEmail templatesCreating React Email templates
swagger.mdOpenAPI docsAPI documentation
clean-code.mdCode qualityGeneral coding standards
structure.mdProject structureUnderstanding monorepo layout
technologies.mdTech stackTechnology choices and versions
path-aliases.mdImport pathsUsing @/ path aliases

🎓 Example Workflows

Workflow 1: Adding a New Feature

1. Read relevant rule file (e.g., backend.md)
2. Ask AI: "Following backend.md, create a products API with CRUD operations"
3. AI generates routes, services, and Swagger docs
4. Review and test generated code
5. Commit changes

Workflow 2: Fixing a Bug

1. Identify the layer (route, service, database)
2. Reference appropriate rule file
3. Ask AI: "Fix this validation error following backend.md patterns"
4. AI suggests fix matching project conventions
5. Apply and test

Workflow 3: Refactoring

1. Update the relevant .ai/rules/ file with new pattern
2. Ask AI: "Refactor this code to match updated backend.md"
3. AI refactors using new conventions
4. Update other files consistently

🔗 IDE-Specific Configurations

Cursor reads from .cursor/rules/*.mdc which links to .ai/rules/. Usage: - @backend.md in chat - Auto-applies rules to current file

🚀 Getting Started

1

Browse the Rules

Explore the .ai/rules/ directory to see what’s available.
2

Read Relevant Files

Read the rules files relevant to your current task.
3

Reference in AI Requests

Mention specific rule files when asking AI for help.
4

Verify Generated Code

Always review and test AI-generated code before committing.


Pro Tip: The more specific you are when referencing rules files, the better the AI-generated code will match your project’s patterns!