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

Frete Bundle Laravel Package

brazilianfriendsofsymfony/frete-bundle

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Symfony-centric: The package is a Symfony bundle, which means it is tightly coupled to the Symfony framework. If the application is built on Symfony (v2+), this package will integrate seamlessly with minimal architectural disruption. However, if the application uses Laravel or another PHP framework, integration will require additional abstraction layers (e.g., a microservice, API wrapper, or facade pattern).
  • Domain-Specific: The bundle is designed for shipping/freight calculations (Correios API integration), making it a highly specialized solution. If the application requires broader logistics support (e.g., multiple carriers, multi-country shipping), this package alone may not suffice without extensions.
  • Monolithic vs. Modular: The bundle encapsulates API logic for Correios, which could be seen as a modular advantage for Symfony apps needing shipping calculations. However, its lack of dependency injection flexibility (e.g., no clear PSR-11 container support) may limit testability or swapping implementations.

Integration Feasibility

  • Symfony Compatibility: The bundle is built for Symfony 2+, so integration into a Symfony 5/6/7 app is straightforward (assuming no breaking changes in Symfony’s DI system). For Symfony 8+, compatibility should be verified due to PHP 8.1+ requirements.
  • Laravel Integration Challenges:
    • No Native Laravel Support: The bundle relies on Symfony’s ContainerInterface, DependencyInjection, and HttpClient. Laravel’s DI container and HTTP stack (Guzzle) are incompatible without adapters.
    • Workarounds Required:
      • Option 1: Create a Laravel-specific facade that wraps the bundle’s logic, using Guzzle for HTTP requests and Laravel’s container for DI.
      • Option 2: Extract core logic into a standalone PHP library (e.g., brazilianfriends/frete-calculator) and consume it via Laravel’s HTTP client.
      • Option 3: Microservice Approach: Deploy the bundle in a separate Symfony app and expose its functionality via an API (e.g., REST/gRPC).
  • API Stability: The Correios API is external and may change. The bundle’s maturity (low stars, no dependents) suggests limited community validation of its robustness.

Technical Risk

  • High for Laravel:
    • Refactoring Risk: Adapting the bundle for Laravel may introduce bugs, especially if the bundle assumes Symfony-specific behaviors (e.g., event dispatchers, parameter bags).
    • Maintenance Overhead: Future updates to the bundle could break Laravel-specific wrappers, requiring rework.
  • Low for Symfony:
    • Minimal Risk: Direct integration is low-effort, but vendor lock-in to Correios’ API is a business risk (e.g., if Correios changes their API or pricing model).
  • Dependency Risks:
    • The bundle may pull in outdated Symfony components (e.g., symfony/http-client v4.x), which could conflict with Laravel’s ecosystem.
    • No clear PSR standards compliance (e.g., PSR-15 for HTTP clients), which could complicate testing or mocking.

Key Questions

  1. Business Requirements:
    • Is Correios the only shipping provider needed, or will others (e.g., FedEx, DHL) be added later? If so, a custom abstraction layer is critical.
    • Are there SLA requirements for freight calculations (e.g., real-time vs. batch processing)?
  2. Technical Feasibility:
    • What is the budget for custom integration work (e.g., Laravel wrapper, microservice)?
    • Are there existing Symfony components in the Laravel app that could simplify integration (e.g., a shared microservice layer)?
  3. Long-Term Viability:
    • How will the team handle Correios API changes (e.g., rate limits, deprecated endpoints)?
    • Is there a fallback mechanism if the Correios API is unavailable (e.g., cached rates, manual override)?
  4. Testing and Observability:
    • How will API response validation be handled (e.g., schema validation, retry logic)?
    • Are there monitoring requirements for freight calculation failures or latency?

Integration Approach

Stack Fit

