Autofacture DZ
Invoicing tool built for Algeria's auto-entrepreneurs — the self-employed workers who need to generate compliant invoices but don't want to deal with accounting software designed for enterprises.
The niche
Algeria introduced the auto-entrepreneur statute a few years ago — it lets freelancers and small traders operate legally with simplified tax obligations. The catch: you have to generate compliant invoices for every transaction, and quarterly declarations need structured data.
Most auto-entrepreneurs fall into one of three categories:
- Freelancers (developers, designers, translators) who bill international clients
- Small traders who sell goods locally
- Service providers (photographers, consultants, tutors) who invoice individuals
The invoicing requirements are specific:
- Invoice number must be sequential (no gaps allowed)
- Certain fields are mandatory: NIF (tax ID), auto-entrepreneur card number, name, client name, date, line items with amounts
- Auto-entrepreneurs don't charge VAT, and the invoice has to say so
- Declarations need turnover figures that match the invoices exactly
Most auto-entrepreneurs either use Word templates (error-prone, non-sequential numbering) or generic invoicing tools that don't understand Algerian tax rules. The few accounting tools that exist are designed for full companies and cost more than most auto-entrepreneurs earn.
What Autofacture does
You enter your business info once (NIF, auto-entrepreneur card number, name, address, activity), add your client's info, line items, and the system generates a compliant PDF invoice. It also tracks your quarterly revenue and generates the declaration summary.
Invoice generation
The PDF generation pipeline:
- User fills in the invoice form (client, items, notes)
- The system validates all required fields
- An invoice number is assigned from a sequential counter (per-user, per-year:
INV-2026-0001) - A Blade template renders the invoice as HTML
- Headless Chrome (via Puppeteer) converts the HTML to PDF
- The PDF is stored and the download link is returned
Why Puppeteer instead of dompdf or TCPDF? Because the invoice template includes Arabic text in the header (the business name and address in Arabic), and the PHP PDF libraries handle Arabic/RTL text poorly. Puppeteer renders it perfectly because it uses the same rendering engine as Chrome.
The template carries the mandatory mentions for an auto-entrepreneur invoice:
┌─────────────────────────────────────────────┐
│ [Business Logo] [Business Name AR/FR] │
│ NIF: xxxxxxx AE card: xxxxxxx │
│ Address line 1, Address line 2 │
├─────────────────────────────────────────────┤
│ Invoice #: INV-2026-0042 Date: 2026-08-15│
│ Client: Client Name │
│ Client NIF: xxxxxxx │
├─────────────────────────────────────────────┤
│ Description Qty Unit Price Total │
│ ───────────────────────────────────────── │
│ Web development 1 15,000 DA 15,000│
│ Hosting (1 month) 1 2,000 DA 2,000│
├─────────────────────────────────────────────┤
│ Total: 17,000 DA │
│ VAT not applicable (auto-entrepreneur) │
├─────────────────────────────────────────────┤
│ Payment terms: Net 30 days │
│ Bank: BNA Account: xxxxxxxxxxx │
└─────────────────────────────────────────────┘
Tax calculation
The auto-entrepreneur regime replaces the usual taxes with a single flat tax on declared turnover, capped by an annual turnover ceiling. The rate and the ceiling live in settings, not in code: they're set by the finance laws and can change from one year to the next.
The calculation runs on every invoice save, not at declaration time. This means the user always sees their current tax obligation and can plan accordingly.
Revenue tracking
The dashboard shows:
- Monthly revenue (current and previous months)
- Cumulative quarterly revenue against the tax threshold
- Tax owed (calculated in real-time)
- Invoice count (monthly and total)
- Outstanding payments (invoices marked as unpaid)
The declaration summary is generated automatically — a table of revenue per month, the applicable rate and the calculated tax. The user can print this or copy the numbers into the official declaration form.
Multi-currency
Many auto-entrepreneurs bill international clients in EUR or USD. The system:
- Stores the original currency and amount on the invoice
- Records the exchange rate at the time of invoice creation (pulled from the official Bank of Algeria rate)
- Displays the DZD equivalent for tax calculation purposes
- The PDF shows both the original amount and the DZD equivalent
Technical details
Stack: Laravel + Inertia.js + Vue.js + Tailwind CSS
The PDF generation was the most technically interesting part. I tried three approaches:
- dompdf — PHP library, renders HTML to PDF. Failed on Arabic text (rendered as squares) and complex CSS layouts
- TCPDF — better Arabic support but very limited CSS. The invoice template looked nothing like the design
- Puppeteer (headless Chrome) — renders the HTML template exactly as designed, handles Arabic/RTL perfectly, supports all CSS features
The Puppeteer approach requires a headless Chrome instance running on the server. I use puppeteer with a custom Docker image that includes Chrome. The generation takes about 2-3 seconds per invoice — acceptable for a user-facing action.
Database: The schema is simple — users, clients, invoices, invoice_items, tax_settings. The interesting part is the invoice numbering: no gaps and no duplicates, even when two invoices are created at the same moment. Each user has one counter row per year, locked inside the transaction that creates the invoice:
DB::transaction(function () use ($user, $data) {
// One counter row per user and year, locked for the duration of the transaction.
$counter = InvoiceCounter::where('user_id', $user->id)
->where('year', now()->year)
->lockForUpdate()
->firstOrFail();
$counter->increment('last_number');
return $user->invoices()->create([
...$data,
'number' => sprintf('INV-%d-%04d', $counter->year, $counter->last_number),
]);
});
The second request waits for the first to commit, then takes the next number. If the insert fails, the transaction rolls back and the number is never used, so there are no gaps.
Results
- Used by 150+ auto-entrepreneurs
- Generated 2,000+ compliant invoices
- Average invoice creation time: under 2 minutes
- Zero compliance issues reported
- 99.8% uptime
Building something similar?
Tell me where you are and what's blocking you. I'll give you an honest read on how I'd approach it.