stemizer/laravel-domain-repositories

Convention-driven repository binding for domain-oriented Laravel architectures.

Maintainers

Package info

github.com/samettemizer/laravel-domain-repositories

pkg:composer/stemizer/laravel-domain-repositories

Statistics

Installs: 0

Dependents: 0

Suggesters: 0

Stars: 2

Open Issues: 0

1.0.1 2026-05-31 21:51 UTC

This package is auto-updated.

Last update: 2026-05-31 21:55:20 UTC


README

Automatic repository discovery and container binding for domain-driven Laravel applications.

This package eliminates manual container bindings for repository pairs. It scans app/Domains, applies a strict naming convention, and registers contracts to their concrete implementations automatically — with optional caching for production.

Installation

composer require stemizer/laravel-domain-repositories

Optionally publish the config:

php artisan vendor:publish --tag=domain-repositories-config

Naming Convention

The package expects the following structure for each domain:

Role Class
Contract App\Domains\{Domain}\RepositoryContract\{Domain}Repository
Concrete App\Domains\{Domain}\Repository\{Domain}{Driver}

Example with Foo domain and default Eloquent driver:

App\Domains\Foo\RepositoryContract\FooRepository   ← interface
App\Domains\Foo\Repository\FooEloquent              ← implementation

If a contract or concrete class does not exist, that domain is silently skipped.

Configuration

// config/domain_repositories.php

'default_driver'  => 'Eloquent',
'default_binding' => 'bind',   // or 'singleton'
'binding_options' => ['bind', 'singleton'],

'domains' => [
    'Foo' => ['driver' => 'Eloquent', 'binding' => 'bind'],
    'Bar' => ['driver' => 'Eloquent', 'binding' => 'singleton'],
],

Per-domain overrides take precedence over defaults.

Directory Scaffolding

RepositoryHelper::ensureDomainDirectories($domainPath) creates the standard domain subdirectories:

Console, Enums, Events, Exceptions, Helpers, Http, Jobs,
Listeners, Models, Observers, Providers, Services,
Repository, RepositoryContract

Caching

In non-local/testing environments the resolved bindings are written to bootstrap/cache/domain_repository_binds.php and loaded on subsequent requests. To clear:

php artisan optimize:clear

Features

  • Automatic contract-to-concrete binding via directory scan
  • Config-driven driver and binding strategy per domain
  • Cache file generation for staging/production
  • Domain directory scaffolding helper

Out of Scope

This package handles repository registration only. Event listeners, service registrations, and other domain concerns are intentionally left out.

License

MIT