Weave Code
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

Laravel Dadata Laravel Package

forest-lynx/laravel-dadata

Laravel package integrating DaData API for address/company/person suggestions, cleaning and geocoding. Provides a client and helpers to call DaData endpoints from your app; configure API keys in Laravel and use services for autocomplete and data normalization.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Use Case Alignment: The package (forest-lynx/laravel-dadata) integrates Dadata.ru (Russian address validation, geocoding, and parsing API) into Laravel, making it ideal for applications requiring address validation, autocomplete, or geocoding (e.g., e-commerce, logistics, or location-based services).
  • Laravel Compatibility: Leverages Laravel’s service container, facades, and eloquent events for seamless integration. Follows Laravel’s dependency injection patterns, reducing boilerplate.
  • API Abstraction: Encapsulates Dadata’s API calls behind a clean facade (Dadata), simplifying usage (e.g., Dadata::suggest('ул.')).
  • Event-Driven Hooks: Supports eloquent observers for post-save validation (e.g., validating addresses on model creation/update).

Integration Feasibility

  • Low-Coupling Design: Minimal invasive changes required. Can be adopted incrementally (e.g., start with autocomplete, later add validation).
  • Configuration-Driven: API key and endpoint config are centralized in .env, adhering to Laravel’s 12-factor principles.
  • Middleware Potential: Could extend to form request validation (e.g., ValidateDadataAddress) or API gateways for external services.

Technical Risk

  • Dependency on External API:
    • Rate Limits: Dadata’s free tier has constraints (e.g., 1,000 requests/day). Scaling may require caching (e.g., Redis) or queueing (e.g., Laravel Queues) to avoid throttling.
    • Cost at Scale: Paid plans may be needed for high-volume use. Budget impact must be assessed.
  • Error Handling:
    • Limited documentation on retry logic for failed API calls. May need custom middleware or exponential backoff.
    • Fallback mechanisms (e.g., cached responses) should be planned for API downtime.
  • Localization:
    • Primarily designed for Russian addresses. If supporting other regions, may need multi-API integration (e.g., Google Maps, OpenStreetMap).
  • Testing Gaps:
    • No visible PHPUnit tests or mocking examples. May require custom test doubles for CI/CD pipelines.

Key Questions

  1. API Key Management:
    • How will Dadata API keys be rotated/secured (e.g., Vault, Laravel Env variables)?
  2. Performance:
    • What caching strategy will be used (e.g., Redis TTL for suggestions)?
  3. Fallbacks:
    • What happens during Dadata API outages? (e.g., graceful degradation)
  4. Validation Rules:
    • Will this replace or supplement existing Laravel validation (e.g., required|dadata_valid)?
  5. Monitoring:
    • How will API usage/errors be logged (e.g., Laravel Horizon, Sentry)?
  6. Multi-Language Support:
    • Is Russian-only functionality acceptable, or will other geocoding APIs be needed?

Integration Approach

Stack Fit

  • Laravel Ecosystem:
    • Service Provider: Package registers a DadataServiceProvider, making it plug-and-play.
    • Facades: Dadata::suggest(), Dadata::clean() align with Laravel’s fluent syntax.
    • Eloquent: Supports model observers for automatic validation (e.g., Address::saved()).
  • Complementary Packages:
    • Caching: Pair with spatie/laravel-redis-cache for rate-limit mitigation.
    • Queues: Use laravel-queue for async validation (e.g., Dadata::validateAsync()).
    • Testing: Integrate with pestphp/pest or mockery/mockery for API testing.

Migration Path

  1. Phase 1: Autocomplete
    • Replace manual address input with Dadata::suggest() in frontend forms (e.g., Vue/React + Laravel Echo).
    • Example:
      $suggestions = Dadata::suggest(request('query'));
      return response()->json($suggestions);
      
  2. Phase 2: Validation
    • Add dadata_valid custom validation rule (extend Illuminate\Validation\Rules\Rule).
    • Example:
      'address' => ['required', new DadataValid],
      
  3. Phase 3: Geocoding
    • Use Dadata::clean() to parse addresses into structured data (e.g., lat, lng).
    • Store in database for maps integration (e.g., Leaflet.js).

