petrvs-repository-pattern

Standardize Petrvs-PGD repository implementations with Eloquent read/write separation and DTOs.

19|14|Updated Aug 6, 2024
One-click install
npx skills add https://github.com/gestaogovbr/pgd-petrvs-publico --skill petrvs-repository-pattern
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: petrvs-repository-pattern
Source: https://github.com/gestaogovbr/pgd-petrvs-publico/tree/main/.agents/skills/petrvs-repository-pattern
Command: npx skills add https://github.com/gestaogovbr/pgd-petrvs-publico --skill petrvs-repository-pattern

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill solves inconsistent and tightly-coupled backend repository implementations by providing a practical, repeatable repository pattern for the Petrvs-PGD codebase.

Core Features & Use Cases

  • Repository design guidance: Create expressive repository contracts, decide what belongs in repositories vs services, and keep read/write behavior coherent in Eloquent repositories.
  • Laravel/Petrvs implementation flow: Generate new repositories with the intended artisan command, register bindings in the RepositoryServiceProvider, and use DTOs for composed return data.
  • Quality safeguards: Add integration-tenant focused tests and run Pest and PHPStan on the modified repository/provider paths.
  • Decision rules and pitfalls: Avoid injecting repositories directly into controllers except in a narrow read-only case, and avoid large associative arrays when domain shapes are stable.

Quick Start

Ask an AI to refactor your Petrvs backend repository by proposing a repository contract, the Eloquent read/write repository implementation using DTOs, the RepositoryServiceProvider bindings, and the integration-tenant tests to validate the behavior.

Frequently Asked Questions about petrvs-repository-pattern

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I separate read and write operations in Laravel Eloquent repositories?

To standardize backend repository implementation, define expressive repository contracts and separate Eloquent read and write logic. Return composed data using DTOs instead of large associative arrays, keeping domain shapes stable and testable across your application.

What is the repository pattern and when should I use DTOs for return data?

The repository pattern standardizes data access by defining clear contracts between your application and persistence layer. Use DTOs for return data when domain shapes are stable, preventing large associative arrays and ensuring type-safe data transfer across module boundaries.

How do I register repository bindings in a Laravel service provider?

Register repository bindings by mapping contract interfaces to their concrete Eloquent implementations within the RepositoryServiceProvider. This wires your repository dependencies into the container, enabling seamless dependency injection across the application.

How do I write integration tests for tenant-scoped repositories using Pest?

Write tenant-scoped integration tests by placing them in the prescribed test directories and executing Pest on modified repository and provider paths. This validates tenant-specific data isolation and ensures your repository behavior functions correctly within multi-tenant contexts.

Should I inject repositories directly into Laravel controllers?

Avoid injecting repositories directly into controllers except in a narrow read-only case. Injecting repositories directly into controllers creates tight coupling; route repository interactions through service classes to maintain proper separation of concerns and architectural boundaries.

How do I run PHPStan analysis on modified repository and provider paths?

Run PHPStan analysis on modified repository and provider paths by executing static analysis directly against your changed files. This quality safeguard detects type errors and architectural violations early, ensuring repository contracts and DTOs strictly adhere to prescribed standards.