Skip to content

Instantly share code, notes, and snippets.

@caneto
Last active January 9, 2026 19:06
Show Gist options
  • Select an option

  • Save caneto/4c3eded1f43372b2442eb7a56a9b7fda to your computer and use it in GitHub Desktop.

Select an option

Save caneto/4c3eded1f43372b2442eb7a56a9b7fda to your computer and use it in GitHub Desktop.
Regras
trigger
always_on

API Generation Rules

These rules define how API integration should be generated, structured, and maintained across the project.

The agent must always follow these standards when creating API-related files or methods.

πŸ“Œ Core API Architecture Rules

rules:
  - "Use Retrofit for all API integrations."
  - "Use JsonSerializable for request and response models."
  - "Follow the multi-repository pattern, where each feature module has its own repository."
  - "Add all standard API endpoints to api_service.dart, unless a special case requires its own custom Retrofit service."
  - "All API responses must use APIResponse<T> and convert to ApiResult<T> through the custom MyCallAdapter."
  - "Model only the 'data' portion of the API response, not the entire wrapper structure."
  - "Use snake_case for all file and folder names."
  - "Request models must use @JsonSerializable(includeIfNull: false, createFactory: false)."
  - "Response models must use @JsonSerializable(), include fromJson() and toJson(), and be immutable."
  - "Each feature module must include its own repository that extends the base Repository class."
  - "Repository methods must directly call the corresponding apiService method and return ApiResult<T>."
  - "Generated code must remain consistent with existing project architecture and naming conventions."

πŸ“Œ Agent Behavior Rules

agent_behavior:
  - "Automatically determine the correct HTTP method based on context or payload structure."
  - "Generate request and response models only when required."
  - "Ensure every generated API method includes proper Retrofit annotations (@GET, @POST, etc.)."
  - "Ensure every repository method is clean, minimal, and limited to calling the API service."
  - "Do not create business logicβ€”only integration and structural code."
  - "Automatically fix inconsistent naming and follow project conventions."
  - "Generate all required imports and ensure paths are accurate."
  - "Notify when build_runner generation is needed."
  - "Summarize generated files and their locations after completion."

πŸ“Œ Expected Output Structure

When generating API integration, the agent should maintain the following folder pattern:

lib/repositories/
  β”œβ”€β”€ api_repositories/
  β”‚   β”œβ”€β”€ api_service.dart
  β”‚   └── api_repository.dart
  β”œβ”€β”€ <feature>_repository/
  β”‚   β”œβ”€β”€ <feature>_repository.dart
  β”‚   └── model/
  β”‚       β”œβ”€β”€ <feature>_req_dm.dart
  β”‚       └── <feature>_res_dm.dart

πŸ“Œ Code Quality Rules

quality:
  - "Follow Dart formatting and null-safety standards."
  - "Ensure all models are immutable and strongly typed."
  - "Avoid duplicate code or logic."
  - "Keep generated code minimal, clean, and scalable."
  - "Maintain consistent naming across services, repositories, and models."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment