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

Filament Cep Field Laravel Package

jeffersongoncalves/filament-cep-field

Filament CEP Field adds a Brazilian postal code (CEP) input to Filament forms with automatic 99999-999 formatting, validation, and address lookup via BrasilAPI/ViaCEP/AwesomeAPI. Includes Laravel model caching, invalidation, queue support, and full Brazilian states mapping.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Pros:

    • Domain-Specific Optimization: Tailored for Brazilian postal code (CEP) use cases, reducing custom development effort for address validation and lookup.
    • Filament Integration: Leverages Filament’s form ecosystem, ensuring consistency with existing UI/UX patterns (e.g., validation, error handling).
    • API Abstraction: Supports multiple CEP APIs (BrasilAPI, ViaCEP, AwesomeAPI) via a unified interface, simplifying vendor switching.
    • Caching Layer: Built-in Laravel Model Caching + queue-based invalidation reduces external API calls and improves performance.
    • Extensible: Customizable field mappings, error messages, and UI (e.g., button position/label) align with Filament’s fluent API style.
  • Cons:

    • Coupling to Filament: Tight integration with Filament v5.x+ limits reuse in non-Filament Laravel apps or other frameworks.
    • API Dependency: Relies on third-party APIs for address lookup, introducing external latency and potential downtime risks.
    • Regional Scope: Only relevant for Brazilian applications (CEP-specific logic).

Integration Feasibility

  • Laravel/PHP Stack Fit:

    • Native Compatibility: Works seamlessly with Laravel 10.x+, PHP 8.2+, and Filament 5.3+. No major framework conflicts.
    • Dependency Graph: Lightweight (~100KB) with minimal external dependencies (only Filament and Laravel core).
    • Database Requirements: Requires a migration for caching tables (minimal schema changes).
  • Key Integration Points:

    1. Form Components: Replaces manual CEP input fields in Filament forms (e.g., CepInput::make()).
    2. API Clients: Under-the-hood HTTP calls to CEP APIs (handled internally; no direct client configuration needed).
    3. Event System: Supports caching events (e.g., CepCached, CepCacheInvalidated) for custom logic.
    4. Validation Rules: Integrates with Filament’s validation pipeline (e.g., required(), custom error messages).

Technical Risk

Risk Area Severity Mitigation
API Downtime High Fallback to cached responses; implement retry logic or local backup APIs.
SSL Certificate Issues Medium Pre-configure cacert.pem or use Laravel’s HTTP client with custom CA paths.
Filament Version Lock Medium Pin Filament to ^5.3 to avoid breaking changes (e.g., PageConfiguration).
Cache Staleness Low Queue-based invalidation ensures freshness; monitor cache hit/miss rates.
Regulatory Compliance Low Ensure API providers (e.g., ViaCEP) comply with Brazilian data privacy laws.

Key Questions for TPM

  1. API Strategy:

    • Should we implement a local CEP database fallback for offline use or high availability?
    • How will we handle API rate limits or usage quotas (e.g., ViaCEP’s free tier)?
  2. Data Flow:

    • Will address data populate other fields (e.g., street, city) in Filament forms, or should we use a separate address resource?
    • How will we sync CEP data with existing address models (e.g., Eloquent relationships)?
  3. Performance:

    • What are the expected cache hit rates for CEP lookups? Should we add a TTL-based fallback?
    • Will the queue-based cache invalidation impact form submission latency?
  4. Localization:

    • Are there plans to extend this for other regions (e.g., US ZIP codes)? If not, should we abstract the CEP logic?
  5. Testing:

    • How will we mock API responses in CI/CD (e.g., using Http::fake())?
    • Should we add integration tests for cache invalidation scenarios?

Integration Approach

Stack Fit

  • Primary Use Case: Filament Admin Panels (e.g., user profiles, business listings, or e-commerce addresses).
  • Secondary Use Case: Customer-Facing Forms (if embedded via Filament’s frontend features).
  • Anti-Patterns:
    • Avoid using this for non-Brazilian regions (e.g., international addresses).
    • Not suitable for CLI or non-web contexts (e.g., Laravel queues, scheduled tasks).

