skip to content

// saas platform

Patchgrid

Multi-tenant IT service management with isolation enforced by the database.

Patchgrid is a ticketing and operations platform for IT and security teams. Each company gets its own subdomain, and its data is isolated at the database level through five independent layers, not by remembering a WHERE clause. All fourteen milestones are built: four ITIL record types with SLA clocks, email intake, passkeys and per-tenant single sign-on, an operator back-office that never impersonates, signed webhooks, reports under 25 ms at 100,000 tickets, and a production rehearsal on emulated AWS.

// tenants01/22
year
2026
type
saas platform
group
platforms and backends
status
complete, all milestones built
tests
2,315

//in plain words

Patchgrid is a help desk for company IT teams. Many companies share one system, but the database itself refuses to show one company another company's tickets, even if a programmer makes a mistake. Staff raise incidents and requests on the web or by email, agents work them against response-time clocks, and every change is approved by someone other than its author.

for IT and security teams, and engineers who want to see tenancy done at the database

the problem

//01the problem

Multi-tenant apps usually trust every query to filter by tenant. One forgotten filter leaks another customer's tickets. I wanted a platform where a cross-tenant read is not a bug you can write.

how it works

//02how it works

  1. 01

    Five layers of isolation

    Composite (orgId, id) foreign keys make a cross-tenant reference unrepresentable, because Postgres checks foreign keys with row security off. The tenant comes from the credential, never the host. Every repository method takes an explicit orgId. A Prisma client extension sets a transaction-local config and throws without context. Postgres enforces it all with forced row level security and an app role that cannot bypass it.

  2. 02

    Four ITIL records, four lifecycles

    Incidents, service requests, problems and changes are modeled as different things with their own states and one transition endpoint. Priority is computed from impact and urgency, and a client that sends one gets a 400. SLA clocks run around the clock, pause while waiting on the requester, and are swept per tenant.

  3. 03

    Everything a desk needs

    Mail to the workspace becomes a ticket if it passes DMARC, and replies thread onto it. A versioned knowledge base suggests articles while a requester types. Assets link to tickets. Queues keep saved views and act on two hundred tickets at once. Uploads go straight to object storage on a separate domain and are checked by their bytes, not their names.

  4. 04

    Identity per workspace

    Passwords come with a second factor, an authenticator app or a passkey, and a workspace can require one. A workspace proves its email domain over DNS and connects its own OpenID Connect provider, and an SSO session opens that workspace and no other. One person can belong to many companies, with a different role and a separate session in each.

  5. 05

    A platform layer that cannot peek

    Operators work at admin. with their own login and second factor, see metadata and never content, and read a workspace only in an owner-granted, read-only, time-boxed support session written to that workspace's audit log. API tokens are service accounts whose scopes intersect a role. Deleting a workspace leaves a nameless tombstone after 30 days.

  6. 06

    Delivery you can replay

    A transactional outbox is read per tenant in transaction-id order below the snapshot horizon, so nothing is lost, repeated or skipped. Notifications, signed webhooks with retries and a circuit breaker, and reporting are its consumers. Reports come from their own read model so they never compete with the queues.

  7. 07

    A production rehearsal, not a demo

    OpenTofu modules written for real AWS deploy it from nothing onto Floci, an AWS emulator, on every change to main: ECS services behind a load balancer with a wildcard certificate, RDS Postgres with roles RDS itself could create, ElastiCache with TLS, S3, SES and Secrets Manager under KMS. The isolation suite then runs again inside the VPC, and the browser suite through HTTPS.

  8. 08

    Invariants you can run

    A tenancy suite asserts 14 catalog and 38 isolation invariants against a live database on every merge, a doctor script checks the roles and privileges, and every integration fixture creates two organizations so a leak fails a test. A Playwright suite drives two tenants through the browser, built around the negative cases.

  9. 09

    Reviewed before shipping

    A threat model with thirteen trust boundaries and STRIDE for each, and five security reviews, at milestone 9 and at every milestone from 11 to 14, that found 58 issues, each fixed or recorded with its reason. Traces and metrics are labelled by tenant, so a Grafana board answers which tenant is slow.

screens

