# Service Repository

When you generate code using Sketch, it creates a foundation for implementing the service repository pattern with empty interfaces that you can extend based on your specific needs.

### Generated Structure

The generated files follow this pattern:

```
app/
├── Repositories/
│   ├── BaseRepository.php
│   └── Post/
│       ├── PostRepository.php (Interface)
│       └── PostRepositoryImp.php (Implementation)
└── Services/
    └── Post/
        ├── PostService.php (Interface)
        └── PostServiceImp.php (Implementation)
```

### Base Repository

The BaseRepository class serves as the foundation for all repository implementations. It provides a set of common database operations that your specific repository implementations can inherit. This includes methods for finding, creating, updating, and deleting records using both ID and UUID.

### Repository Components

The repository layer consists of two main components:

### Repository Interface

```php
<?php

namespace App\Repositories\Post;

interface PostRepository
{
    // Define your repository methods here
}
```

### Repository Implementation

```php
<?php

namespace App\Repositories\Post;

use App\Repositories\BaseRepository;
use App\Models\Post;

class PostRepositoryImp extends BaseRepository implements PostRepository
{
    public function __construct(Post $model)
    {
        parent::__construct($model);
    }
    
    // Implement your repository methods here
}
```

### Service Components

The service layer also consists of two main components:

### Service Interface

```php
<?php

namespace App\Services\Post;

interface PostService
{
    // Define your service methods here
}
```

### Service Implementation

```php
<?php

namespace App\Services\Post;

class PostServiceImp implements PostService
{
    // Implement your service methods here
}
```

### Extending the Pattern

After generation, you can extend these classes by:

1. Adding methods to your repository interface based on your data access needs
2. Implementing those methods in your repository implementation class
3. Adding business logic methods to your service interface
4. Implementing the business logic in your service implementation class

For example, you might extend them like this:

```php
// PostRepository.php
interface PostRepository
{
    public function findPublishedPosts();
    public function findByCategory($categoryId);
}

// PostService.php
interface PostService
{
    public function getPublishedPosts();
    public function getPostsByCategory($categoryId);
}
```

This structure provides a clean foundation that you can build upon while maintaining separation of concerns and following SOLID principles.
