New series: Building ContractBill, in 4 parts.See all parts
Part 3 of 4

Building ContractBill, part 3: the architecture, the company and the rules

Why the design changed three times, why the database keeps each firm apart, and the paperwork behind SMS codes and payments.

On this page

August: the architecture changed three times

The first real decision was not which framework. It was where the work happens.

Attempt one: keep it all in the frontend. I started on Astro, with the bill grid shipping zero JavaScript. The reasoning was that a bill must render the same way every single time, with nothing hidden waiting on hydration, because a number that appears half a second late is a number a biller might not see before he prints.

Attempt two: split out a backend. That fell over quickly. The rate database, with more than 10,000 rows, cannot live in a browser, and neither can the Excel export engine, which builds a workbook with live formulas inside it. So those became a separate service.

Attempt three, the one I kept: one Next.js App Router deploy for everything. Marketing site, product and API in one repository, one deploy, one session cookie.

Two deploys sounded cleaner and was worse in every practical way. It meant two sessions, two stories for sign in, and CORS between my own code. Every feature would have had to be thought through twice.

I also dropped the original zero JavaScript rule, and wrote down why. The idea behind the rule was right, but the rule itself was not. What really matters is that the bill is the same every time, so the server is now the source of truth for every saved number, and exports are made on the server instead of from whatever data the client has.

The region

Postgres in ap-south-1, Mumbai. Next.js functions pinned to Vercel's bom1, also Mumbai.

The reason is that delay adds up. Every query runs inside a row level security transaction, and the billing grid makes a lot of them. A round trip to another region adds roughly 150 ms to each one. Put the database in Singapore and the app in Mumbai, and the grid feels broken, not slow.

There is a second reason, which is where the data lives. Indian contractors' tender documents and quoted percentages staying on Indian servers answers a question before a customer has to ask it.

I had first planned to build on Google Cloud, but Next.js on Vercel was simply more reliable for this kind of application, so I moved, and put both halves in Mumbai.

Postgres keeps each firm apart, not my code

Row level security, not an application level WHERE org_id = ?.

The reason is specific rather than theoretical. The most commercially sensitive value in this system is a contractor's quoted percentage, the number he won the tender at. If a competitor sees it, he is at a disadvantage on every future tender against that firm. One forgotten WHERE in one query, once, can end a business for a customer who trusted me.

With filtering in the application, every developer has to remember, for ever. With row level security, the database refuses.

That decision came with its own hard lessons. FORCE ROW LEVEL SECURITY cancels SECURITY DEFINER but not BYPASSRLS. Adding a foreign key to a forced table fails during validation, and the obvious fix is the wrong one. Both sides of a join need the same settings, or you get failures that look like permission bugs and are actually schema bugs. None of that is in a tutorial.

Sign in is written by hand, into my own schema

Not Clerk, which is the nicest to work with of them all. It is priced in dollars, hosted in the US, and it moves user records out of the very database whose isolation I am selling. That does not make sense as a product story.

Not a hosted sign in product bundled with the database either, because its phone pipeline still needs Indian DLT registration, so it saves no compliance work, and it ties the sign in tables to one vendor.

So email and password, Google, and one time codes over SMS were all written by hand, with the sign in tables sitting beside the row level security policies they have to work with. At launch the only way in is a one time code sent to your phone. Email sign in has been taken out, and Google sign in is built and switched off for now. A third database role handles sign in, with BYPASSRLS and a deliberately tiny list of grants, and that boundary is the security model.

The rest of the design was written down before it was built: the authorisation model, and a list of background jobs for later, such as working out which rate book a tender uses, spotting the GST factor, and checking that a backup can actually be restored, because a backup nobody has ever restored is a hope rather than a backup. Those jobs are planned, and not all of them are built yet.

August: the company, and the numbers behind it

Software was not the only thing that had to exist.

Udyam registration. A sole proprietorship on my own PAN. A current account. The plain paperwork that has to be in place before anyone can legally pay you.

