Brazil mandates that every business issuing goods or services emit an NF-e (Nota Fiscal Eletrônica) — a government-signed XML submitted to SEFAZ in real-time. The protocol is SOAP-based, from 2006, documented only in Portuguese, and the homologation environment goes offline on weekends.
I spent 6 months building FoxNFe — a multi-tenant SaaS that abstracts all of this into a simple REST API. Here is everything I learned the hard way.
The Architecture
Tenant App ──REST──► FoxNFe Laravel API ──SOAP/XML──► SEFAZ (27 states) │ PostgreSQL RLS Redis + Queues Certificate Store
Enter fullscreen mode
Exit fullscreen mode
Laravel 11 — API backend, queued jobs, service layer
PostgreSQL + RLS — row-level security per tenant
Redis + Laravel Queues — async processing (SEFAZ takes 2–30s per request)
A1 Digital Certificates — encrypted per-tenant, loaded at runtime
27 SEFAZ endpoints — one per Brazilian state, routed by CNPJ UF
Lesson 1: PostgreSQL RLS finally Is Not Optional
Multi-tenant apps on PostgreSQL often…