Skip to content
webdmamun
All work

Property & Investment CRM Platform

A CRM for a property and investment business: public enquiries triaged into contacts, opportunities tracked through their own approved stage sequence for each of four investment routes, and every read and write decided by the database.

Industry
Property investment and development
Status
in development2026

Built with Next.js, React, TypeScript, Tailwind CSS, PostgreSQL, Supabase, Vitest, Vercel

This system holds sensitive client data, so it is described without naming the client, without a link, and without screenshots of real records.

The system in numbers

Database tables
38
Row-level policies
92
Permissions
49
Roles
6
Pipelines
10
Pipeline stages
61

Source: Repository audit of the CRM source, September 2026.

In this case study

The problem

A property business can run four commercially different investment routes at once — co-ownership through a special-purpose vehicle, a pooled route for smaller investors, an end-to-end turnkey service, and contracted institutional delivery. They look similar from the outside. Operationally they are four different businesses.

Each route has its own approved sequence of stages, its own paperwork, its own money flow and its own point at which identity checks have to clear. An enquiry that arrives through the website does not announce which of the four it belongs to, and the answer often changes after the first conversation.

The access problem is sharper than the workflow one. Sales needs to know whether a person has cleared identity checks, and must not see the passport scan that proves it. Finance prepares payments and must not be the one who approves them. A project manager should see the projects they are delivering and not the rest of the business. Those are not preferences about what to show on a screen — they are rules that have to hold even if someone guesses a URL.

And the public website has to write into a system that nobody outside the company may read at all.

What was needed

One internal system that models all four routes as they actually run, captures website enquiries into the same record set that staff work from, and enforces who may see and do what in a way the interface cannot talk its way around.

What I built

A CRM built on row-level database security rather than application checks alone. The signed-in member of staff is carried into the database connection, and the database itself decides which rows they may read and write — 92 policies across 38 tables. The application layer holds the session and a catalogue of 49 permissions across 6 roles; navigation is filtered on the server, so a link to an area someone cannot open is never sent to their browser, and the destination page checks again anyway.

The four investment routes are modelled as separate pipelines rather than as one pipeline with branches: 10 pipelines and 61 stages, seeded once and then read from the database at runtime. Moving an opportunity forward is one stage at a time; moving it backwards always requires a recorded reason and a permission most staff do not hold. Skipping a stage was deliberately not seeded — if the business wants it, that is a configuration change, not a release.

Public enquiries reach the database through a single function with elevated rights that can touch exactly one table, with rate limiting counted in the database rather than in a process that does not outlive the request. Staff triage them into contacts under the permissions they already hold, and the consent captured on the website travels with the record.

The platform is in active development. Contacts, opportunities, enquiry intake and triage, administration and the audit trail are built and covered by tests; delivery, compliance, agreements and finance exist in the schema and are not yet built, and are not described here as though they were.

Who uses it

CRMInternal staff
The enquiry queue, contacts, opportunities and the pipeline view — scoped to what each role is allowed to see, by the database rather than by the interface.
AdministrationSystem administrators
Staff accounts, email invitations, role assignment and suspension. Every role change and suspension is written to an append-only audit log.
Public websiteProperty owners and institutions
The public-facing site and its enquiry form — the only route by which someone outside the company can put a record into the system.

What it does

  • Public enquiry intake

    Website enquiries written through one controlled path, consented and rate limited in the database.

  • Enquiry triage

    A queue with new, reviewing, converted, closed and spam states, and conversion into a contact record.

  • Contact records

    Individuals and companies, normalised phone numbers, lead source, notes and a unified activity timeline.

  • Consent capture

    Marketing consent recorded with its source and timestamp, and never overwritten in place.

  • Duplicate detection

    Email and phone checked on entry so the same person does not become two records.

  • Opportunity pipelines

    Four investment routes, each with its own approved stage sequence read from the database.

  • Guarded stage moves

    Forward one stage at a time; backwards needs a recorded reason and a permission, with full stage history.

  • Roles and audit

    Six roles, 49 permissions, email invitations, suspension, and an audit log that refuses to be edited.

The CRM

The enquiry queue, contacts, opportunities and the pipeline view — scoped to what each role is allowed to see, by the database rather than by the interface.

