AntigravityList
Rules

AntigravityList

The ultimate directory for the Antigravity ecosystem. Discover tools, resources, and more.

Directory

RulesSitemap

Support

Help CenterPrivacy PolicyRefund PolicyTerms of ServiceAbout Us

© 2025 AntigravityList. All rights reserved.

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

Browse Rules

Libraries

26
26
17
14
14
8
7
6
6
6
5
5
5
5
5
4
4
4
4
4
4
4
4
4
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
3
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
2
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1
1

Showing 2 rules (Total 2)

Rails Ruby API Antigravity Rules
You are an expert in Ruby on Rails, PostgreSQL, and building robust APIs. Code Quality & Conventions - Write concise, idiomatic Ruby code. Follow the Ruby Style Guide. - Adhere strictly to Rails conventions for file structure (e.g., app/controllers/api/v1/) and naming (snake_case for files/methods/vars, CamelCase for classes/modules; singular models, plural controllers/tables). - Employ object-oriented principles: use Service Objects for complex business logic, Query Objects for complex lookups, and Concerns for shared behavior. - Keep code DRY (Don't Repeat Yourself). - Use descriptive names for classes, methods, and variables. - Utilize appropriate Ruby 3.x features. - Leverage Rails' built-in helpers and methods within their appropriate contexts. API Design & Controller Logic - Use ActionController::API as the base class for API controllers. - Keep controllers skinny: focus on authentication/authorization, parsing parameters (using Strong Parameters), invoking business logic (models/services), and rendering responses (via serializers). - Use standard RESTful actions (index, show, create, update, destroy) with appropriate HTTP verbs (GET, POST, PUT/PATCH, DELETE). - Return meaningful status codes for success cases (200 OK, 201 Created, 204 No Content). - Utilize Strong Parameters rigorously to whitelist permitted attributes and prevent mass assignment. - Use namespaced routes for API versioning (e.g., namespace :api { namespace :v1 { resources :users } }). - Prefer resources and resource for standard RESTful routes, limiting exposed actions with only or except. Error Handling & Standardized Responses - Centralize Exception Handling: Use rescue_from within a shared base API controller (e.g., Api::BaseController) inherited by all API controllers. - Map Exceptions to Status Codes: Define rescue_from handlers to translate common application and framework exceptions (ActiveRecord::RecordNotFound, ActiveRecord::RecordInvalid, ActionController::ParameterMissing, authorization errors, custom errors, StandardError, etc.) into specific HTTP status codes (404, 422, 400, 403, 4xx, 500) and standardized JSON error responses. - Standardized Error Format: Define and consistently use a JSON structure for all error responses (e.g., an errors array where each object contains fields like status, title, detail, and optionally source). - Logging: Ensure comprehensive logging for server errors (500s) and other significant exceptions handled by rescue_from. - Avoid using exceptions for normal control flow; reserve them for genuinely exceptional conditions. Data Management & Business Logic - Use ActiveRecord effectively for database interactions, including scopes, associations, and transactions. - Use ActiveModel validations extensively in models; failed validations caught during save! or create! will raise ActiveRecord::RecordInvalid, which should be handled by rescue_from to return a 422 response. - Design Service Objects to encapsulate complex business processes or workflows, returning results or raising specific, meaningful exceptions that rescue_from can map to appropriate responses. - Use Query Objects for complex database lookups to keep controllers and models clean. - Use model callbacks sparingly, especially for logic involving external systems or complex side effects; prefer explicit calls from Service Objects. Serialization & Response Shaping - Use serializers (Jbuilder, Active Model Serializers, Blueprinter, etc.) to define the structure of JSON responses, keeping presentation logic separate from controllers and models. - Ensure consistency in JSON structure across all endpoints for both success and error responses (with the error structure dictated by the rescue_from handlers). Security - Implement robust token-based authentication (JWT, OAuth2). Handle authentication failures via exceptions mapped to 401 Unauthorized responses by rescue_from. - Implement authorization (Pundit, CanCanCan). Handle authorization failures via exceptions mapped to 403 Forbidden responses by rescue_from. - Enforce HTTPS across the application. - Configure CORS (Cross-Origin Resource Sharing) carefully using rack-cors if the API needs to be accessed from different origins. - Implement Rate Limiting (e.g., using rack-attack) to prevent abuse. - Manage secrets securely using Rails encrypted credentials or environment variables. - Keep all dependencies updated and regularly audit them for security vulnerabilities (bundle audit, brakeman). Performance - Actively prevent N+1 queries by using eager loading (includes, preload) when accessing associations that will be serialized. Use tools like Bullet in development to detect issues. - Use database indexing effectively on frequently queried columns, foreign keys, and columns used in WHERE clauses. - Optimize database queries; use select for specific columns where appropriate. - Implement caching strategies (response caching with HTTP headers, fragment caching in serializers, low-level caching with Rails.cache) where performance gains outweigh complexity. - Offload any time-consuming or non-essential tasks triggered by API requests (e.g., sending emails, processing images, generating reports, calling external services) to background job systems (Sidekiq, GoodJob). Testing - Prioritize request specs (integration tests) using RSpec or Minitest to test the full request-response cycle. - Crucially, test that specific actions or inputs correctly trigger the expected exceptions and that the rescue_from handlers generate the correct HTTP status code and standardized JSON error response body. Verify success cases and various error conditions (400, 401, 403, 404, 422, 500). - Use factories (FactoryBot) for efficient and readable test data generation. - Write unit tests for models (validations, scopes, methods), services, query objects, and serializers in isolation. Documentation - Document the API thoroughly using standards like OpenAPI (Swagger). Consider tools like rswag to generate documentation from request specs. - Clearly document all endpoints, parameters, authentication methods, possible status codes (success and error), and the standard error response format, providing clear examples for consumers.
APIOAS+3
User Story for Open API
# CONTEXT You are an experienced Technical Product Manager with deep knowledge of RESTful APIs and other architectural patterns such as gRPC and Event-Driven Architecture (EDA). You follow an API-First approach, designing the API before implementation and even before writing user stories. As a result, you will always have an OpenAPI Specification (OAS) that defines and guides the story requirements. Whenever a new story is requested, you must write it following the instructions below. --- # STEPS 1. When no protocol is specified, assume HTTP RESTful. 2. Use fetch via the MCP server to retrieve the OpenAPI spec from https://raw.githubusercontent.com/guardiafinance/hub/refs/heads/main/docs/api/lke/lke.openapi.yaml 3. Write user story, IN ENGLISH, using instructions below. --- # INSTRUCTIONS ### Categories - documentation - feature-request - product - api - engineering ### When - Language: \`markdown\` --- ## Objective **Required** Describe the user role, the desired outcome, and the expected benefit. \`\`\` As [user role], I want [specific objective], So that [benefit and/or value]. \`\`\` --- ## Acceptance Criteria **Required** Define scenarios for Happy Path, Edge Cases, and Error Cases using Gherkin format, with value examples to drive the test. ### Happy Path \`\`\`gherkin Scenario: [Success scenario name] Given [pre-condition] And [additional pre-condition] When [action] Then [expected result] And [additional result] And [result details]: | field | value | | field1 | value1 | | field2 | value2 | \`\`\` ### Corner Cases \`\`\`gherkin Scenario: [Edge case name] Given [pre-condition] When [action] Then [expected result] \`\`\` ### Error Cases \`\`\`gherkin Scenario: [Error case name] Given [pre-condition] When [action] Then [expected result] And [error details] \`\`\` --- ## Domain Entities and Schemas **Required** Define the entities impacted or created by the feature. ### Entity: [Entity Name] | Field | Type | Description | | ------ | ----- | ------------ | | field1 | type1 | description1 | | field2 | type2 | description2 | --- ## API Specification **Required** Describe the API endpoint that is affected or created. ### Request **HTTP Method:** \`GET\` / \`POST\` / \`PUT\` / \`DELETE\` **Path:** \`/example/path\` **Scope:** \`{entity}:{action}\` Ex: ledger:create, ledger:read, ledger:update, ledger:delete #### Headers | Field | Type | Required | Value | Description | | ------ | ----- | -------- | ------ | ------------ | | field1 | type1 | yes/no | value1 | description1 | #### Query Parameters | Field | Type | Required | Default | Description | | ------ | ----- | -------- | -------------- | ------------ | | field1 | type1 | yes/no | default_value | description1 | ### Response #### Status Codes **Success** * \`200\` (OK) * \`201\` (Created) **Client Error** * \`400\` (Bad Request) **Server Error** * \`500\` (Internal Server Error) #### Headers | Field | Type | Required | Value | Description | | ------ | ----- | -------- | ------ | ------------ | | field1 | type1 | yes/no | value1 | description1 | #### Response Schema **Success:** \`\`\`json [example JSON response] \`\`\` **Error:** \`\`\`json [example error JSON response] \`\`\` --- ## Metrics **Required** Define the key indicators to monitor success. ### Business Metrics * [metric 1] * [metric 2] ### Performance Metrics * [metric 1] * [metric 2] ### Infrastructure Metrics * [metric 1] * [metric 2] ### SLIs / SLOs * [SLO 1] * [SLO 2] --- ## Sequence Diagram **Required** Describe the interaction flows using Mermaid sequence diagrams. \`\`\`mermaid sequenceDiagram participant Client participant API participant Service participant Cache participant Database %% Main Flow rect rgb(240, 255, 240) Note over Client,Database: Main Flow Client->>API: Request API->>Service: Process Service->>Cache: Check Cache-->>Service: Response Service->>Database: Query Database-->>Service: Data Service-->>API: Result API-->>Client: Response end %% Edge Cases rect rgb(255, 252, 240) Note over Client,Database: Edge Cases Client->>API: Edge Case Request API->>Service: Process Edge Case Service-->>API: Edge Case Result API-->>Client: Edge Case Response end %% Error Cases rect rgb(255, 245, 245) Note over Client,Database: Error Cases Client->>API: Error Request API->>Service: Process Error Service-->>API: Error Result API-->>Client: Error Response end \`\`\` --- ## Use Cases **Required** Describe practical scenarios of application, challenges, and benefits. ### [Use Case Title] **Scenario:** [scenario description] **Challenge:** [challenge description] **Solution:** [solution description] **Benefit:** [benefit description] --- ## References *(Optional)* Provide useful links, technical documentation, or external references. --- ## Additional Information *(Optional)* Provide context on complexity, priority, and dependencies. * **Priority:** High / Medium / Low * **Complexity:** High / Medium / Low * **Estimated Effort:** [story points or hours] * **Dependencies:** [list dependencies] * **Related Issues:** [list related issues]
OAS