Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Veritas Laravel Package

dbstudios/veritas

Laravel package for verifying and validating incoming request data and payloads with a consistent rule-based approach. Helps enforce data integrity across APIs and forms, offering a lightweight way to define checks, run assertions, and return clear validation feedback.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Validation-Centric Design: Veritas is not a JWT library but a validation framework for Laravel, misaligned with the original description’s focus on JWT authentication. The package excels at centralizing validation rules (e.g., form inputs, domain constraints) but lacks native JWT-specific features like token generation, signing, or revocation. This creates a misalignment with the stated use case (JWT auth).
  • Laravel Ecosystem Synergy: Integrates seamlessly with Laravel’s validation system (e.g., Validator facade) and form requests, but requires manual JWT handling (e.g., using firebase/php-jwt separately). This introduces duplication of concerns (validation + auth).
  • Stateless Validation: Ideal for APIs or microservices where input validation is decoupled from auth, but not a replacement for JWT libraries like typhon/jwt-auth or lucadegasperi/oauth2-server.
  • Customizability: Supports composable validation rules, but lacks JWT-specific features (e.g., claim validation, token storage). Users must roll their own for JWT logic.

Integration Feasibility

  • Laravel Compatibility: Works with Laravel 5.5+; no breaking changes expected. However, JWT functionality must be added separately, increasing complexity.
  • Validation Integration: Plugs into Laravel’s Validator and FormRequest classes, enabling reusable validation logic across controllers. Example:
    use DbStudios\Veritas\Rules\Email;
    use DbStudios\Veritas\Rules\MinLength;
    
    $rules = [
        'email' => ['required', new Email],
        'password' => ['required', new MinLength(8)],
    ];
    
  • No JWT-Specific Features: Missing token generation, signing, or middleware for JWT. Users must combine it with:
    • firebase/php-jwt for token handling.
    • Custom middleware for auth.
  • Database Agnostic: No assumptions about storage; validation rules are pure PHP, but JWT tokens require external storage (e.g., Redis for refresh tokens).

Technical Risk

  • Security Risks:
    • No Built-in JWT Security: Users must manually implement:
      • Token signing (e.g., HS256/RS256).
      • Claim validation (e.g., iss, exp, aud).
      • Token revocation (e.g., blacklist table).
    • Validation Auth Bypass: Validation rules alone cannot enforce auth; requires additional middleware.
  • Performance Risks:
    • Double Validation: If using both Veritas (for inputs) and a separate JWT library (for auth), duplicate validation logic may exist.
    • No Caching: Validation rules are not cached by default; high-traffic APIs may need rule caching (e.g., Validator::extend()).
  • Dependency Risks:
    • No Native JWT Dependency: Requires firebase/php-jwt or similar, adding maintenance overhead.
    • Laravel Version Lock: May lag behind Laravel’s latest features (e.g., Laravel 10’s new validation helpers).

Key Questions

  1. Core Need Clarification:
    • Is the goal input validation (Veritas’ strength) or JWT authentication? If the latter, this package is not the right tool.
    • Are you building a validation layer or an auth system?
  2. JWT Implementation:
    • How will tokens be generated, signed, and stored? Veritas provides no JWT functionality.
    • Will you use a separate JWT library (e.g., typhon/jwt-auth) alongside Veritas?
  3. Validation Scope:
    • Are validation rules reusable across APIs/forms, or is this for a single use case?
    • How will validation errors be handled in APIs (e.g., JSON responses vs. redirects)?
  4. Migration Path:
    • What existing validation/auth logic will be replaced or extended?
    • Are there legacy systems relying on custom validation that must integrate?
  5. Team Expertise:
    • Does the team have experience with Laravel validation and JWT libraries?
    • Is there bandwidth to combine Veritas with a JWT solution?

Integration Approach