The dashboard answers the two questions staff open the system with: who is in the book, and what is moving. Counters are live queries scoped by row-level security, so two people can see different numbers here. No records exist yet, so they read zero rather than sample data.
The triage queue. An enquiry is reviewed and either becomes a contact or is closed — there is no second system it can fall into.
Each investment route runs its own pipeline, so the filter is a real boundary rather than a label: an opportunity cannot be moved from one route’s stages into another’s.
Consent is a field with a source and a timestamp, not a checkbox. The form says where the value goes and how it is stored — phone numbers in E.164, email normalised for duplicate detection.
Administration: invitations rather than created passwords, roles assigned and revoked in place, and the role catalogue shown alongside so the effect of a change is visible. Names and email addresses on this screen are placeholders.

The public website

The public-facing site and its enquiry form — the only route by which someone outside the company can put a record into the system.

The public site shares the application and the database with the CRM. Branding is replaced throughout — this case study is published without naming the client.
Where a record enters the system. The form states what it will not ask for, and the submission reaches the database through the one function that is allowed to write it.

The hard parts

Letting the public write to a private database, safely

Public enquiries have to insert a row into a system nobody outside the company may read. Adding a second database login would have meant another password, another connection string and another deployment secret. Instead there is a single function that runs with elevated rights and can touch exactly one table; no insert policy exists at all, so even an administrator cannot write an enquiry row directly. Rate limits are counted in the database, because separate serverless instances cannot share a counter, and the visitor’s IP address is stored only as a truncated hash — enough to rate limit, and no more.

A default that quietly grants everyone execute

PostgreSQL grants execute on a new function to PUBLIC by default. The migration that created the elevated-rights writer granted it to the application role but never revoked that default, which left anonymous visitors technically holding execute on it — only a missing schema grant stood in the way. A follow-up migration revokes it, and the rule is now explicit: after creating a function that runs with elevated rights, revoke execute from PUBLIC in the same migration.

Refusing to invent a fifth product line

Converting an enquiry naturally wanted to create an opportunity, but an opportunity must belong to one of the four investment routes, and none of them described what some enquirers actually had. Rather than inventing a fifth value to make the flow complete, conversion creates a contact only. The gap is written down and waits for a decision from the business instead of being papered over in code.

Stages the business can change without a release

The four stage sequences came from an approved specification, so the obvious move was to put them in the code. They are instead seeded into the database once and read from it at runtime, with the seed converging rather than only adding — a grant or a stage that has left the declared set is removed when it runs again. Reordering a pipeline is then an administration change with an audit trail, not a deployment. The same reasoning kept stage skipping out: it can be added as configuration if the business asks for it, and until then the sequence means what it says.

Architecture

One Next.js application serves both halves — the public marketing site and the protected CRM — against one managed PostgreSQL database. They share a deployment because they share a domain model: an enquiry submitted on the public site is the same row the CRM triages.

Authorisation lives in the database. The application connects as a role with neither SUPERUSER nor BYPASSRLS, sets the signed-in user on the connection, and every policy resolves through one has_permission function against the seeded permission matrix. The permission codes are declared once in TypeScript, seeded as data, and named by the SQL policies, so the application and the database cannot drift apart without the seed run failing.

Public form submissions are the one path with no identity behind them. They reach the database through a single function with elevated rights and can touch nothing else.

The audit log is append-only in three independent ways — grants, policies, and triggers that refuse the change even when the database owner attempts it.

no identityone functionPublic websiteCRM (staff)Enquiry intakeSession & permissionsEnquiry triageContacts & opportunitiesPipelines & transitionsRow-level policiesPostgreSQLAppend-only audit

Where it stands

The platform is in active development. This case study documents the CRM and operational foundation built so far — enquiry intake and triage, contacts, opportunities, the four stage pipelines, administration and the audit trail — with further modules to be added as the product progresses.

No usage figures are given because there are none to give: the environment holds no live records yet, which is also why the screens in this case study show their empty states rather than invented data. What can be stated is behaviour the test suite holds in place — that an opportunity cannot move backwards without a reason and a permission, that a stage gate cannot be bypassed by editing the record instead of moving it, that an audit event cannot be altered after it is written, and that an anonymous submission can reach exactly one table and nothing else.

Want something like this? Tell me how your business runs today.