In TourCockpit, the Database Decides Who Sees What
TourCockpit can be used from the web, the API, WhatsApp, a phone call and Claude. Every one of those ends at the same place: Postgres, which refuses any row that belongs to another company.
In TourCockpit, the user interface is the last thing I think about. The API comes first, and everything the office does on the screen can be done through it. My agent uses it on WhatsApp and on a phone call, and Claude uses it through MCP.
With one screen, I check permissions in one place. With five ways into the same data, each one is a place where a filter can be missing. One missing condition on one query, and a tour company sees the bookings of another tour company.
I wanted to guarantee that nobody will access the wrong information, and the lowest level I could think of was the database itself.

Here I talk to a local copy of the database directly, with the same user the app connects with. No company set, it shows nothing. Company A set, it shows only company A. Ask for company B and you get nothing back, and a write into company B is refused by Postgres itself.
The database knows which company is asking
Every table that holds a company's data has a company id on each row. Postgres has a feature called row level security: you attach a policy to a table, and from then on the database applies it to every query, by itself. My policy says one thing. A row can be read or written only if its company is the company of this request.
When a request comes in, the app finds who is signed in and which company they are working in, and it tells the database at the start of the transaction. That setting lives only as long as the transaction. When it ends, the connection goes back to the pool clean, so the next request can never get the last company.
If the app forgets to set the company, the query gets zero rows. That's the part I like most.

The app can't go around it
The app connects to the database with a user that can't bypass these policies, and the policies apply to the owner of the table too. So even with a bug in my code, the database still says no.
On top of that, the app adds the company to every query on a company's data, by itself, and a test fails if a new table with a company id is missing from that list. The tests for the database part talk to Postgres directly, around the app, so the only thing that can stop them is the policy.
Who sees what inside a company
Row level security answers which company. Inside that company, what each person can see and change lives in the app, with three roles: the admins and managers who run the office, and the tour operators, the outside desks. A tour operator signs in to the same product and only sees their own bookings.
The agents get nothing extra. When Claude connects to TourCockpit, or my agent answers on WhatsApp, it acts as a specific person, with that person's role. It can do everything that person can do, and nothing more. That's what lets me give the whole API to an agent.
Put the guarantee in one place
Every new way into TourCockpit gets the same protection, and nobody has to remember to add it. I trust one place, the lowest one, and I test it.
This API is the new UI, so the security had to move down to the database.
Get the next post by email
One email when a post lands, from chip@ciprianrarau.com. No drip, no marketing, unsubscribe anytime.