Chrysolites Tech Academy

Photo Social App with FlutterFlow and Supabase · Course book

Chapter 29: Finishing the Base App

Pairs with Lesson 29: Completing Chat and 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.

PatternWhere it appearsWhat it solves
Profile table sharing the account's idusersApp-specific details for each authenticated account
One-to-many foreign keyposts.user_id, comments.post_id, messages.chat_idEach item belongs to one parent
Intermediate table with a unique pairlikes, user_follower, chat_membersMany-to-many relationships without duplicates
Self-referencecomments.parent_idTrees of replies of any depth
Stored value kept by a triggerlike_count, follower counts, last_message_atFast reads of values that would be slow to compute
View joining tablesposts with authors, comments with authors, chat listOne query per screen
Row level security policyEvery table and bucketRules 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.

users postslikescommentsuser_followerchat_memberschatsmessagesbuckets replies post images, avatars
Figure 29.1 — The whole database at a glance. Users connect to almost everything; three intermediate tables and one self-reference carry the social features.

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.

Worked example. Take 1,000 users after a year. If each shares 10 posts, there are 10,000 posts. At 25 likes and 5 comments per post, there are 250,000 likes and 50,000 comments. Following 150 people each gives 150,000 follow rows. With 20 conversations per person there are 10,000 chats and 20,000 member rows, and at 30 messages a day per person about 11 million messages. Messages outnumber every other table combined by more than twenty times, so the messages table, its index on chat and time, and paging on the chat page matter most for performance as the app grows.
userspostschatsmemberscommentsfollowslikesmessages 1k10k10k20k50k150k250k11M 103104105106 rows per table after a year, 1,000 users (log scale) messages bar is clipped: its true height is beyond 10 million
Figure 29.2 — Estimated rows per table for 1,000 users after a year. Messages dominate, followed by likes and follows.

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

  1. Recompute the worked example for 3,000 users with the same rates. How many likes and messages are there after a year?
  2. Which database pattern would you use for saved posts, and which columns would its table need?
  3. How does the chat list view find "the other member" in a one-to-one chat?
  4. List the three stored values in the app that are kept by triggers.
  5. Why is the messages table the most important one to index well?
  6. Write a ten-step end-to-end test that covers every major feature of the app.

Install Chrysolites Tech Academy

Android / Chrome / Edge: open the browser menu and choose Install app or Add to Home screen.

iPhone / iPad (Safari): tap the Share button, then Add to Home Screen.