Stack Fit

  • Best For:
    • Laravel Applications Needing Centralized Validation: Ideal for forms, APIs, or internal workflows where validation logic is duplicated.
    • Microservices with Shared Validation Rules: Enables reusable rules across services (e.g., user registration, payment processing).
    • Projects Avoiding JWT: If the focus is input validation (not auth), Veritas is a strong fit.
  • Poor Fit:
    • JWT Authentication: Lacks token generation/signing; not a replacement for jwt-auth or oauth2-server.
    • Session-Based Auth: Overkill for traditional Laravel session auth (use Illuminate\Validation instead).
    • High-Security Systems: No built-in JWT security features (e.g., claim validation, revocation).

Migration Path

  1. Phase 1: Validation Extraction
    • Scope: Replace duplicate validation logic in controllers with Veritas rules.
    • Steps:
      • Define reusable rules (e.g., Email, MinLength) in app/Rules.
      • Replace inline validation (e.g., Validator::make($data, [...])) with Veritas-composed rules.
      • Example:
        // Before
        $validator = Validator::make($request->all(), [
            'email' => 'required|email',
            'password' => 'required|min:8',
        ]);
        
        // After
        $validator = Validator::make($request->all(), [
            'email' => [new Email],
            'password' => [new MinLength(8)],
        ]);
        
  2. Phase 2: Form Request Integration
    • Scope: Centralize validation in FormRequest classes.
    • Steps:
      • Extend FormRequest to use Veritas rules:
        use DbStudios\Veritas\Rules\Email;
        
        class StoreUserRequest extends FormRequest {
            public function rules() {
                return [
                    'email' => [new Email],
                    'name' => ['required', 'string'],
                ];
            }
        }
        
  3. Phase 3: API Validation (If Needed)
    • Scope: Extend validation to API responses (e.g., JSON error formats).
    • Steps:
      • Create a custom error formatter to return Veritas errors in API format:
        Validator::extend('email', function ($attribute, $value, $parameters, $validator) {
            return filter_var($value, FILTER_VALIDATE_EMAIL);
        });
        
      • Use Validator::failed() to return structured errors:
        {
            "errors": {
                "email": ["The email must be a valid address."]
            }
        }
        
  4. Phase 4: JWT Integration (Separate)
    • Scope: If JWT auth is needed, pair Veritas with a JWT library.
    • Steps:
      • Install firebase/php-jwt:
        composer require firebase/php-jwt
        
      • Create a custom JWT guard (example):
        use Firebase\JWT\JWT;
        use Firebase\JWT\Key;
        
        class JwtGuard extends Guard {
            public function validate($credentials = []) {
                $token = $credentials['token'] ?? request()->bearerToken();
                try {
                    $decoded = JWT::decode($token, new Key(config('jwt.secret'), 'HS256'));
                    return $this->user()->setUserResolver(function () use ($decoded) {
                        return User::find($decoded->user_id);
                    });
                } catch (\Exception $e) {
                    return false;
                }
            }
        }
        
      • Register the guard in AuthServiceProvider:
        $this->app['auth']->extend('jwt', function ($app) {
            return new JwtGuard($app['request'], $app['auth.manager']);
        });
        

Compatibility

  • Laravel Versions: Tested on 5.5+; may need adjustments for Laravel 10+ (e.g., validation helpers).
  • PHP Versions: Requires PHP 7.2+; ensure alignment with your stack.
  • Database: No schema changes; validation rules are pure PHP.
  • Third-Party Libraries:
    • JWT Libraries: Must be added separately (e.g., firebase/php-jwt, typhon/jwt-auth).
    • Form Requests: Works with Laravel’s FormRequest classes but does not replace them.
    • Validation Extensions: Can extend Laravel’s Validator but does not override built-in rules.

Sequencing

| Step | Task | Dependencies | Risk | |------|------|--------------

Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings
coleus/apps
seampact/laravel
emmyconceptng/laravel-ng-postcode
jjsquady/round-robin