Garnet CRM
Multi-tenant CRM for field sales and collections teams
THE CHALLENGE
Field sales teams record visits, orders, deliveries, and cash across many people and areas. The numbers pass through several hands, and when someone asks who changed a balance, there is often no answer. I wanted one system where each level of a company sees only what it should, the money follows normal accounting rules, and every change leaves a trail.
TECH STACK
Engineering Approach
Organization Structure as the Model
Modeled a company as regions, areas, and teams, with regional and area managers, salespeople, and collectors. Roles are assigned by the level above, and each area manager gets separate daily reports from sales and collections.
Permission Engine with Access Levels
Each person has one access level, either a prepared role or a custom checklist of permissions. Only owners create and edit access levels, and the most sensitive permissions are limited to the owner and accountant.
Tenant Isolation by URL
Every organization lives under its own URL, and a person sees only the organizations they belong to. Onboarding is by invitation.
Design Before Code
Wrote a design document and worked through the rules first: credit limits, payment allocation, post-dated cheques, returns, and who can approve what. The code then enforces decisions that were already made.
Key Technical Decisions
The choices that shaped the architecture and how easy it is to maintain.
Scoped visibility, money never edited, everything audited
Three promises, fixed before building.
When people hand over cash, trust has to come from the system. Fixing these rules early means every later feature has to respect them.
One access level per person
Customizing an access level means saving a new one, with no per-person exceptions.
Exceptions pile up until nobody can explain who can do what. One level per person keeps permissions explainable.
The system does not issue invoices
Receipts carry whatever invoice or VAT numbers each company enters on its own form.
Invoicing rules differ by company and country, so the product stays general and out of that scope.
A credit limit is the only order block
Overdue amounts are shown, but only the credit limit stops an order.
One predictable rule is easier to work with than several overlapping holds.
Challenges & Solutions
The first organization model was too flat. Real teams have regions above areas and several collectors per area.
Reworked the structure to regions, areas, and teams before building on top of it.
Password reset by email needed a custom sender and a verified domain.
Set up Resend as the sender with a custom reset email template, so reset works end to end in production.
The preview deployment kept failing even though the code was fine.
The environment variables, including the direct database URL, were set for production but not for the preview environment. Setting them there fixed it.
Outcomes
Garnet CRM has working sign-in, organization isolation by URL, a permission engine, a team page with invitations, email password reset, and Arabic and right-to-left support, deployed on Vercel.
KEY TAKEAWAYS
Writing the rules down first made the code simpler. The permission engine only had to enforce decisions that were already made, instead of inventing them as it went.