//03screens

  1. An agent's queue: Priorities computed from impact and urgency, deadlines counting down to the next target, overdue work marked.
    01An agent's queuePriorities computed from impact and urgency, deadlines counting down to the next target, overdue work marked.
  2. An incident, as the agent sees it: Only the transitions its state allows are offered, and the internal note is set visibly apart.
    02An incident, as the agent sees itOnly the transitions its state allows are offered, and the internal note is set visibly apart.
  3. The same incident, as the requester sees it: The reply is there. The internal note is not, because the API never sent it.
    03The same incident, as the requester sees itThe reply is there. The internal note is not, because the API never sent it.
  4. Raising a ticket: There is no priority field. Matching knowledge base articles are suggested while the requester types.
    04Raising a ticketThere is no priority field. Matching knowledge base articles are suggested while the requester types.
  5. A change awaiting approval: A plan, a window, a risk and a rollback, decided by someone other than whoever wrote it.
    05A change awaiting approvalA plan, a window, a risk and a rollback, decided by someone other than whoever wrote it.
  6. Reports: SLA compliance, median and p90 time to resolve, and backlog by age, read from a model of their own.
    06ReportsSLA compliance, median and p90 time to resolve, and backlog by age, read from a model of their own.
  7. A webhook: Standard Webhooks signatures, retries with backoff, a circuit breaker and a delivery log you can replay.
    07A webhookStandard Webhooks signatures, retries with backoff, a circuit breaker and a delivery log you can replay.
  8. One person at Acme, as an admin: Each workspace is its own tenant, and each tab holds its own session.
    08One person at Acme, as an adminEach workspace is its own tenant, and each tab holds its own session.
  9. The same person at Globex, as an agent: Neither list ever shows the other company's tickets.
    09The same person at Globex, as an agentNeither list ever shows the other company's tickets.
  10. Single sign-on per workspace: The workspace proves its email domain over DNS, then connects its own OpenID Connect provider.
    10Single sign-on per workspaceThe workspace proves its email domain over DNS, then connects its own OpenID Connect provider.
  11. The operators' back-office: Workspace names, plans and status, never what is inside them, behind its own login and second factor.
    11The operators' back-officeWorkspace names, plans and status, never what is inside them, behind its own login and second factor.
  12. Which tenant is slow: Traces and metrics carry a bounded tenant label. Here one workspace browses five times harder than the other.
    12Which tenant is slowTraces and metrics carry a bounded tenant label. Here one workspace browses five times harder than the other.

measured

//04measured

5
isolation layers
keys, credential, repository, prisma, postgres rls
2,315
automated tests
1,232 api unit, 278 integration, 402 authorization, 52 tenancy, 226 contract and 125 more
12
browser scenarios
two tenants and the negative cases; 9 also run through the https load balancer
59
architecture decision records
10,257 lines of specification, kept true as the code changed
< 25 ms
every report at 100,000 tickets
from a dedicated read model, measured in the load check
58
security findings
five reviews, at milestones 9 and 11 to 14; each fixed or recorded with its reason
13
trust boundaries
stride per boundary in the threat model

decisions

//05decisions

  1. 01

    chose a shared schema with row level security and composite foreign keys

    over a database or schema per tenant, or row level security alone

    Per-tenant databases make migrations and reporting expensive. Row level security alone leaves one hole: Postgres checks foreign keys with row security off, so a reference across tenants is still writable. Composite (orgId, id) keys close it. The cost is a wider key on every table and an explicit orgId on every repository method.

  2. 02

    chose the tenant from the credential

    over the tenant from the hostname

    A host header is attacker-controlled. The session or token names the tenant, and the origin is a cross-check that can refuse but never grant.

  3. 03

    chose computing priority from impact and urgency

    over a priority dropdown

    A typed priority is an argument, not a fact. Deriving it keeps queues honest at the price of a 400 for any client that tries to set it.

  4. 04

    chose support sessions granted by the owner

    over operator impersonation

    Impersonation is the feature every breach report mentions. A read-only, time-boxed session through the workspace's own routes gives operators what they need and leaves a line in the customer's audit log.

  5. 05

    chose integration tests against the Compose Postgres

    over Prisma mocks or Testcontainers

    Mocks give false confidence about the one thing that matters here, the database's behaviour. Testcontainers were slow to start. Every fixture creates two organizations so a leak is a failing test, not a finding.

  6. 06

    chose database roles RDS itself could create

    over a superuser bootstrap

    RDS has no superuser, so the roles were written for that from the start: no BYPASSRLS anywhere, and a doctor script asserts the app role is not a member of the table owner. Local development and the rehearsal enforce isolation the same way, at the cost of a more careful bootstrap.

  7. 07

    chose a production rehearsal on emulated AWS

    over a hosted demo

    It is a learning and portfolio project, and what it teaches is the architecture. A hosted demo proves one deployment worked once; deploying from nothing to an emulator on every change proves the infrastructure code, the roles and the TLS paths every time, at no cost. The trade-off is stated: certificate renewal, real mail authentication and the emulator's own gaps are designed for but not proven on AWS.

  8. 08

    chose dropping the machine learning milestone

    over local triage and phishing models

    The models would have added a second language, a GPU-sized container and a prompt-injection boundary without teaching more about isolation, authorization or delivery. The milestone was removed on the record, its number left unused, and the time went to identity and the production rehearsal.

