charcoal-dev/contracts
Lightweight set of PHP/Laravel contract interfaces for the Charcoal ecosystem. Defines shared abstractions to keep packages decoupled and consistent, making it easier to swap implementations, test components, and build integrations across projects.
RepositoryInterface, ServiceInterface) imply DDD patterns, which are increasingly adopted in Laravel monoliths/microservices. Useful for enforcing separation of concerns and testability.bind() in service providers).RepositoryInterface implementations.strict_types=1 and attribute usage (PHP 8.1+).UserRepository with RepositoryInterface if it aligns with existing methods.class UserService extends Service).Auth::user()) with contract-injected dependencies.$this->app->bind(
RepositoryInterface::class,
UserRepository::class
);
RepositoryInterface but may need adapter classes for non-CRUD methods.Builder) may not align with contract methods.$this->mock()->shouldReceive('findById')->andReturn($user);
| Phase | Task | Dependencies |
|---|---|---|
| Discovery | Map existing code to contracts. | None |
| Scaffolding | Create abstract base classes (e.g., AbstractRepository). |
Contract interfaces |
| New Development | Write new services using contracts. | Scaffolding |
| Refactoring | Replace old services with contract-compliant versions. | Testing framework |
| Testing | Validate contract behavior with unit/integration tests. | Mocking libraries (e.g., Mockery) |
| Deployment | Roll out in feature flags or per-module. | CI/CD pipeline |
RepositoryInterface::find() → UserRepository::fetch()).ServiceInterface for my use case?"| Risk | Mitigation Strategy | Detection Method |
|---|---|---|
| Contract Mismatch | Use PHPStan to enforce implementation. | Static analysis |
| Circular Dependencies | Enforce layered architecture (e.g., API → Services → Repositories). | Dependency graph tools (e.g., PHPMD) |
| Uncaught Exceptions | Implement global exception handlers in contracts. | Error tracking (Sentry) |
| Charcoal Ecosystem Decline | Maintain forks of critical contracts. | Monitor GitHub activity |
| Testing Gaps | Write contract-specific tests (e.g., "Does RepositoryInterface::save() handle validation?"). |
Test coverage tools (e.g., Infection) |
How can I help you explore Laravel packages today?