Building CRM Inside Your Own Node.js and PostgreSQL Stack
The data model, module boundary, permissions, audit log and billing integration for CRM features inside your product, and how an external team can build them in your codebase and hand them over.
Building CRM inside your own Node.js and PostgreSQL stack works best when customer data is already product data. Model accounts, contacts, deals and activities as ordinary tables in their own schema, and build them as a module of a modular monolith rather than a new service. Enforce role-based and record-level permissions in the API, with PostgreSQL row-level security as a second line, and write an append-only audit log in the same transaction as each change. Keep billing and subscriptions in your payment provider; the CRM holds references and a status updated by webhooks. If your developers are busy on the product, an external team can build it in your repository and conventions and hand it over. Solzet does that.
Should you build CRM features inside your own product or buy a third-party CRM?
Build inside your product when the CRM data is really product data: your accounts are the tenants or organisations in your app, the signals that matter to sales are usage and plan data you already hold, and the workflows people want, such as onboarding, renewals or account health, run on that data. A third-party CRM then needs a sync in both directions, a second copy of every customer, and a seat for everyone who needs to look at an account.
Buy when the sales team needs what CRM products are good at and you are not: email sequencing, call recording, marketing automation, forecasting across a large pipeline, and a marketplace of integrations. A middle route is common too: keep the account and usage data in your product and push a summary into a bought CRM through its API. The general rule between licensing and owning a CRM is on build vs buy CRM, and what a build costs to own is on what it really costs to build a CRM; this page is about how to build it well if you do.
- Build when accounts, plans and usage already live in your database and sales works from them.
- Build when many internal users need light access to account data and per-seat licences would multiply.
- Buy when the value is in sales tooling rather than in your data: sequencing, dialling, marketing and forecasting.
- Sync when both are true: product data stays at home, and a summary goes to the CRM the sales team prefers.
What data model do accounts, contacts, deals and activities need in PostgreSQL?
Keep it relational and boring. Put the CRM tables in their own PostgreSQL schema, link accounts to the organisation or tenant table your product already has, and reuse your existing users rather than creating a second identity store. Use real foreign keys everywhere, including for activities: a nullable foreign key per parent type with a check constraint keeps referential integrity, which a generic entity type and entity id pair does not.
Custom fields are the usual temptation. A JSONB column validated against a schema you store is fine for fields that vary by customer and are rarely filtered; anything you filter, sort or report on deserves a real column and a migration.
| Table | Core columns | Notes |
|---|---|---|
| accounts | id, organisation_id (your tenant), name, domain, owner_id, team_id, lifecycle_stage, created_at, updated_at, archived_at | One row per customer organisation, linked to the tenant your product already knows. |
| contacts | id, account_id, user_id (if they are also a product user), name, email, phone, role, consent fields, owner_id | Unique email per account with a case-insensitive index; consent kept with the contact. |
| pipelines, stages | pipeline id, name; stage id, pipeline_id, name, position, is_won, is_lost | Stages are data, not an enum, so sales can change them without a deployment. |
| deals | id, account_id, primary_contact_id, pipeline_id, stage_id, amount_minor, currency, expected_close_on, owner_id, closed_at, close_reason | Money as integer minor units plus currency; stage history in its own table or the audit log. |
| activities | id, type (call, email, meeting, note, task), subject, body, due_at, completed_at, owner_id, account_id, contact_id, deal_id | Nullable foreign keys with a check that at least one parent is set. |
| roles, role_assignments, teams | role id, name, permissions; user_id, role_id, scope; team id, members | Reuse product users; add CRM roles and team membership for record scoping. |
| audit_log | id, occurred_at, actor_id, action, table_name, record_id, before, after, request_id | Append-only; see the audit log section below. |
Why build the CRM as a module of a modular monolith rather than a new service?
Because the CRM needs your product data constantly, and a separate service turns every read of it into a network call, a sync job or a duplicated table. A module inside the existing Node.js application shares the deployment, the database connection, authentication and observability you already run, while keeping its own boundary.
The boundary is what makes it a modular monolith rather than more code in a big ball. The CRM module owns its schema and exposes a small interface, such as functions or an internal API, that the rest of the product calls; other modules do not query its tables directly, and it reads product data through the product's own interfaces. Events between modules go through an outbox table written in the same transaction and processed by a worker, so a deal closing can trigger onboarding without the two modules knowing each other's tables. If the CRM one day needs its own service, that boundary is where you cut.
- One folder or package per module, with an explicit public interface and lint rules that block imports of another module’s internals.
- One PostgreSQL schema per module, with migrations owned by the module and run by your existing migration tool.
- An outbox table for cross-module events, processed idempotently by a worker.
- Shared kernel kept small: identity, tenant context, money and time types, error handling.
How should permissions work: role-based, record-level or PostgreSQL row-level security?
All three, in layers. Role-based access control decides what a user may do: view deals, edit accounts, export, administer stages. Record-level scoping decides which records: my own, my team's, my region's, or all within the tenant. Both belong in the API layer, in one authorisation function that every query and mutation goes through, so the rules live in one place and are covered by tests.
PostgreSQL row-level security is a strong second line, especially for tenant isolation. Policies on the CRM tables compare the row's organisation or owner with a setting the application sets per transaction, for example with SET LOCAL and current_setting, so a missing where clause cannot leak another tenant's data. Three details matter. Table owners and roles with BYPASSRLS skip policies, so the application must connect as a role that is neither, or the tables must use FORCE ROW LEVEL SECURITY. Settings must be transaction-scoped when you use a connection pooler, or one request's context can leak into the next. And policies cost query planning time, so check the plans of your heaviest list views. The PostgreSQL documentation on row security policies is the reference.
How do you build an audit log that support, security and auditors can trust?
Write it in the same transaction as the change it describes, so a change without an audit row cannot exist. Each row records who acted, when, what action, which table and record, the values before and after as JSONB, and the request id that ties it to your logs. The application role gets insert and select on the audit table and nothing else, so nobody can edit history through the application.
You can write audit rows from the application, which knows the user and the reason, or from database triggers, which catch every write including scripts and migrations. Many teams use triggers for completeness and pass the user and request id through a transaction setting. Partition the table by month with declarative partitioning so retention is a matter of detaching old partitions, and show the history on each record in the CRM screens, because the people who read the audit log most are support staff, not auditors.
- Same transaction as the change, never a fire-and-forget call afterwards.
- Actor, time, action, table, record id, before and after values, request id.
- Insert-only grants for the application role.
- Monthly partitions and a written retention rule.
- A history view on every account, contact and deal.
Where should billing and subscription logic sit when the CRM lives in your product?
Beside the payment provider, not inside the CRM. Providers such as Stripe, Paddle or Chargebee are built to be the source of truth for subscriptions, invoices, payment methods, proration, dunning and often tax, and card data should never touch your database. Rebuilding any of that in the CRM creates a second, slightly different version of what a customer owes.
The CRM holds references and a read model: the provider's customer id on the account, the current plan, status and renewal date, updated from the provider's webhooks. Webhook handlers verify the signature, store the event id so duplicates are ignored, and update the read model in one transaction with an audit row. A deal that closes as won calls your billing module, which creates or changes the subscription at the provider; the CRM never calculates an invoice itself. Entitlements, meaning what the customer may use in the product, stay in the product and follow the subscription status.
| Concern | Lives in | The CRM sees |
|---|---|---|
| Plans, prices, invoices, payment methods, dunning | The payment provider | Plan name, status, renewal date and a link to the provider record. |
| Creating or changing a subscription | Your billing module, calling the provider API | An event when it succeeds or fails. |
| Entitlements and feature limits | Your product | The current plan and usage summary on the account. |
| Quotes and deal value | The CRM | Its own data, handed to the billing module on close. |
What engineering work does a CRM need beyond the tables?
The tables are the small part. What decides whether sales actually uses an in-house CRM is the work around them, and it is where build estimates usually go wrong, so scope each item explicitly. We give no generic figures for it, because the effort depends on your product and conventions; the drivers and the running costs after launch are set out in what it really costs to build a CRM.
- List views with filters, sorting, saved views and bulk actions, which is where users spend most of their time.
- A pipeline board with drag and drop between stages, and stage history.
- Search across accounts, contacts and deals, often PostgreSQL full-text search to begin with.
- Imports with column mapping, validation and duplicate detection, and exports.
- Email and calendar integration through the Microsoft Graph or Gmail APIs, if activities should log themselves.
- Notifications, reminders and task queues.
- Reporting: pipeline by stage and owner, activity by user, and an export for your analysts.
- Data protection: retention rules, deletion and export of a person’s data on request.
- Tests for the permission rules and the billing webhooks, since those are the parts that hurt when they fail.
What does Solzet do when your own developers have no time to build the CRM?
Solzet builds it inside your stack and hands it to your developers. Our own senior consultants and full-stack developers work in your repository, with your Node.js framework, ORM or query builder, migration tool, lint rules, test setup and CI pipeline, and open pull requests that your developers review, so nothing arrives as a foreign codebase. We start with a short design: the data model, the module boundary, the permission rules, the audit log and the billing integration, written as decision records in your repository. Then we build in short iterations with a working demo in your staging environment, and finish with documentation and walkthrough sessions so your team owns the module from the next sprint. How we contract ownership and support is on custom CRM development; if you are also weighing a self-hosted open-source CRM, see open-source CRM or a custom-built CRM.
We recommend the right solution: Dynamics 365 (Customer Engagement, Business Central or Finance and Operations), Power Platform, or a custom-built CRM. One team for CRM, ERP and the integration between them.
What do people ask us?
Should we build CRM features inside our own app or buy a CRM?
Build inside your app when accounts, plans and usage already live in your database and sales works from them, or when many people need light access. Buy when the value is in sales tooling such as sequencing, dialling and forecasting. Syncing a summary of product data into a bought CRM is a valid middle route.
What tables does a CRM need in PostgreSQL?
At minimum accounts, contacts, pipelines and stages, deals, activities, roles and team membership, and an audit log. Link accounts to your existing tenant table, reuse your product users, and use real foreign keys rather than a generic entity reference.
Should the CRM be a separate microservice?
Usually not at first. A module inside a modular monolith shares your deployment, database and authentication while keeping its own schema and interface. Cross-module events go through an outbox table, and the module boundary is where you would cut a service later if you ever need one.
Is PostgreSQL row-level security enough for CRM permissions?
It is a strong second line, especially for tenant isolation, but role-based rules and record scoping belong in the API as well. Make sure the application role is not the table owner or a BYPASSRLS role, or use FORCE ROW LEVEL SECURITY, and set the user context per transaction when you use a connection pooler.
Should subscription billing live in the CRM?
No. Keep subscriptions, invoices and payment methods in the payment provider and let your billing module talk to it. The CRM stores the provider customer id and a read model of plan and status updated from signed, deduplicated webhooks.
How much engineering time does an in-house CRM take?
It depends on the scope around the tables: list views, the pipeline board, search, imports, email integration, notifications and reporting. Scope each item explicitly and estimate against your own conventions; generic figures are not reliable for a build inside an existing product.
Can an external team build the CRM in our codebase and hand it over?
Yes. Solzet builds it in your repository with your framework, migration tool, tests and CI, through pull requests your developers review, documents the design as decision records and hands the module over so your team owns it.
Where should you go next?
Custom CRM development
React, Node.js, PostgreSQL and .NET, with the code in your repository from day one.
What it costs to build a CRM
Effort drivers, running costs and a five-year cost model.
Build vs buy CRM
When to license a CRM, build on Power Platform or own one.
Open-source CRM or a custom build
SuiteCRM, EspoCRM and Twenty against a CRM you own, over five years.
Custom CRM takeover
When the developer who built your CRM stops responding.
Which solution is right for your business?
Tell us what you need. A senior consultant replies within one business day with a recommendation (Customer Engagement, Business Central, Finance and Operations, Power Platform or a custom-built CRM), not a sales script.