Case study · Multi-tenant SaaS
CRMA
A multi-tenant CRM where AI agents propose and people approve.
Engineering project

The run is paused here
CRMA is a multi-tenant CRM built on Laravel 12 and React 19. AI agents can search, research and draft, but they can never change data on their own. Every write becomes a proposal with a field-level diff, a stated reason and a risk class, and the agent run pauses until a person approves, edits or rejects it.
- Role
- Repository owner and engineering lead, with AI pair programming
- Domain
- B2B sales CRM in Arabic and English
- Surfaces
- Web app, versioned REST API and an MCP server
- Status
- Pre-launch. Not deployed to production
The problem
- 01
Sales teams want AI help, but a model with write access to shared customer records is a liability. One wrong stage change or outbound message reaches real people.
- 02
Most AI features in a CRM either stay read-only and add little, or act on their own and add risk.
- 03
Teams in the Gulf need a native Arabic, right-to-left interface, not a translated afterthought.
Core modules
One workspace for the whole pipeline. Every screen here is the running application on seeded demo data.

Kanban stages with a rule-based health score on every card, and a review strip that counts stale, stuck and unscheduled deals.
How work moves through the system
Event-driven. A record change can start a workflow, the AI reads freely, and every write it wants waits for a person.
Step 01
Intake
Leads arrive from Meta lead ads, WhatsApp, web forms and CSV import.
- Meta lead ads
- Forms
- CSV import

Step 02
Record and score
Each lead becomes a record with a rule-based score, and every deal carries a health score. The numbers come from CRM data, not from a model.

Step 03
Automate
A record event starts a workflow. The graph is validated before it can be activated, and its expressions use a typed DSL instead of eval().
- trigger → condition → action

Step 04
Propose
The copilot reads and searches freely. Anything that would change data becomes a proposal with a diff, a reason and a risk class, and it expires after 72 hours by default.
- agent_action_proposals

Step 05
Decide
A person approves, edits or rejects it in the AI Action Center. Only low and medium risk proposals can be approved together.

Step 06
Execute and resume
Only an approved action runs. The paused agent run then resumes with its context intact, and the proposal moves to its final tab in the Action Center.

