← All case studies

// engineering

Rebuilding the Foundations of a Live Platform

Node.jsExpressPostgreSQLSupabaseStripe API

Overview

A business had a customer-facing portal and several workflows built around a CRM, a payment provider and a hosted front-end builder. Parts of the experience looked finished. Underneath, there was no application layer holding it together, so the platform worked only as long as nobody leaned on it. The job was to build that foundation while the product stayed in use.

The Problem

Critical functionality was spread across the CRM, the payment provider, the front-end builder and a handful of separate workflows, with nothing coordinating them. That created five specific problems:

Investigation

The useful question was not "what is broken?" but "where does each fact actually live?" Mapping three basic facts showed the problem clearly. Who is paying lived in the payment provider. Who has access lived partly in the CRM and partly in the front end. Who submitted what lived wherever a workflow happened to drop it. The same person could be correct in one system and wrong in another, and nothing could say which to believe.

Two decisions followed from that. The first was build versus buy for authentication. Hosted auth products handle login well, but login was not the hard part here. The hard parts were checking entitlement against the payment provider and attributing submissions reliably, and both would have needed custom logic wrapped around a third party anyway. A small purpose-built backend was less to maintain.

The second was about trust. If a user's identity travels with a submission in the form data or the URL, anyone who can edit a request can change it. That design is only as trustworthy as the browser. The rule that came out of this was that identity is established on the server, once, at login, and everything afterwards reads from it.

architecture_before_after.txt
BEFORE

Payment      CRM      Front-end     Separate
Provider              Builder       Workflows
   |          |          |             |
   +----------+-----+----+-------------+
                    |
   each holds part of the truth,
   nothing coordinates them
                    |
                    v
   payment status and platform
   access drift apart


AFTER

Front End
    |
    v
Application Backend (one source of truth)
    |
    +--> Payment Provider  (valid subscription?)
    +--> Database          (users, reviews, history)
    +--> CRM               (customers, provisioning)

The Solution

A dedicated Node.js and Express backend, with PostgreSQL through Supabase for persistent data, sitting between the front end and the tools it used to depend on.

The submission endpoint shows the identity rule in one place: the user comes from the verified session, and nothing about the user is read from the request body.

reviews.jsrouter.post("/reviews/submit", requireAuth, async (req, res, next) => {
  try {
    // Identity comes from the verified session, never from the request body
    const user = req.user;
    const { reviewData, clientEmail } = req.body;

    const contactId = await upsertCrmContact(clientEmail);
    await saveReview({ userId: user.id, contactId, reviewData });
    await sendToCrm(contactId, {
      reviewData,
      submittedByName: user.name,
      submittedByEmail: user.email,
    });

    res.json({ status: "submitted" });
  } catch (err) {
    next(err);
  }
});

Engineering Trade-offs

The core principle

Every fact needs one source of truth, and it should never be the browser.

The main trade-off was building a foundation instead of adding more features on top of the existing structure. Continuing to extend the old setup would have produced visible progress sooner. It would also have made every later change harder, because each new feature would have inherited the same scattered state.

Trust decisions went on the server even though a front end already existed and appeared to work. Doing the checks in the browser would have looked identical in a demo, and it would have left the one thing the business cared about, correct attribution and correct access, dependent on the honesty of whoever was using the page.

The first version was also deliberately narrow. It used a single session type with a normal expiry, with no refresh tokens, no retry queues for every integration and no complicated roles. Each of those is a reasonable later addition, and leaving them out kept the security surface small enough to reason about while the product was live. One limit was accepted knowingly: in that first version, entitlement was checked when an account was created, not on every login, so a lapsed subscription was not caught automatically. It was recorded as the first thing to add if the business needed it.

Challenges

Outcome

Reflection

The most useful habit on this project was asking, for each feature, "which system is the source of truth for this?" and refusing to accept "the browser" or "whichever tool saw it last" for anything that mattered. Once those answers were fixed, the rest could be built incrementally on top of them, even with the product live. The known limit in the first version is the other lesson: it is better to state plainly what a design does not yet cover than to let a reviewer, or a customer, find it first.