Component Symfony Fit Laravel Fit Mitigation Strategy
Dependency Injection Native (ContainerInterface) Incompatible (Laravel’s Container) Use Laravel’s bind() or a facade pattern.
HTTP Client Symfony’s HttpClient Guzzle (default) or Laravel HTTP Client Abstract HTTP calls to a shared interface.
Configuration Symfony’s Configuration Laravel’s .env + config/ Map Symfony params to Laravel config/environment variables.
Event System Symfony Events Laravel Events Decouple event listeners if needed.
Validation Symfony Validator Laravel Validator Use a shared validation library (e.g., Respect/Validation).

Migration Path

Option 1: Direct Symfony Integration (Low Risk)

  1. Prerequisites:
    • Ensure the Symfony app is on a compatible version (e.g., Symfony 5+ with PHP 8.0+).
    • Install via Composer:
      composer require brazilianfriendsofsymfony/frete-bundle
      
  2. Configuration:
    • Add the bundle to config/bundles.php.
    • Configure parameters.yml or .env with Correios credentials:
      bfos_frete:
          codigo_empresa: "%env(CORREIOS_CODE)%"
          senha: "%env(CORREIOS_PASSWORD)%"
      
  3. Usage:
    • Inject BFOS\FreteBundle\Service\FreteService into controllers/services.
    • Example:
      $frete = $freteService->calcularFrete([
          'codigo_servico' => '40010',
          'peso' => 1.5,
          'largura' => 20,
          'altura' => 10,
          'comprimento' => 30,
          'cidade_origem' => '01001000',
          'cidade_destino' => '01311000',
      ]);
      
  4. Testing:
    • Mock HttpClient for unit tests.
    • Test edge cases (e.g., invalid service codes, API failures).

Option 2: Laravel Integration (High Effort)

  1. Abstraction Layer:
    • Create a Laravel service provider to wrap the bundle’s logic:
      // app/Providers/FreteServiceProvider.php
      namespace App\Providers;
      use Illuminate\Support\ServiceProvider;
      use BFOS\FreteBundle\Service\FreteService as SymfonyFreteService;
      use Illuminate\Support\Facades\Http;
      
      class FreteServiceProvider extends ServiceProvider {
          public function register() {
              $this->app->singleton('frete', function ($app) {
                  return new class {
                      public function calcularFrete(array $params) {
                          // Use Guzzle/Laravel HTTP client to call Correios API directly
                          // or extract bundle logic into a standalone class.
                          $response = Http::post('https://api.correios.com/v1/frete', $params);
                          return $response->json();
                      }
                  };
              });
          }
      }
      
  2. Alternative: Standalone Library:
    • Fork the bundle and extract core logic into a PSR-compliant library (e.g., brazilianfriends/frete-calculator).
    • Publish as a Composer package for Laravel:
      composer require brazilianfriends/frete-calculator
      
  3. Configuration:
    • Store Correios credentials in .env:
      CORREIOS_CODE=your_code
      CORREIOS_PASSWORD=your_password
      
    • Bind to Laravel’s container in config/services.php:
      'frete' => [
          'codigo_empresa' => env('CORREIOS_CODE'),
          'senha' => env('CORREIOS_PASSWORD'),
      ],
      
  4. Usage:
    • Inject the service into controllers:
      use Illuminate\Support\Facades\Frete;
      
      $frete = Frete::calcularFrete([
          'codigo_servico' => '40010',
          'peso' => 1.5,
          // ... other params
      ]);
      
  5. Testing:
    • Mock Http::fake() for API responses.
    • Test error handling (e.g., invalid credentials, rate limits).

Option 3: Microservice (High Scalability)

  1. Deploy Bundle as a Service:
    • Create a Symfony micro-app with the bundle.
    • Expose an API endpoint (e.g., /api/frete/calculate).
  2. **L
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.
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
dmstr/api-platform-utils-bundle
dmstr/api-configuration-bundle
chrisdev/ux-components
baks-dev/finances
emuniq/filament-browser-notifications
syriable/filament-translator
hungnm28/livewire-form
wenprise/eloquent
crudly/encrypted
fadion/bouncy
cuci/prototurk-sdk
gos/pubsub-router-bundle
cuci/prototurk-sdk-symfony
clementtalleu/easyadmin-markdown-bundle