Smart ERP
A 96-table ERP and CRM for a smart home and access control company, from lead to invoice to support.
Smart ERP is the internal system of an Egyptian smart home and access control company: 96 tables, 19 modules, and 321 Row-Level Security policies covering the sales pipeline, site surveys, quotes, inventory with serial numbers, purchasing, projects and field visits, invoicing with Egyptian Tax Authority e-invoicing, cash, contracts, and support tickets. I designed and built it alone on Next.js and Supabase.
The context
The company runs two business lines on one team: residential smart home installs (high volume, short sales cycle) and B2B access control for offices, factories, and compounds (tenders, long cycles, multi-year maintenance contracts). Spreadsheets and chat threads could not hold either.
This is an installation business, not retail. Money enters as a quote built from a site survey and leaves as a completed install of serialised hardware under warranty. The system had to model that lifecycle: lead, survey, quote, job, invoice, support.
What I built
Nineteen modules built one at a time, each used on real data before the next one started.
- CRM: leads, customers, contacts, sites, pipelines, opportunities, activities, WhatsApp threads
- Catalog, kits, price lists, survey templates, surveys, and quotes
- Stock with locations, serial units, moves, reservations, and counts
- Suppliers, purchase orders, goods receipts, and landed cost
- Projects, phases, materials, technician scheduling, visits, checklists, and time entries
- Invoices, ETA e-invoice submissions, payments and allocations, expenses, petty cash, company cash, commissions
- Service contracts (AMC), preventive schedules, tickets with SLA, warranty claims
- Twelve seeded roles and 162 permissions enforced by a registry-driven RLS generator
- AI layer: prompt registry, run log, and an analytics chat that turns questions into guarded SQL
- Reports, five reporting views, and a finished design system
How it works
The schema is the product. Fifty migrations build 96 tables across public, private, and reporting schemas, and a registry-driven generator writes the Row-Level Security policies so every new table is covered by construction. Audit passes closed the tables that had slipped through and added denormalised team and branch scope columns so records never silently disappear from the people who should see them.
Money is modelled honestly: VAT applies only when the company is registered, outbound supplier payments and overheads have a home, and a company cash view answers the one question the owner kept asking, how much money do we have. The e-invoicing module submits to the Egyptian Tax Authority and tracks each submission.
The AI analytics chat generates SQL with Gemini and runs it through a guarded function that only permits reads over the reporting views, so a wrong answer is a wrong number, never a changed record.
The outcome
Build steps 0 to 14 are shipped and running on the cloud; the business operates on it daily, and each release is versioned in a changelog.
It is the deepest ERP I have built alone and the reference for what I mean by a CRM: the whole company in one system.
More work
Have a project like this?
I build platforms, apps, and systems like these end to end, from Cairo and remote worldwide. Tell me what you are building.