A layered stack diagram with surfaces on top and Postgres, functions and realtime beneath.

    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.

    GC
    GarunaCDX Editorial
    Editorial team
    Nov 22, 2026 5 min read
    Key takeaways
    • 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.

    A layered diagram: five surfaces feeding edge functions, Postgres, realtime channels and scheduled jobs, hosted in Mumbai.
    The stack, layer by layer. Rules live low. Screens stay thin.

    Layer by layer

    LayerIt ownsIt never does
    SurfacesLayout, input, showing stateDecide who may do what
    Edge functionsOne business action each: book, check in, advance, insert an emergency, notify, onboard. They verify the caller’s role, then call the databaseHold state
    PostgresThe queue, the schedule and the rules about them. Multi-step changes are single transactionsTrust the caller
    RealtimePushing a changed row to whoever may see itCarry names or phone numbers to staff boards
    Scheduled jobsReminders, expiry and clean-up inside the databaseRun 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.

    A queue from booked to waiting to in consultation to done, with a table of which role may do each step.
    Who may move a patient. Check-in and emergency insert are reception only.

    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.
    Architecture review
    Show us your current stack and the rule you trust least. We will tell you where it should live.
    Book a free scoping call

    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.

    Your verdict
    Was this article useful?
    GC
    Written by
    GarunaCDX Editorial
    Editorial team

    Engineers, product and growth folks at GarunaCDX writing about the systems we build for clients.

    View all articles
    Share
    Planning something similar?

    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.

    FAQ

    Frequently asked questions

    Postgres with row-level security gives access rules at the data layer, and Auth, Realtime and functions come on the same platform. For a multi-tenant app with five surfaces that is fewer moving parts than assembling them.

    No. It is the floor. Business actions also go through functions that check the caller's role, and every policy is tested role by role.

    Schema changes ripple into the mobile models and the web types at the same time. One repository keeps them in one commit instead of drifting across teams.

    A patient's own channel carries their own row. Staff boards are told that something changed and re-read, so names and phone numbers are not broadcast.

    The GarunaCDX build log

    Industry insights, once a month

    New case studies, healthcare, marketplace, B2B SaaS and industrial breakdowns, and the engineering notes behind what we ship. One short email a month, no fluff.

    We never share your data — see our Privacy Policy for details.