Mshalia
A centralized ERP for Arabian horse studs and farms. It manages horse records, clients, breeding contracts, and invoices — with QR codes and digital signatures — plus financial reporting, fully in both Arabic and English.
One hub runs the whole stud. Track horses, clients, and breeding contracts; generate signed, QR-coded invoices and contracts on demand; and watch revenue, expenses, and margins on a live dashboard — with access scaled by role, from super-admin down to the client.
What it solves
- Farm operations are scattered: managers have no central system for client records, breeding contracts, invoices, and finances.
- Contracts and invoices are typed by hand, with no templates or PDF generation.
- Revenue, expenses, and margins sit in spreadsheets with no dashboard to see them.
- Client communication — invoices, contracts, reminders — is scattered across email with no audit trail.
- Arabic and English paperwork has to be kept in sync by hand, in separate files.
Impact
super_admin → client, per-route
Signed contracts & invoices
Revenue, expense, margin

Architecture
Data flow
- Admin uploads horse record
- POST /api/horses (auth + role verified)
- Firestore insert → horses/{id}
- Function: compress images + thumbnails
- Dashboard: Server Component → Firestore → Recharts
- Invoice request → /api/invoices/generate (rate-limited)
- @react-pdf/renderer + pdf-lib (QR + signature) → Storage
- Signed URL → email via Function → client scans QR to pay
Engineering decisions
Firestore for document-oriented data
Horse records, clients, and contracts are JSON docs with real-time listeners for the live dashboard; no schema migrations, flexible as farm requirements evolve.
Server-side PDF generation on the fly
@react-pdf/renderer renders React components to PDF and pdf-lib adds QR codes + signatures, keeping templates in code (not external tools); output is cached in Storage.
Role-based middleware gating
proxy.ts checks the session cookie, validates the role in users/{uid}, and allows or denies the route — no per-endpoint repetition.
Rate limiting by tier
Expensive PDF generation is limited to 10/min while reads allow 60/min, preventing abuse during high-volume invoice requests.
Bilingual with transliteration
Contracts generate in Arabic and English; a transliteration step converts horse names (اسم) to Latin characters for filing and email, and Firestore stores both variants.
Gallery



