
One backend, five surfaces: how we structured DrInCity
Row-level security on every table, private realtime channels, one function per business action and one repository. The structure behind a live clinic platform.
- Screens ask. The backend decides. Five surfaces means five chances to disagree.
- Row-level security on every table, with role lookups evaluated once per statement.
- Realtime channels are private and scoped per patient and per clinic-doctor pair, never global.
- Only reception checks in and inserts emergencies. Call-in is a timestamp, not a state.
- One policy file decides what sends an SMS, a push or an inbox message.
DrInCity series · The engineer’s view
Quick answer
Put every rule in the backend and keep screens thin. DrInCity runs five surfaces on one backend: Postgres with row-level security on every table, one edge function per business action, private realtime channels per patient and per clinic-doctor pair, and one repository so schema changes reach every client in the same commit.
The short answer
Put every rule in the backend and keep the screens thin. DrInCity has five surfaces on one backend: Postgres with row-level security on every table, edge functions for business actions, private realtime channels, and one repository, so a schema change reaches every client in the same commit.
Why one backend
Five surfaces means five places a rule can be implemented differently. A patient app that checks “is this slot free?” and a dashboard that checks it differently will disagree on a busy morning. So the screens ask, and the backend decides.

Layer by layer
| Layer | It owns | It never does |
|---|---|---|
| Surfaces | Layout, input, showing state | Decide who may do what |
| Edge functions | One business action each: book, check in, advance, insert an emergency, notify, onboard. They verify the caller’s role, then call the database | Hold state |
| Postgres | The queue, the schedule and the rules about them. Multi-step changes are single transactions | Trust the caller |
| Realtime | Pushing a changed row to whoever may see it | Carry names or phone numbers to staff boards |
| Scheduled jobs | Reminders, expiry and clean-up inside the database | Run business rules a function should own |
Row-level security on every table. A patient, a reception user, a doctor and an admin each see only their own rows. The role lookup inside each policy is wrapped so the database evaluates it once per statement, not once per row. That one habit is the difference between a policy that is correct and a policy that is correct and fast.
Realtime on private channels. Each patient has a channel, and each clinic-doctor pair has one. Authorisation happens when a client joins, so a patient can never subscribe to a doctor’s queue. The patient’s phone receives the changed row and applies it without a second read. Staff boards re-read, coalesced, because they show names and phone numbers we don’t broadcast. A failure to publish can never fail the queue write itself.
One policy for notifications. SMS, push and the in-app inbox are decided in one file. A plain position shift sends nothing, because the live screen already shows it. A message goes out when your turn is approaching, when it is your turn, when an emergency moves you down, and when a booking changes.
Rules by role
The part of the design we are proudest of is a small table: who may change a patient’s state.

Reception alone checks patients in and inserts emergencies. A doctor may start and end their own consultation and take a break. “Call in” is a timestamp on the row, not a state, so reception’s ownership of the order holds. This is enforced on the server and by row-level policies. The screen hides buttons for convenience, not for safety.
One repository
The mobile app, the web and the database live together. A new column, a new function input and a new policy ripple into Dart models and TypeScript types at the same moment. Splitting them into repositories would desync exactly the changes that most need to move together. The cost is a heavier checkout. We’ll take it.
What this stack costs you
Be honest about it before you pick it.
- You depend on a managed platform. It is a good one, and it is still a dependency. Know your exit.
- Policies are code you must test. A missing policy is a silent hole, not an error. We test every role against every table. More in break it before a clinic does.
- Deploys are several steps. Database, functions, config, web, app. We built a check that compares what is deployed with the repository, because order and omission both bite.
- Hosting region is a choice. Ours is Mumbai, and the clients and functions are pinned to the same region so a request does not cross an ocean.
For a wider take on the same decision, see one backend for the app and the web.
Architecture details come from DrInCity’s project documents and architecture decision log. The platform is live in Mumbai and Uttar Pradesh per Aadarsh. We publish no load, latency or usage figures. The realtime channel design is described as built; confirm delivery behaviour before quoting it as a measured property.
More by GarunaCDX
Let's talk about your build.
Tell us what you are building. A founding engineer replies within one working day with how we would approach it.
