Mobile Development
Building a large Flutter and Supabase app: keeping business rules in the database
Yakın Çevrem is the largest product I've built on my own: over 90,000 lines of Dart and a database schema past 10,000 lines. This post is about my most important decision: trusting the database, not the client, with the rules.
Planning a get-together with friends always went the same way: a long message thread, asking everyone one by one when they were free, then a shopping list that got lost somewhere. Calendar apps felt too personal, project tools felt too corporate. I wanted something that lived in the gap between them, and that's how Yakın Çevrem ("close circle") started.
Today the app means roughly 90,000 lines of Dart, a 10,800-line PostgreSQL schema and a release history that has reached build 61. I'll admit I didn't know it would grow this big. But the more it grew, the clearer it became that one early decision was right: keep the business rules in the database, not in the client.
Why Supabase?
When you build a mobile app alone, the most expensive thing is time. Setting up and maintaining separate infrastructure for auth, database, file storage, realtime updates and server functions would have eaten the time I needed for the app itself. Supabase gathers all of that around PostgreSQL. That was the real appeal for me: underneath is an ordinary, powerful database I already know well.
But Supabase has another side: the client talks to the database almost directly. There's no API layer of your own in between. So the answer to "can this user see this row?" has to live in the database, not in the app. Otherwise anyone who opens up the app can read everything.
RLS: one rule, enforced the same way for everyone
Row Level Security lets you write, per table, which rows the person running a query may see or change. In Yakın Çevrem, only members of a group can see that group's meetups; only people added to a project can change its tasks. Those rules don't live as an if statement in the app; they sit on the table itself.
-- Only group members can see a meetup.
create policy "members can read meetups"
on public.meetups for select
using (
exists (
select 1 from public.group_members gm
where gm.group_id = meetups.group_id
and gm.user_id = auth.uid()
)
);The biggest thing this gave me was calm. When I rewrite a screen or add a feature, the chance of accidentally opening a permission hole is much lower. The rule is in one place and applies the same way no matter which screen the request comes from.
Triggers and RPC functions
Some rules are more complex than "who can see this?". Updating the attendee count when someone answers "I'm going", changing a project's progress when a task is completed, closing someone's open invites when they leave a group. Doing these on the client meant repeating the same logic on every screen and forgetting one of them someday. I moved them all into triggers and RPC functions; the client only says "I want to do this", and the database makes sure it happens consistently.
One more detail: the schema script can be re-run on top of older versions without losing data. In a 10,000-line schema, every upgrade would be a gamble without that discipline.
Working offline
People open a planning app on the subway, in an elevator, in a café with bad signal. Showing "an error occurred" just because there's no connection damages trust from day one. So actions taken offline go into a local queue and are sent in order when the connection returns. Data that has been read is cached too; the app stays usable even on a weak connection.
Here RLS turned out to help again: when a queued action is finally sent, if the user's permissions changed in the meantime, the database simply rejects it. The client never has to wonder "am I still allowed to do this?".
Encrypted chat and notifications
The app has one-to-one and group chat. Messages are encrypted with a key stored in Supabase Vault. Notifications that arrive while the app is closed work through an Edge Function that sends push messages via Firebase Cloud Messaging. So notification logic also lives on the server side, in one place.
Two languages, and errors the build catches
Every string shown to the user comes from abstract contracts under lib/l10n/. If a Turkish or English translation is missing, the app doesn't compile. It sounds like a small detail, but in a large app it's much better to find out that half a screen is untranslated on my own machine than from a user complaint.
What I learned
- Writing rules in the database feels slower at first, then makes every feature faster.
- Versioning the schema like code and keeping it re-runnable is the insurance policy of a growing product.
- Offline support isn't a bonus feature on mobile; it's a basic expectation.
- When you develop alone, your best teammate is a build that catches mistakes before you do.
Yakın Çevrem is now being prepared for Google Play. While building it, I often thought: an app that tries to bring people together shouldn't be scattered on the inside. Maybe that's why keeping the rules in one place mattered so much.