Migration Path

  1. Pre-Installation:

    • Verify Laravel/Filament versions (laravel/framework: ^10.0, filament/filament: ^5.3).
    • Check PHP SSL configuration (resolve cacert.pem issues if present).
    • Assess API provider quotas (e.g., ViaCEP’s free tier allows 1,000 requests/day).
  2. Installation:

    composer require jeffersongoncalves/filament-cep-field
    php artisan vendor:publish --tag=cep-migrations
    php artisan migrate
    
  3. Form Integration:

    • Replace existing CEP inputs with CepInput::make() in Filament resources/pages.
    • Example:
      use JeffersonGoncalves\Filament\CepField\Forms\Components\CepInput;
      
      CepInput::make('cep')
          ->required()
          ->setStreetField('address_line_1')
          ->setCityField('city')
          ->setStateField('state');
      
  4. Post-Installation:

    • Test with valid/invalid CEPs (e.g., 01310100 for São Paulo).
    • Monitor API response times and cache efficiency (e.g., via Laravel Debugbar).

Compatibility

Component Compatibility
Filament Forms ✅ Full support (replaces TextInput for CEP fields).
Filament Tables ❌ No direct support (use for forms only; display CEP as plain text).
Livewire ✅ Underlying Livewire components ensure reactivity.
API Providers ✅ Multi-provider support (configurable via environment variables).
Laravel Queues ✅ Cache invalidation uses queues (no blocking I/O).

Sequencing

  1. Phase 1: Core Integration

    • Replace CEP fields in critical Filament forms (e.g., user onboarding).
    • Validate API responses and error handling.
  2. Phase 2: Caching Optimization

    • Configure cache TTLs based on usage patterns (e.g., 24h for static addresses).
    • Implement fallback logic for API failures (e.g., cached data or manual entry).
  3. Phase 3: Monitoring

    • Add logging for API failures (monolog channel).
    • Set up alerts for cache miss rates > 5%.
  4. Phase 4: Scaling

    • Distribute cache across multiple servers (if using Redis).
    • Consider a local CEP database for high-volume apps.

Operational Impact

Maintenance

  • Pros:

    • Minimal Codebase: Package handles CEP logic; no need to maintain custom validation/masking.
    • Centralized Updates: Dependencies (e.g., Filament, Laravel) managed via Composer.
    • API Abstraction: Switching providers requires only config changes.
  • Cons:

    • Vendor Lock-in: Tied to Filament’s form system; migrating to another admin panel would require rewrites.
    • Dependency Updates: Must monitor Filament major versions (e.g., v5.x → v6.x) for breaking changes.
  • Maintenance Tasks:

    • Quarterly: Update package and test CEP API compatibility.
    • Annually: Review cache invalidation logic for edge cases (e.g., CEP changes).

Support

  • Common Issues:

    • SSL Errors: Document cacert.pem setup for devops teams.
    • API Limits: Monitor usage and implement fallback strategies.
    • Cache Staleness: Educate users on manual cache invalidation (e.g., php artisan cep:clear-cache).
  • Support Channels:

    • GitHub Issues: Active maintainer (Jèfferson Gonçalves) responds to bugs.
    • Filament Community: Leverage Filament’s Slack/Discord for integration help.

Scaling

  • Horizontal Scaling:

    • Cache: Redis/Memcached for distributed caching (package supports Laravel’s cache drivers).
    • API Load: Queue CEP lookups for non-critical paths (e.g., background jobs for address enrichment).
  • Vertical Scaling:

    • Database: Ensure cep_cache table is indexed for fast lookups.
    • API Rate Limits: Implement exponential backoff for retries.
  • Performance Bottlenecks:

    • API Latency: Mitigate with aggressive caching (e.g., 1h TTL for static addresses).
    • Form Rendering: Avoid overusing `
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.
besmartand-pro/php-quality-config
sentix/ai-chatbot
terminal42/code-quality-tools
codifyo/ts-generator-bundle
testo/fiber
mintobit/jobqueue
a4sex/maintenance-bundle
a4sex/entity-date-update
a4sex/client-identifier
a4sex/base-utilites
a4sex/key-value-storage
a4sex/micro-status
chilldev/dependency-injection-extra
datinglibre/datinglibre-app-api
biberltd/corebundle
bricre/symfony-bundle-test
biberltd/logbundle
dominium/http-adapter-bundle
dominium/google-analytics
a4sex/auto-clean-entity