System architecture
A modular monolith. Every box maps to code or configuration in the repository.
Surfaces
One codebase, four ways in.
- Inertia v2 · React 19
- REST /api/v1 · 244 routes
- AI API · 41 routes
- MCP server · OAuth 2.1
Edge and policy
Scoped to a tenant and checked against a policy before any domain code runs.
- nginx
- 26 middleware
- Organisation scope
- 49 policies
- Rate limits
- Idempotency keys
Application
Laravel 12 on PHP 8.3, split by domain.
- CRM domains
- Workflow engine
- Pipeline intelligence
- Agent runtime · 19 tools
- Model router
- Hybrid knowledge retrieval
app/Ai/* · DealSignalCalculator · PipelineIntelligence
Async and realtime
Queues split by workload, a scheduler and WebSockets.
- Redis 7
- Horizon queues
- Reverb WebSockets
- Scheduler
queues: default/imports · email · ai/agents · webhook · whatsapp_outbound
Data
One relational store, scoped by organisation.
- MySQL 8
- 150 models
- 168 migrations
Delivery
Docker Compose services, a GitHub Actions pipeline for tests, lint and deploy, and a release script that switches an atomic symlink and rolls back when the health check fails.
Governed AI: propose, review, execute
The agent runtime pauses the run, shows a field-level diff with the reason and the risk, and resumes only after a human decision.
Reads run immediately. Writes wait for a person.
Saffron asked for a formal proposal — update the deal stage.
Started
An illustrative replay of the copilot screen below. The proposal, its fields and its reason are copied from that screen; the timing is not. Record content stays in English, as it does in the app.
Risk classes
Every tool is classed by its consequence, not by its name.
- READRuns immediately
- LOW_WRITEBecomes a proposal
- MEDIUM_WRITEBecomes a proposal
- HIGH_EXTERNALAlways needs approval
- CRITICALNeeds approval, never in bulk
app/Ai/Tools/Risk.php
Bulk approval is offered only for low and medium risk. Proposals expire after 72 hours by default.




How these screens were made
The copilot screens use the project’s deterministic Fake model driver, the same approach as its end-to-end tests. Only the model’s choice of tool calls was scripted. Tool execution, policy checks, risk classification, proposal creation and the run pause are the real application code. No live model call was made.
Analytics that are computed, not guessed
Deal health, pipeline review and lead scores are deterministic rules over CRM data. The AI can explain a number; it does not invent one.

Stated on the screen
Deal workspace: the health score and the rule that cost points
Pipeline review
Eight rule-based signals, recounted over the open deals each time the review runs.
- Close date passed
- Stale
- Stuck in stage
- No next step
- Commitments due
- Closing soon
- No contact
- Recently advanced
DealSignalCalculator · PipelineIntelligence · config/intelligence.php


Figures in these screens are seeded demo values, not business results.
Security, tenancy and access control
Defence in depth, enforced at the middleware, policy and validation layers, and covered by tests.
- 01
Identity
TOTP two-factor sign-in, OIDC single sign-on, SCIM provisioning, session management and IP allowlists.
- 02
Request hygiene
Rate limiting, idempotency keys and security headers.
app/Http/Middleware
- 03
Tenant isolation
Organisation scoping, plus validation rules that reject a reference to another tenant’s records.
app/Rules/TenantExists.php · tests/Feature/Tenancy
- 04
Authorisation
Roles per organisation and Laravel policies, with tests that keep the API and the interface in parity.
tests/Feature/Rbac
- 05
Outbound calls
An SSRF-safe fetcher: public addresses only, the connection pinned to the validated address, and every redirect checked again.
app/Support/Http/SafeHttpFetcher.php


Responsive by default
The same React components adapt to a 390 px viewport, approvals and the deal workspace included.
Arabic and English, one codebase
The same pipeline in both reading directions. Drag across it to compare.


- Each page loads its own translation namespace.
- Layouts mirror through logical CSS properties, not hard-coded left and right.
- Record content stays in the language it was entered in. It is data, not interface.
Engineering evidence
Counts measured from the repository on 14 Oct 2026.
- Routes
- 1,054
- Models
- 150
- Migrations
- 168
- Controllers
- 155
- Policies
- 49
- Middleware
- 26
- Jobs
- 25
- Inertia pages
- 183
- AI tools
- 19
- Agent profiles
- 15
- Governed actions
- 8
- PHP test files
- 417
- Frontend test files
- 268
- Playwright specs
- 22
No eval()
Workflow expressions moved to a typed DSL, and an audit command finds legacy definitions and pauses them.
Measured retrieval
Knowledge search fuses BM25 and vector results with Reciprocal Rank Fusion, and an eval harness reports recall@k and MRR.
MCP with OAuth 2.1
PKCE S256, hashed audience-bound tokens and rotating refresh tokens with reuse detection. External agents can read or propose, never write.
What was verified
- A model-directed agent loop with server-side step and tool-call limits (AgentRuntime).
- AI writes stored as proposals with a 72-hour expiry, executed only after approval (ActionEngine).
- Hybrid retrieval: lexical and vector results fused with RRF, filtered by organization.
- An MCP server behind OAuth, exposing read and propose tools to external agents.
- Organization-scoped data with tenant-isolation tests.
Executed on 18 Oct 2026: 139 targeted Pest tests passed with 578 assertions (AI, RBAC, workflows and tenant isolation), on SQLite in memory. The full suite was not run; the repository’s own plan lists failing backend tests.
What I do not claim
- Pre-launch. The repository’s own production plan scores readiness at 47/100 and marks it NO-GO.
- There are no customers, revenue or usage figures, and none are implied.
- Stripe, Twilio, WhatsApp, Meta and model providers were not exercised live; some are partial.
- No load tests have been run, so scalability is an architectural property only.
- Every record on screen is seeded or fictional demo data.
Architecture
A modular Laravel 12 monolith serving an Inertia and React 19 app, a versioned REST API, an AI API and an MCP server. MySQL 8 and Redis 7 with Horizon queues, Reverb WebSockets and a scheduler, packaged as Docker Compose services and shipped through GitHub Actions.
Stack
Laravel 12 · PHP 8.3 · Inertia v2 · React 19 · TypeScript · Tailwind CSS 4 · MySQL 8 · Redis 7 · Horizon · Reverb · Sanctum · Pest · Vitest · Playwright · Docker · GitHub Actions
Source
Private repository








