Skip to content

How Makeen is built

Makeen is a compliance platform for SAMA-licensed finance and payment companies in Saudi Arabia. This page documents its architecture, database-enforced controls, offline verification, test results, and roadmap.

  1. BrowserTalks only to the web app and never holds tokens.
  2. Web (BFF)Keeps sessions in httpOnly cookies and calls the API.
  3. APIVerifies identity and explicit permissions on every endpoint.
  4. PostgreSQLIsolates each firm's rows and commits changes atomically.
  5. WorkersDeliver outbox events, fire SLA timers, and seal the ledger.
Invariant tests on real PostgreSQL 16
238
Application tables with forced row-level security
62
Hand-written SQL migrations
36
Max interval between signed ledger seals
5 min
Critical or high dependency vulnerabilities
0

Architecture

Modular monolith
Four applications run the system: the API (NestJS), the web app (Next.js 15 with App Router acting as a backend-for-frontend), worker-outbox, and worker-scheduler.
Domain modules
The codebase is structured into 11 modules (RoPA, DSAR, Breach, DPIA, Evidence, Governance, Identity, Integrations, Platform, Admin, and Notification) backed by 9 shared libraries.
Database and background jobs
PostgreSQL 16 is accessed through Kysely over 36 hand-written SQL migrations, with no ORM-generated schema. Background jobs run via pg-boss.
BFF boundary
The web app holds an httpOnly session and calls the API server-side, so authentication tokens never reach the browser. There is no external CDN.

One transaction per change

Atomic commit
Every state-changing command runs inside a single database transaction. Either every record commits together or nothing is written.
What commits together
Each transaction writes the state change, a hash-chained ledger event, the workflow history row, an outbox event, an SLA deadline timer when applicable, and the idempotency reservation.
Database-enforced logging
In application-role sessions on the API path, PostgreSQL refuses to commit a business change without a matching ledger event for that row. Background worker writes are covered by tests, and signed ledger seals extend tamper detection to database-level changes.

Tamper-evident ledger

Append-only storage
The ledger is append-only inside PostgreSQL itself. Direct table writes are revoked and blocked by triggers, and a dedicated role owns the only insert function.
Hash chain and signed seals
Events are hash-chained and sealed with an Ed25519-signed Merkle root at least every 5 minutes and on critical events. Each seal is also copied outside the database.
Independent verification
Verification checks every seal signature and Merkle root against a public key kept outside the database, reconciles the seal copies with PostgreSQL, and compares against a checkpoint kept by the auditor, so deleting the newest seals along with their events is caught.
Fail-closed result
Verification fails closed. Any layer that is skipped reports "partial", never "intact".

How an obligation counts as met

Owner and separation of duties
An obligation counts as met only with current evidence approved by a second person and a named owner holding the owning role. Whoever collected the evidence cannot approve it, enforced directly in PostgreSQL.
Client-side fingerprints
Only evidence with a document fingerprint counts. The browser computes the file's SHA-256 hash locally without uploading the file itself.
Stale-approval guard
Each approval binds to the exact set of evidence shown to the approver. If that set changes beforehand, PostgreSQL rejects the approval with APPROVAL_STALE.
Derived expiry
Evidence remains current only while it falls within the obligation's review cycle and before the document's recorded validity date (covers_until, such as a report period end or certificate expiry). One lapsed item requires re-approval, and "overdue" and "evidence expired" statuses are derived automatically rather than typed in.

Evidence pack, verifiable offline

Pack contents
One download contains every obligation with its owner, derived status, evidence fingerprints and collectors, approving ledger event, and ledger checkpoint. It also includes the signed seals, public key, and a Merkle inclusion proof for each approval.
Sealed before export
Before each export, the register manifest is committed to the ledger and sealed.
Offline verification
An open script (verify-evidence-pack.mjs) checks the pack with no Makeen server required. It confirms no obligation was omitted, no fingerprint was altered, every approval is covered by a signed seal, and recomputes every derived status so tampered expiry states fail.
Key and checkpoint pinning
Auditors can pass --key-sha256 to pin an independently obtained key fingerprint and --checkpoint to pin a recorded ledger checkpoint. This ties the offline check directly to the firm's known key and latest audited state.
Offline verification command
node tooling/scripts/verify-evidence-pack.mjs pack.json \
  --key-sha256 <hex> --checkpoint <seal_index>:<seal_hash>

Access control

Three layers
Requests pass through OIDC/JWT (RS256 with pinned issuer and audience), an explicit permission check on every business endpoint, and PostgreSQL row-level security. Only 4 endpoints are public, strictly for health checks and session bootstrap.
Forced row-level security
FORCE ROW LEVEL SECURITY is enabled across 62 application tables and guarded by a test that fails if any new table lacks protection. The organisation id is derived on the server and never crosses the API boundary.
Isolated database roles
Separate database roles isolate access, including a physically read-only audit role. The application role cannot bypass row-level security.
Data hygiene and secrets
No personal data is written to logs, URLs, or event payloads. In production, the service refuses to start without required secrets.

Testing

Invariant tests
All four CI jobs pass, including 238 invariant tests across 16 files against real PostgreSQL 16. They directly verify separation of duties, the append-only ledger, zero row-level-security leaks, chain integrity, idempotency, SLA timers, and Merkle sealing.
Unit and HTTP tests
The test suite also runs 168 unit tests and 84 HTTP end-to-end assertions.
Security scanning
The security job runs gitleaks, OSV-Scanner, Semgrep, and Trivy. The dependency audit reports 0 critical and 0 high vulnerabilities.
Verification benchmarks
Across 407 obligations, 1,200 evidence items, 300 approvals, and about 23,000 ledger events, offline pack verification completes in 0.07 to 0.12 s and full hash-chain recomputation takes 17 to 26 s.

On the roadmap

Upcoming capabilities planned for production deployments.

  • Evidence file upload and storage hosted inside Saudi Arabia.
  • Production single sign-on with OIDC and MFA.
  • Hosting inside Saudi Arabia with a documented backup and restore runbook.
  • Signing key custody in an HSM or KMS and S3 Object Lock (WORM) storage for seal copies.
  • An external penetration test and load testing.