Inspiration The inspiration behind eFactura came from a simple observation : thousands of Moroccan small businesses — from corner stores in Derb Omar to small service providers across the country — are still managing their invoices manually on Excel or paper. With the DGI (Morocco's tax authority) mandating e-invoicing in UBL 2.1 format for all businesses by 2027, and 90% of TPEs having no ready solution, we saw a critical gap. We asked ourselves : what if a small merchant could just take a photo of a delivery note and have everything done automatically — invoice generated, VAT calculated, tax declaration pre-filled ? That question became eFactura.

What it does eFactura.ma is an AI-powered web application that automates the most time-consuming parts of financial administration for Moroccan small and medium businesses. It does three things :

  1. Intelligent document capture — The user takes a photo of any commercial document (receipt, delivery note, purchase order). Gemini Vision API reads and understands the document, extracting the client name, products, quantities, prices, and applicable VAT rate — even from imperfect images.
  2. Compliant invoice generation — The app automatically generates a DGI-compliant invoice in both PDF format (with all required legal mentions : ICE, IF, RC) and XML UBL 2.1 format, which is the standard required by Moroccan tax law. Invoices are sequentially numbered, electronically signed, and archived for 10 years.
  3. Tax declaration automation — Every month, the app aggregates all invoices, calculates the VAT balance (collected minus deductible), and pre-fills the SIMPL declaration form. Users receive alerts at D-30, D-7, and D-1 before fiscal deadlines to avoid late penalties.

How we built it We built eFactura using a four-layer architecture :

Frontend : React + TypeScript with TailwindCSS, built as a PWA for mobile-first usage Backend : FastAPI (Python) orchestrating the full OCR + AI pipeline AI layer : Gemini Vision API for intelligent data extraction from document images, combined with Tesseract OCR and OpenCV for image preprocessing and correction. Prompts were specifically engineered for Moroccan fiscal vocabulary (ICE validation, Moroccan VAT rates, DGI terminology) Infrastructure : PostgreSQL for data storage, Redis + Celery for async task queues, AWS S3 with AES-256 encryption for long-term invoice archiving, deployed on EC2 with Docker

The core innovation is the Gemini-powered extraction pipeline : instead of rigid templates, Gemini understands the semantic meaning of any commercial document and returns structured JSON data ready for invoice generation.

Challenges we ran into Moroccan document diversity — Commercial documents in Morocco come in many formats, languages (Arabic, French, mixed), and quality levels. Training our prompts to handle this diversity while correctly identifying ICE numbers and applicable VAT rates (Morocco has five rates : 20%, 14%, 10%, 7%, 0%) was a significant challenge. DGI compliance complexity — The UBL 2.1 XML standard required by the DGI has very specific field requirements. Building a generator that produces valid, legally compliant XML for every invoice type (standard, credit note, partial payment) required deep research into Moroccan tax law. AI error handling — Gemini occasionally misreads ambiguous documents. We had to design a validation layer that flags uncertain extractions and presents them to the user for confirmation before any invoice is finalized — because in a fiscal context, errors have real legal consequences.

Accomplishments that we're proud of

Building a full end-to-end pipeline : photo in → DGI-compliant invoice out, powered by Gemini Vision Achieving reliable data extraction across diverse Moroccan commercial document formats in both French and Arabic Designing a system that makes e-invoicing compliance accessible to a merchant with no accounting background — if you can take a photo, you can use eFactura Identifying and integrating the MOWAKABA subsidy program, which reduces the real cost for TPEs from 249 DH/month to just 25 DH/month — effectively removing the financial barrier to adoption

What we learned

Gemini Vision is remarkably capable for document understanding, especially when prompts are domain-specific. Generic prompts give generic results — fiscal-vocabulary-aware prompts give production-ready results. The real challenge in B2B SaaS is not building the product — it's understanding the regulatory and operational context deeply enough to build something that actually fits into a real workflow. AI confidence is not binary — we learned to design around uncertainty, always keeping a human validation step before any legally binding action. The MOWAKABA program is massively underutilized — most TPEs eligible for 90% digitalization subsidies don't even know it exists. Distribution and awareness are as important as the product itself.

What's next for eFactura

Bank reconciliation module — automatic matching of bank statement transactions to invoices, with AI-assisted resolution for ambiguous cases and automatic payment reminder emails Full accounting journal — every invoice automatically generates the corresponding accounting entry, moving eFactura from invoice management toward genuine accounting automation Open Banking integration — connecting directly to Moroccan bank APIs to eliminate manual CSV imports Predictive fiscal analytics — using historical invoice data to forecast monthly VAT obligations and cash flow, giving merchants visibility weeks in advance Cabinet comptable multi-tenant mode — allowing accounting firms to manage 50+ client companies from a single dashboard Commercial launch on the MOWAKABA program — targeting the 357,000 TPEs and 21,000 PMEs facing the DGI 2027 deadline, with a goal of 2,000 paying clients by month 12

Built With

  • ai
  • nextjs
Share this project:

Updates