And the financial model, which took real work: the money earned on each bill, projections for several sizes of user base, from a handful of firms to a few hundred, and my own cost of serving each of those sizes. That means the servers, the payment gateway's cut, and the cost of each AI read.

Writing all of this down honestly changed the pricing. At first I planned four plans based on two things: the number of downloads, and whether AI was included. While writing the pricing document, I realised this did not make sense. If the download limit is high, nobody cares about it. If it is low, people start worrying about how many times they download a bill instead of checking whether the numbers are correct, which goes against the whole point of the product. So I removed download limits completely. Now the only difference between the plans is how many times AI can read a document.

It also made me mark clearly what I do not know. When I wrote this, the AI cost per read was not yet measured. Nobody had measured what a multi page scan returning a 90 item JSON actually costs. So the endpoint records the model, the input size and both token counts on every attempt, successful or not, and the question can be answered within a month of real use. Until then the three credit allowance is a cap on the damage, and every AI price in the model is a placeholder rather than a result.

September: the compliance

TRAI DLT

In India you cannot simply send an SMS to a customer. Every sender must be registered on a Distributed Ledger Technology platform run by the telecom operators, with the business registered, the sender header approved, and every message template approved before a single message can be delivered.

So: registering the business. Getting the header REVNIN approved. Getting the one time code template cleared as Service Implicit, not Transactional, because Transactional is kept for banks and financial institutions, and a one time code template sent there gets rejected. Then setting up the chain from the business to the telemarketer on both the DLT portal and the messaging provider, because the two have to match.

Nobody warns you that a one time password cannot legally reach an Indian phone until a telecom regulator says so. It is not a technical problem, and there is no library for it.

Razorpay

Integrated, with KYC done. When I wrote this it was not yet taking live payments, and that difference matters, so I will be exact: the live keys were still pending.

The integration is designed around one failure. It is 6 pm on a submission day. The contractor pays. The webhook is lost. The bill stays locked, and he cannot file. That is not a bug report, that is a customer gone.

So the payment is checked when the checkout finishes, and again when the webhook arrives. Both checks use the event ID, so the same payment cannot be processed twice. Every payment event is saved in the payments table before anything else is updated. Each bill can have only one open order of each type, and every order has an idempotency key, so if someone clicks twice, they get the first order instead of being charged twice.

One more rule keeps the whole money path simple: a payment only ever adds to a balance of what has been paid for. A payment never sets a flag on a bill, never touches a firm's record and never switches on a feature directly. The product asks exactly two questions: is this bill unlocked, and does this tender have AI credits left. Adding subscriptions next year adds a row on one side and changes nothing on the other.

Weeks on the interface

I want to be honest about this, because it is the part people skip.

The first version of the interface was dark. Gradients. Glow effects. Cards inside cards. It looked like every AI made interface you have ever scrolled past, because that is exactly what it was.

I threw it out.

What replaced it took weeks. A proper brand pass first: what this thing is, who it is for, and what a 45 year old contractor who is not comfortable with English needs to see. Then drawing the logo, and turning the artwork into proper vectors rather than tracing something rough. Then a decision to go light everywhere and drop the dark palette completely, across the product, the marketing site and every document.

Then design tokens. Real ones. A set palette, type scale and spacing scale, used everywhere, instead of colours chosen screen by screen. That is the difference between an interface that holds together at screen forty and one that does not.

The writing got the same treatment. Every label, button, heading and error message in the product is written for a contractor reading it for the first time, in plain Indian English, keeping his own paperwork words: RA Bill, DSR, Schedule of Work, Work Outlay. Not "billing dashboard", and not "streamline your workflow".

First published on LinkedIn on 6 September 2026, as part of one long article. Read the original

Next, part 4 of 4What it does now, and the bill that matched
Tarun KumarFounder, Revenin Technologies. IIT Guwahati.

I built ContractBill and RateAnalyser at Revenin Technologies.

Get new posts by email

One email when a new post is out, and nothing else. You can stop them any time.

Buttondown keeps the list and sends the emails. How we use your email