try it

//06try it

  1. //bring up the whole stack with a demo seed

    pnpm install && pnpm local:up && pnpm dev

    node 24, pnpm 10 and docker; postgres, redis, minio and mailpit in compose

  2. //assert the isolation invariants against the live database

    pnpm test:tenancy
  3. //send a ticket in by email, or a forged one

    pnpm --filter @patchgrid/api run inbound:send -- --from rita@patchgrid.test --to acme

    add --dmarc fail to watch it refused

  4. //deploy to emulated aws and verify isolation inside the vpc

    pnpm aws:up && pnpm aws:run verify

    floci and opentofu; pnpm aws:down tears it down

highlights

//07highlights

  • Subdomain per tenant across one monorepo: marketing, workspace, operator back-office and API
  • Row level security forced on every tenant table, composite keys across tenants
  • Priority derived from impact x urgency, four lifecycles behind one transition endpoint
  • Email intake gated by DMARC, knowledge base, assets, presigned uploads
  • Passkeys, step-up and per-tenant OpenID Connect single sign-on
  • No impersonation, ever: support sessions are granted, read-only, audited and time-boxed
  • Transactional outbox, Standard Webhooks, reports under 25 ms at 100,000 tickets
  • Deployed from nothing to emulated AWS by OpenTofu on every change to main
  • OpenTelemetry per tenant, CodeQL and a full-history secret scan on every change

built with

  • NestJS
  • Next.js
  • PostgreSQL
  • Prisma
  • Redis
  • BullMQ
  • Turborepo
  • Zod
  • WebAuthn
  • OpenTelemetry
  • Playwright
  • Docker
  • OpenTofu

on githubpatchgrid

license
MIT
language
TypeScript
latest release
v1.0.0 oct 30, 2026
last push
dec 1, 2026

printings

//08printings

  1. First commit and twelve decisions

    The foundation milestone: package scope, per-type state machines, SLA rules, cookie sessions, the error format and the testing strategy, decided before the code.

  2. Milestones 1 to 6

    Tenancy and identity, the incident lifecycle, notifications and live updates, the other three record types, attachments, assets, the knowledge base and email intake.

  3. Milestone 9, hardening

    Member MFA with step-up, the browser suite, OpenTelemetry per tenant, OpenAPI, a load check at 100,000 tickets and a security review with 16 findings fixed.

  4. Milestones 10 to 12

    The demo seed, marketing site and production images, the decision not to deploy, the transactional outbox and webhooks, then reports, saved views and bulk actions.

  5. Milestone 13, identity

    Passkeys, per-tenant OpenID Connect single sign-on with a DNS-proven domain, and external requesters. The machine learning milestone was dropped on the record.

  6. Milestone 14, the production rehearsal

    OpenTofu modules for real AWS, deployed from nothing to Floci in CI, database roles RDS could create, and the browser suite through the HTTPS load balancer. Its review found 12 issues.

  7. Complete

    Every milestone built and verified. The README became a forty-screen tour, regenerated from the seeded demo by one command.

  8. v1.0.0

    The completed platform tagged as its first release, so the version on this page comes from the repository from now on.

questions

//09questions

Is there a live demo?
No, by decision. It runs locally with one command and a seeded demo of two companies and an operator. Production is rehearsed instead: OpenTofu deploys it from nothing to Floci, an AWS emulator, on every change to main, and the isolation and browser suites run against that deployment.
How do you know one tenant cannot read another's data?
Five layers, and proof for each: a tenancy suite with 52 assertions against a live database, run again inside the emulated VPC, a doctor script that checks the app role cannot bypass row level security, a browser suite across two tenants, and integration fixtures that always create two organizations.
Can a platform admin see customer tickets?
No. The back-office sees workspace metadata, never content. Reading a workspace requires a support session the owner grants, which is read-only, time-boxed and written to that workspace's audit log.
Can a company sign in with its own identity provider?
Yes. A workspace proves it owns its email domain with a DNS record, then connects its own OpenID Connect provider. Members are provisioned on first sign-in, and an SSO session opens that workspace and no other, so one company's provider cannot vouch for anyone elsewhere.
What happened to the AI triage?
It was dropped on purpose. Local triage and a phishing-URL model would have added a second language, a GPU-sized container and a new attack surface without teaching more about isolation. The decision is recorded, and phishing stays an ordinary category that routes to the security team.
Is it finished?
Yes. All fourteen planned milestones are built and verified, and the plan ends there. What a real deployment would still need, such as live mail authentication and certificate renewal, is written down rather than assumed.

related sheets

//10related sheets

//11contact

Say hello.I read everything.

Email is the fastest way to reach me. For anything that needs a conversation, book a call.

to

name
Khaled Saeed
country
Lebanon