Skip to content

Chemaclass/satscribe / .claude/skills/create-repository

create-repository

Verified

Scaffold a repository — interface in Domain, Eloquent implementation in Infrastructure, plus binding and test

FileKindSize
SKILL.mdskill md2.4 KB
---
description: Scaffold a repository — interface in Domain, Eloquent implementation in Infrastructure, plus binding and test
argument-hint: "<Module>/<Entity>"
disable-model-invocation: true
allowed-tools: "Read, Write, Edit, Glob, Grep, Bash(vendor/bin/phpunit *), Bash(composer *)"
---

# New Repository

Create the repository in `$ARGUMENTS` (e.g. `Chat/Message`). Repositories are the **only** place Eloquent may appear.

Read `modules/Chat/Infrastructure/Repository/ChatRepository.php` and mirror it. Layer rules: `.claude/rules/architecture.md`.

## Files

```
modules/<Module>/Domain/Repository/<Entity>RepositoryInterface.php
modules/<Module>/Infrastructure/Repository/<Entity>Repository.php
tests/Feature/<Module>/<Entity>RepositoryTest.php
modules/<Module>/<Module>ServiceProvider.php          # binding
```

## Interface (Domain)

```php
namespace Modules\<Module>\Domain\Repository;

interface <Entity>RepositoryInterface
{
    public function find(int $id): ?<Entity>;

    public function save(<Entity> $entity): <Entity>;

    public function delete(<Entity> $entity): void;

    // public function findActiveByUser(string $npub): array;
}
```

Method names describe **domain intent** (`findActiveByUser`), not query mechanics (`findByStatusAndDate`).

## Implementation (Infrastructure)

```php
namespace Modules\<Module>\Infrastructure\Repository;

use App\Models\<Entity>;

final readonly class <Entity>Repository implements <Entity>RepositoryInterface
{
    public function find(int $id): ?<Entity>
    {
        return <Entity>::find($id);
    }

    public function save(<Entity> $entity): <Entity>
    {
        $entity->save();

        return $entity;
    }
}
```

## Binding

```php
<Entity>RepositoryInterface::class => <Entity>Repository::class,
```

## Test — Feature suite, needs a real DB

```php
final class <Entity>RepositoryTest extends TestCase
{
    use RefreshDatabase;

    public function test_find_with_existing_id_returns_entity(): void { /* … */ }

    public function test_find_with_unknown_id_returns_null(): void { /* … */ }
}
```

Consumers (Actions, Services) mock the **interface** in their own unit tests.

## Specific to repositories

- Queries live here, never in Actions, Services, or Controllers
- Return models or domain objects — never a query builder
- Eager-load relations here so callers can't cause N+1
- Missing model? Create it in `app/Models/` plus a migration

```bash
composer test
```
finishing-a-development-branchobra/superpowersUse when implementation is complete, all tests pass, and you need to decide how to integrate the workStars: 322kUpdated Claude CodeCodexVerifiedInstall
systematic-debuggingobra/superpowersUse when encountering any bug, test failure, or unexpected behavior, before proposing fixesStars: 322kUpdated Claude CodeCodexVerifiedInstall
test-driven-developmentobra/superpowersUse when implementing any feature or bugfix, before writing implementation codeStars: 322kUpdated Claude CodeCodexVerifiedInstall
skill-creatoranthropics/skillsCreate new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.Stars: 198kUpdated Claude CodeCodexVerifiedInstall