Product Decisions This Supports
- Standardization of UUIDs: Replace inconsistent UUID generation (e.g.,
Str::uuid(), manual string concatenation, or third-party libraries) with a single, maintained source for UUIDs in Laravel/PHP applications. Aligns with Laravel’s shift toward UUIDs for primary keys and distributed systems.
- Testing Efficiency: Accelerate test development by providing deterministic UUID generation for fixtures, edge cases, and assertions. Reduces flakiness in tests where UUIDs are used (e.g., mocking, seeding).
- Migration to UUIDs: Enable seamless adoption of UUIDs as primary keys in Laravel models, supporting:
- Distributed systems (microservices, multi-database setups).
- Event sourcing/CQRS architectures (via Broadway integration).
- Database-agnostic designs (e.g., switching from PostgreSQL to MySQL without ID conflicts).
- Roadmap Alignment:
- Future-proof for features requiring UUIDs (e.g., multi-tenancy, soft deletes with UUIDs, or graphQL IDs).
- Simplify onboarding for new developers by standardizing UUID usage early.
- Build vs. Buy:
- Avoid reinventing UUID logic: This package wraps
ramsey/uuid, a widely used, RFC-compliant library, reducing technical debt.
- Leverage existing ecosystem: Integrates with Laravel’s Eloquent, API resources, and testing tools without custom development.
- Use Cases:
- Primary Keys: Replace auto-increment IDs with UUIDs in Eloquent models (e.g.,
protected $primaryKey = 'uuid').
- API Resources: Generate UUIDs for endpoints (e.g.,
/users/{uuid}) or payloads.
- Event Sourcing: Use UUIDs for event message IDs, aggregate roots, or command IDs (critical for Broadway users).
- Distributed Tracing: Assign UUIDs as correlation IDs for logs/metrics.
- Multi-Tenant Systems: UUIDs as tenant identifiers or scoped keys.
When to Consider This Package
Adopt if:
- Your Laravel/PHP app requires UUIDs for primary keys or unique identifiers (e.g., migrating from auto-increment IDs).
- You need deterministic UUIDs for testing (e.g., fixtures, mocks, or assertions) and want built-in helpers.
- Your team uses Broadway (event sourcing/CQRS) or plans to adopt it, as this package is tightly coupled to its UUID patterns.
- You prioritize type safety (strict PHP types) and modern PHP practices (PHP 7.2+).
- You want to standardize UUID generation across the codebase to reduce inconsistencies (e.g., mixing
Str::uuid(), ramsey/uuid, or manual implementations).
- Your project can tolerate minimal maintenance risk (last release: 2020) but relies on the underlying
ramsey/uuid library for updates.
Look elsewhere if:
- You need high-performance UUID generation (this is a thin wrapper; consider native extensions like
ext-uuid or ramsey/uuid directly).
- Your app doesn’t use UUIDs for primary keys and only needs them for APIs or non-critical fields (Laravel’s
Str::uuid() may suffice).
- You require active maintenance or long-term support (the package is unmaintained;
ramsey/uuid is actively updated).
- Your project uses PHP <7.2 (e.g., legacy systems).
- You need non-random UUIDs (e.g., time-based, hash-based, or versioned UUIDs; this package defaults to random v4 UUIDs).
- You’re not using Broadway and want to avoid its UUID-specific patterns (e.g., message IDs, metadata formats).
- You prefer zero dependencies and want to use Laravel’s built-in tools exclusively.
How to Pitch It (Stakeholders)
For Executives:
*"This package standardizes how we generate UUIDs across our Laravel applications, eliminating inconsistencies and reducing technical debt. By adopting it, we can:
- Future-proof our architecture for distributed systems, microservices, or event sourcing (e.g., Broadway).
- Simplify testing with built-in UUID helpers, speeding up development and reducing flaky tests.
- Avoid reinventing the wheel: It’s a lightweight wrapper around
ramsey/uuid, a trusted library already used by Laravel and other PHP frameworks.
- No upfront cost: MIT-licensed and easy to integrate—just a
composer require away.
Example impact: If we migrate from auto-increment IDs to UUIDs for primary keys, this package ensures consistency and compatibility with tools like Broadway, which is critical for our event-driven roadmap. The risk is minimal since it relies on ramsey/uuid for updates."*
For Engineering (Tech Leads/Architects):
*"We’re proposing broadway/uuid-generator to:
- Standardize UUIDs across the codebase, replacing ad-hoc implementations (e.g.,
Str::uuid() or manual string generation).
- Simplify testing with deterministic UUIDs for fixtures and assertions (e.g.,
UuidGenerator::generate() in PHPUnit).
- Leverage
ramsey/uuid under the hood—a robust, widely adopted library—without maintenance overhead for us.
- Enable Broadway integration if we adopt event sourcing/CQRS, ensuring UUIDs align with message IDs and aggregate roots.
Trade-offs:
- Last updated in 2020: No active maintenance, but
ramsey/uuid is still updated. We’d monitor compatibility with PHP 8.2+/Laravel 10+.
- Broadway-specific: Assumes its UUID patterns (e.g., message IDs). If we’re not using Broadway,
ramsey/uuid directly may be simpler.
- Dev dependencies: Adds PHPUnit/PHPStan to CI (non-intrusive if already used).
Recommendation: Start with a pilot in a Broadway module or UUID-heavy feature. If issues arise, we can fork the package or switch to ramsey/uuid."*
For Developers:
*"This package makes UUIDs easy and consistent in Laravel:
- Generate UUIDs in one line:
use Broadway\UuidGenerator\UuidGenerator;
$uuid = UuidGenerator::generate(); // e.g., '123e4567-e89b-12d3-a456-426614174000'
- Use UUIDs as primary keys in Eloquent models:
class User extends Model {
protected $primaryKey = 'uuid';
protected $keyType = 'string';
}
- Test with deterministic UUIDs:
$testUuid = UuidGenerator::generate();
$this->assertEquals($testUuid, $user->uuid); // No flakiness!
- Works with Laravel’s UUID columns (PostgreSQL/MySQL) and APIs.
When to use it:
✅ You need UUIDs for primary keys or unique IDs.
✅ You’re using Broadway or want to adopt event sourcing.
✅ You want to avoid mixing Str::uuid(), ramsey/uuid, or manual UUIDs.
When to skip it:
❌ You only need UUIDs for APIs (use Str::uuid()).
❌ You’re on PHP <7.2 or Laravel <9.
❌ You need non-random UUIDs (e.g., time-based)."*
For QA/Test Engineers:
*"This package supercharges UUID testing in Laravel:
- Deterministic UUIDs: Generate predictable UUIDs for fixtures or edge-case testing.
$fixedUuid = UuidGenerator::generate(); // Same UUID every run
- Assert UUID formats: Validate UUIDs in tests without regex headaches.
$this->assertInstanceOf(UuidInterface::class, $user->uuid);
- Seamless integration: Works with Laravel’s PHPUnit and Eloquent test helpers.
Example: Replace flaky factory()->create() with UUID-controlled fixtures, reducing test failures due to randomness."*