Photo Social App with FlutterFlow and Supabase · Course book
Chapter 29: Finishing the Base App
This part finishes the chat feature and, with it, the base version of the photo app. The chat groups page now shows real conversations with names, previews and times, and the whole app, from sign-in to posting, likes, comments, follows, profiles and chat, works end to end. Finishing a project is also the right moment to step back. This chapter completes the chat groups page, reviews the database structure as a whole and the patterns that repeat through it, estimates by hand how much data each table holds for a modest community, with a chart, works through a final round of debugging and testing, and suggests where to take the app next.
Completing the chat groups page
Each row on the chat groups page needs four things: the other member's name and avatar, a preview of the latest message, the time of that message and whether it is unread. The view built for this page joins the viewer's chat_members rows with the chat, with the other member's user row and with the latest message, so one query returns everything. Rows are ordered by the chat's last_message_at, kept current by the trigger on messages, so the most recent conversations rise to the top.
A few details make the list feel finished. The preview shows "You: " before the user's own latest message and cuts long messages to one line with an ellipsis. Times use a compact form, "4m", "2h", "Mon" or a short date. Unread conversations, where the latest message is newer than the viewer's last_read_at, are shown in bold with a small dot. A conversation with no messages yet shows "Say hello". And tapping a row opens the chat page, which marks the conversation as read, so returning to the list shows the dot gone and the row back in normal weight.
Finding "the other member" in a one-to-one chat means choosing the member whose id is not the viewer's. In a group chat, the row shows the group's name, or a list of first names, and a combined avatar. Handling both cases in the view keeps the page itself simple: it just displays the name and picture the view provides.
The page should also stay current without effort from the user. Refreshing the list whenever the page comes into view, for example when the user returns from a conversation, picks up new messages and the changed order. Pull-to-refresh lets people check for new messages on demand. Until real-time updates are added in a later extra part, these two refreshes are what keep the list accurate, and they are cheap because the view returns only one row per conversation, however long each conversation has become.
Leaving or deleting a conversation is the last piece of chat housekeeping. Swiping a row, or long-pressing it, can offer "Delete chat". For a one-to-one conversation, many apps hide the chat for the person who deleted it rather than destroying it for both, which a hidden flag on that person's chat_members row expresses neatly; the other person keeps their copy. If a new message later arrives, the flag can be cleared so the conversation reappears. Removing a member row outright, by contrast, means that person leaves the conversation entirely, which suits group chats.
A note on database structure
The finished app rests on a small number of tables, and the same few patterns appear again and again. Recognising them is the most valuable lesson of the series, because they apply to almost any app.
| Pattern | Where it appears | What it solves |
|---|---|---|
| Profile table sharing the account's id | users | App-specific details for each authenticated account |
| One-to-many foreign key | posts.user_id, comments.post_id, messages.chat_id | Each item belongs to one parent |
| Intermediate table with a unique pair | likes, user_follower, chat_members | Many-to-many relationships without duplicates |
| Self-reference | comments.parent_id | Trees of replies of any depth |
| Stored value kept by a trigger | like_count, follower counts, last_message_at | Fast reads of values that would be slow to compute |
| View joining tables | posts with authors, comments with authors, chat list | One query per screen |
| Row level security policy | Every table and bucket | Rules enforced on the server for every client |
These patterns make the app easy to extend. Saving posts to a collection is another intermediate table, between users and posts. Hashtags are a tags table and an intermediate table between posts and tags. Blocking is an intermediate table between users and the users they block, consulted by policies. Each new feature is mostly a matter of choosing the right pattern and writing its policies.
The structure also explains several decisions that might have seemed arbitrary along the way. Posts store the author's id rather than their name, so a changed username updates everywhere at once. Counts are stored rather than recalculated, so busy pages stay fast. Images live in buckets rather than tables, so the database stays small. And every rule that matters, one like per person, no following yourself, only members reading chats, lives in the database rather than only in the app, so that no future version of the app, and no script, can break it. Writing these decisions down, with the SQL for each table, trigger, view and policy, turns the project into something another developer could understand and maintain, which is the real mark of a finished app.
How much data, and where?
Bringing together the estimates from earlier chapters shows where data accumulates in a modest community, which guides indexing and planning.
Final debugging, testing and next steps
A finished feature deserves a final end-to-end test with two or three accounts: sign up, complete onboarding, post photos, search, open details, like, comment and reply, follow and unfollow, edit a profile, start a chat, exchange messages and check unread markers and ordering on both sides. Watching the Supabase tables while testing shows whether every action writes what it should, and testing on a real phone catches layout and keyboard issues that a browser preview hides. Before inviting anyone else, review every policy and replace any "allow all" storage policy used during development.
A short pre-release checklist helps. Confirm that row level security is enabled on every table in the public schema, with no table left open. Check that each bucket's policies allow uploads only into the uploader's own folder. Remove test accounts and test posts, or move testing to a separate Supabase project so that real users never see them. Make sure no service key or other secret has been placed in the FlutterFlow project, and that the anon key is the only key the app contains. Add simple ways to report content and block users, which app stores expect for apps with user content. And check how the app behaves offline and on a slow connection, so that every screen shows a sensible message rather than spinning for ever.
Performance is worth a final look, too. Open the busiest screens, the feed, a popular post's comments and a long chat, with plenty of test data, and watch how quickly they load. Slow screens usually point to a missing index on a filtered column, a query that fetches more rows than the screen shows, or images uploaded at full size; each has a straightforward fix described in earlier chapters.
The base version is complete, and the series continues with extras that make it production-ready: a forgot and reset password flow, email verification and real-time chat so messages arrive without refreshing. Beyond those, the patterns above make many features within reach: notifications, saved posts, hashtags, blocking and reporting, and, as the series' own title suggests, a sound foundation for adding artificial intelligence features later, such as smart captions or content moderation.
Practice tasks
- Recompute the worked example for 3,000 users with the same rates. How many likes and messages are there after a year?
- Which database pattern would you use for saved posts, and which columns would its table need?
- How does the chat list view find "the other member" in a one-to-one chat?
- List the three stored values in the app that are kept by triggers.
- Why is the messages table the most important one to index well?
- Write a ten-step end-to-end test that covers every major feature of the app.
This course book is available to read online only at tech-academy.chrysolites.org.