Compatibility

  • Laravel Versions: Tested with Laravel 9/10 (check composer.json constraints).
  • PHP Versions: Requires PHP 8.0+. Confirm compatibility with your stack.
  • Database Agnostic: No SQL-specific logic; works with MySQL, PostgreSQL, etc.
  • Frontend Agnostic: Returns JSON for any frontend (e.g., Livewire, Inertia.js, API consumers).

Sequencing

Step Priority Effort Dependencies
Add .env config High Low Dadata API key
Implement autocomplete High Medium Frontend integration
Add validation rule Medium Low Custom rule class
Cache responses Low Medium Redis setup
Async processing Low High Queue worker

Operational Impact

Maintenance

  • Package Updates:
    • Monitor forest-lynx/laravel-dadata for breaking changes (MIT license allows forks if needed).
    • Dependency Alerts: Use roave/security-advisories to track Dadata SDK vulnerabilities.
  • Configuration Drift:
    • Centralize Dadata settings in .env to avoid hardcoding.
    • Use Laravel Env Validator to enforce required keys.

Support

  • Debugging:
    • Enable DD(Dadata::lastResponse()) for troubleshooting API issues.
    • Log errors to Sentry or Laravel Log with context (e.g., user_id, address).
  • Documentation Gaps:
    • Create internal runbooks for:
      • API key rotation.
      • Handling rate limits.
      • Common errors (e.g., 429 Too Many Requests).
  • Vendor Lock-in:
    • Abstract Dadata calls behind interfaces for future API swaps (e.g., GeocodingService).

Scaling

  • Rate Limits:
    • Implement exponential backoff for retries (e.g., spatie/backoff).
    • Cache responses with short TTL (e.g., 5 mins) to reduce API calls.
  • Queue-Based Processing:
    • Offload validation to queues to avoid blocking requests:
      Dadata::validate($address)->onQueue('dadata-queue');
      
  • Database Optimization:
    • Store parsed geodata (e.g., lat, lng) in separate columns to avoid repeated API calls.

Failure Modes

Scenario Impact Mitigation Strategy
Dadata API downtime Autocomplete/validation fails Fallback to cached responses or manual input
Rate limit exceeded 429 errors Queue requests + exponential backoff
Invalid API key All calls fail Monitor Dadata::lastError()
Database overload Slow geocoding queries Denormalize geodata or use read replicas
Regional unsupported Non-Russian addresses fail Multi-API integration (e.g., Google Maps)

Ramp-Up

  • Onboarding:
    • 1-hour workshop: Demo autocomplete + validation for devs.
    • Cheat Sheet: Key methods (suggest(), clean(), validate()).
  • Training:
    • Focus on:
      • When to use suggest() vs. clean().
      • Handling API errors gracefully.
      • Caching strategies.
  • Adoption Metrics:
    • Track:
      • API call volume (vs. rate limits).
      • Reduction in manual address corrections.
      • Frontend autocomplete usage.
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.
daikazu/eloquent-salesforce-objects
unseen-codes/chat
romalytar/yammi-jobs-monitoring-laravel
kisame76/filament-db-table-state
nqxcode/laravel-lucene-search
dpfx/laravel-livewire-wizards
workos/workos-php-laravel
sofa/laravel-global-scope
nawasara/auth-primitives
adhocrat-io/arkhe-main
make-dev/orca-harpoon
itsemon245/lamet
baks-dev/dashboard
amoifr/pickle-panther-bundle
make-dev/orca
dmstr/symfony-system-resources-bundle
dmstr/symfony-job-queue-bundle
dmstr/openapi-json-schema-bundle
dmstr/keycloak-security-bundle
dmstr/doctrine-audit-log-bundle